Ticket #15 (new enhancement/request)
timer1 capture part code snip
| Reported by: | cncbasher | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | firmware | Keywords: | |
| Cc: |
Description (last modified by liamMT) (diff)
could this code be added please ,
void timer1_capture_init(void) {
// MCLK = 48054857, 24 (41.61902ns) rollover 366 times per second,6.0, 1.50, 375KHz, 46.9KH
AT91_REG *tcb_bmr = AT91C_TCB_BMR; // TC Block Mode Register
AT91_REG *tcb_bcr = AT91C_TCB_BCR; // TC Block Control Register
AT91PS_TC pTC1 = AT91C_BASE_TC1; // Use timer 1
AT91_REG *pmc_pcer = AT91C_PMC_PCER; // peripheral clock enable reg
// Allocate space for capture events
evt_head = calloc(512,sizeof(struct EVENTTIME));
evt_p = evt_head;
evt_tail = (evt_head + 512);
*pmc_pcer = (1 << AT91C_ID_TC1); // Enable the timer1 clock
// iprintf("AT91C_PMC_PCSR 0x%X, (0x%X)\n", pmc_pcsr, *pmc_pcsr);
// No external clocks
*tcb_bmr = AT91C_TCB_TC0XC0S_NONE |AT91C_TCB_TC1XC1S_NONE |AT91C_TCB_TC2XC2S_NONE;
// Don't sync the timers
*tcb_bcr = 0; //AT91C_TCB_SYNC
// AT91C_TC_CLKS_TIMER_DIV1_CLOCK MCK/2),2=8,3=32,4=128,5=1024
// Channel Mode register, Capture mode.
// Counter inc on rising edge.
pTC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK |
AT91C_TC_ETRGEDG_NONE | // no external reset (trigger) on falling
AT91C_TC_LDRA_RISING | // Load A on rising
AT91C_TC_LDRB_RISING; // Load B on rising
// Enable the clock, software trigger.
pTC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
// Enable interrupt on rollover, and A load and B load.
pTC1->TC_IER = AT91C_TC_COVFS | AT91C_TC_LDRAS | AT91C_TC_LDRBS;
/* Setup System Interrupt Mode and Vector with Priority 7 and Enable it */
volatile AT91S_AIC * pAIC = AT91C_BASE_AIC;
pAIC->AIC_SMR[AT91C_ID_TC1] = AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE | 7;
pAIC->AIC_SVR[AT91C_ID_TC1] = (unsigned long) tc1_isr;
pAIC->AIC_IECR = (1 << AT91C_ID_TC1);
}
this will use timer1 to capture a pulse using a free running timer1 then loading LDRA on rising edge and LDRB on the next rising edge ,
then using LDRB and then LDRA the difference becomes the pulse width
this can be used for example reading in a RC Reciever servo pulse i need some assistance adding this to the rest of the code and building an example but it's a start , also see at91.com for Timer capture
someone better than me may have an easier way but thought i would add this for concideration
Change History
Note: See
TracTickets for help on using
tickets.
