|
My goal is to set a TC to count pulses every 10 seconds.
I want to know if it is possible to count the TIOA transitions and once the clock reaches a terminal value (n seconds), I want to capture the number of pulses in one of the registers.
It is not clear if the result (pulse count) is going to end up in RA, RB or RC. Also please explain if I need to set TC_RC with a terminal value (compare) and set TC_CPCTRG = 1?
I have as follows:
//----------------------------------------------------------------------------- void HAL_InitTC3(DWORD period) { unsigned long dummy; AT91PS_PIO pPioA = (AT91PS_PIO) AT91C_BASE_PIOA;
//PMC AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC3); //enable timer 3 clock over PMC //PIO pPioA->PIO_PDR = AT91C_PB0_TIOA3; //define PB0 TIOA3 as peripheral pPioA->PIO_BSR = AT91C_PB0_TIOA3; //select peripheral B
//Disable the clock and the interrupts before to configure it AT91C_BASE_TC3->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC3->TC_IDR = 0xffffffff;
//Clear the status bit dummy = AT91C_BASE_TC3->TC_SR;
//Set the mode AT91C_BASE_TC3->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_FALLING | AT91C_TC_ABETRG | AT91C_TC_LDRA_FALLING | AT91C_TC_LDRB_FALLING | AT91C_TC_CPCTRG;
//ticks = DIV1_CLOCK //Set the compare register (10 seconds) AT91C_BASE_TC3->TC_RC = period;
//Enable the clock AT91C_BASE_TC3->TC_CCR = AT91C_TC_CLKEN; }
void HAL_CloseTc3() { //Disable the clock and the interrupts before to configure it AT91C_BASE_TC3->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC3->TC_IDR = 0xffffffff; }
DWORD HAL_ReadCapture(DWORD capReg) { switch(capReg) { case 0: return AT91C_BASE_TC3->TC_RA; case 1: return AT91C_BASE_TC3->TC_RB; case 2: return AT91C_BASE_TC3->TC_RC; } }
|