Go Down

Topic: DUE Timer Counter in capture mode. (Read 4766 times) previous topic - next topic

Black_Wolf

#15
Jun 15, 2016, 10:33 pm Last Edit: Jun 16, 2016, 08:26 pm by Black_Wolf
Hi,
I test the flag CLKSTA, but... it's not really good.
When I start a timer it's OK, the flag is 0 since I stop the timer, and only after the flag is 1 and thats all.
When I restart timer CLKSTA is always 1.

Simple test...
Code: [Select]
#define NB_TRY 5
#define HORLOGE 42000000

uint32_t tc6ra;
uint32_t statusTC6;
int TC6Try_nb;
uint32_t _ticks_per_usecs = HORLOGE / 1000000;


void setup () {
 Serial.begin ( 115200 );

 REG_PIOC_PDR = 0x2000000;
 REG_PIOC_ABSR = REG_PIOC_ABSR | 0x2000000u;
 REG_PMC_PCER1 = REG_PMC_PCER1 | 0x2;

 TC_Configure ( TC2, 0,
       TC_CMR_TCCLKS_TIMER_CLOCK1 |
       TC_CMR_CPCTRG |
       TC_CMR_LDRA_FALLING |
       TC_CMR_ETRGEDG_FALLING |
       TC_CMR_ABETRG
 );
 
 TC_SetRC ( TC2, 0, 1200000 * _ticks_per_usecs );
 
 TC2->TC_CHANNEL[0].TC_IER = TC_IER_LDRAS;
 TC2->TC_CHANNEL[0].TC_IER = TC_IER_CPCS;
 
 NVIC_SetPriority ( TC6_IRQn, 1 );
 NVIC_ClearPendingIRQ ( TC6_IRQn );
 NVIC_EnableIRQ ( TC6_IRQn );
}

void loop () {
 TC_Start(TC2,0);
// NVIC_EnableIRQ(TC6_IRQn);
 Serial.print("ON\t");
 Serial.println((statusTC6 & TC_SR_CLKSTA), HEX);
 delay(3000);
 TC_Stop(TC2,0);
// NVIC_DisableIRQ(TC6_IRQn);
 TC2->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKDIS;
 Serial.print("OFF\t");
 Serial.println((statusTC6 & TC_SR_CLKSTA), HEX);
 delay(3000);
}

void TC6_Handler () {
 statusTC6 = TC_GetStatus(TC2, 0);
 
 if ( ( statusTC6 & TC_SR_LDRAS ) && ( TC2 -> TC_CHANNEL[0].TC_IMR & TC_IMR_LDRAS ) )  {
 tc6ra = TC2->TC_CHANNEL[0].TC_RA;
 }
 
/* if ( ( statusTC6 & TC_SR_CPCS ) && ( TC2 -> TC_CHANNEL[0].TC_IMR & TC_IMR_CPCS ) ) {
 TC6Try_nb ++;
 tc6ra = 0;
 if ( TC6Try_nb >= NB_TRY ) {
 REG_PWM_CDTYUPD0 = TOP_FAN_STOP;
 NVIC_DisableIRQ ( TC6_IRQn );
 TC_Stop ( TC2, 0 );
 if ( DEBUG ) Serial.println ( ERRORMSG_TOP3_BLOCKED );
 TC6Try_nb = 0;
 }
 }*/
}


I miss something ?

[EDIT]
OK, I found an other way. I disable the timer in the PMC when I stop it, and I read the status when I want to test it.

Go Up