Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Count pulses over a period of time
PostPosted: Thu Nov 17, 2011 11:15 pm 
Offline

Joined: Thu Nov 17, 2011 10:21 pm
Posts: 2
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;
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: