Arduino DUE Hardware Quadratur REG_TC0_CV0 auf 0 setzten

OP #5041328
Lesenswert?

Guten Morgen an alle µC Freunde,

ich hätte da mal eine kurze Frage. Ich benutze beim DUE die Hardware 
Quadratur Einheit und soweit funktioniert auch alles. Nur habe ich das 
Problem, dass ich hin und wieder den gezählten Wert einfach wieder auf 0 
setzten möchte. Quasi ein Reset des Quadratur Zählers. Ich nutze 
folgenden Code zur Auswertung.
1
...
2

3
    REG_PIOB_PDR = mask_quad_A;     // activate peripheral function   (disables all PIO functionality)
4
    REG_PIOB_ABSR |= mask_quad_A;   // choose peripheral option B    
5
    REG_PIOB_PDR = mask_quad_B;     // activate peripheral function (disables all PIO functionality)
6
    REG_PIOB_ABSR |= mask_quad_B;   // choose peripheral option B 
7
    
8
    // activate clock for TC0
9
    REG_PMC_PCER0 = (1<<27);
10
    // select XC0 as clock source and set capture mode
11
    REG_TC0_CMR0 = 5; 
12
    // activate quadrature encoder and position measure mode, no filters
13
    REG_TC0_BMR = (1<<9)|(1<<8)|(1<<12);
14
    // enable the clock (CLKEN=1) and reset the counter (SWTRG=1) 
15
    // SWTRG = 1 necessary to start the clock!!
16
    REG_TC0_CCR0 = 5;   
17

18
...

Hier ist dann der aktuell quadrierte Wert abgelegt ( REG_TC0_CV0 ).


Ich hab schon getestet REG_TC0_CV0 = 0; zu setzten. Das funktioniert 
leider nicht.

Weiß jemand wie ich das machen kann?


Vielen Dank im Voraus.


LG
Digit-22
Gast #5047264
Lesenswert?

Digit-22 N. schrieb:
> Weiß jemand wie ich das machen kann?

Aus dem Datenblatt:
--------------------------------------------------
36.7.1 TC Channel Control Register
Name: TC_CCRx [x=0..2]
Access: Write-only

• CLKEN: Counter Clock Enable Command
0: No effect.
1: Enables the clock if CLKDIS is not 1.

• CLKDIS: Counter Clock Disable Command
0: No effect.
1: Disables the clock.

• SWTRG: Software Trigger Command
0: No effect.
1: A software trigger is performed: the counter is
reset and the clock is started.
--------------------------------------------------

Ich tippe mal auf Bit 2, SWTRG, das tut was du willst.
Gast #5182349
Lesenswert?

Did you find the solution to this problem.
I'm not able to reset the counter, REG_TC0_CV0, without moving the 
encoder. Then it resets. Otherwise it doesn't
This is the Arduino code I'm using:

void setup()
{
  Serial.begin(38400);
  REG_PIOB_PDR = digitalPinToBitMask(2);
  REG_PIOB_ABSR |= digitalPinToBitMask(2);
  REG_PIOB_PDR = digitalPinToBitMask(13);
  REG_PIOB_ABSR |= digitalPinToBitMask(13);
  REG_PMC_PCER0 = (1<<27);
  REG_TC0_CMR0 = 5;
  REG_TC0_BMR = (1<<9)|(1<<8)|(1<<12);
}

void loop()
{
  int32_t pulseCount;
  REG_TC0_CCR0 = TC_CCR_CLKEN | TC_CCR_SWTRG;
  for(int i = 0; i < 50; i++)
  {
    pulseCount = REG_TC0_CV0; //read counter register
    Serial.print(i);
    Serial.print(' ');
    Serial.println(pulseCount);
    delay(100);
  }
  REG_TC0_CCR0 = TC_CCR_CLKDIS;  //disable clock
  REG_TC0_CCR0 = TC_CCR_CLKEN | TC_CCR_SWTRG;  //enable clock and reset 
counter
  while(REG_TC0_CV0);
  for(int i = 0; i < 50; i++)
  {
    pulseCount = REG_TC0_CV0; //read counter register
    Serial.print(i);
    Serial.print(' ');
    Serial.println(pulseCount);
    delay(100);
  }
  while(1);
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren