Go Down

Topic: Timer Interrupts on Due (Read 164008 times) previous topic - next topic

ss13

hi
i want to design a timer with arduino mega 2560
this time must have a restore point and Measure every 10 millisecond and display this time on the lcd
i have a lot of problem
the first problem is for reset point
i cant active the reset point and show this on the lcd
please help me
this is my email
fziaee93@yahoo.com
please send your proposed about my project to my email
thanks alot

youthreewire

How to set an external clock signals for the interrupt? I am using a codec chip with the Due where the codec shield sends an external clock out.I need to sync the external clock from the codec with the due. I have the follow code for timer but I dont think it does that.
'
Code: [Select]
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        pmc_set_writeprotect(false);
        pmc_enable_periph_clk((uint32_t)irq);
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above
        TC_SetRA(tc, channel, rc/2); //50% high, 50% low
        TC_SetRC(tc, channel, rc);
        TC_Start(tc, channel);
        tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
        tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
        NVIC_EnableIRQ(irq);
}

sayrol

Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

Code: [Select]

volatile boolean l;

//TC1 ch 0
void TC3_Handler()
{
        TC_GetStatus(TC1, 0);
        digitalWrite(13, l = !l);
}

void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        pmc_set_writeprotect(false);
        pmc_enable_periph_clk((uint32_t)irq);
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above
        TC_SetRA(tc, channel, rc/2); //50% high, 50% low
        TC_SetRC(tc, channel, rc);
        TC_Start(tc, channel);
        tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
        tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
        NVIC_EnableIRQ(irq);
}

void setup(){
        pinMode(13,OUTPUT);
        startTimer(TC1, 0, TC3_IRQn, 4); //TC1 channel 0, the IRQ for that channel and the desired frequency
}

void loop(){
}


Here is the table of parameters:
ISR/IRQTC        ChannelDue pins
TC0TC002, 13
TC1TC0160, 61
TC2TC0258
TC3TC10none  <- this line in the example above
TC4TC11none
TC5TC12none
TC6TC204, 5
TC7TC213, 10
TC8TC2211, 12

Someone can help me please. I wanna know where do you get these functions from : pmc_set_writeprotect(false);
TC_SetRA(tc, channel, rc/2); //50% high, 50% low
TC_SetRC(tc, channel, rc);
TC_GetStatus(TC1, 0);
Because I searched in datasheet ATMEL SAM3X (1459 pages), and i never found anything about that.

Wurstnase

Quote
Someone can help me please. I wanna know where do you get these functions from : pmc_set_writeprotect(false);
TC_SetRA(tc, channel, rc/2); //50% high, 50% low
TC_SetRC(tc, channel, rc);
TC_GetStatus(TC1, 0);
Because I searched in datasheet ATMEL SAM3X (1459 pages), and i never found anything about that.
Because it's libsam and CMSIS.

RustyBody

Thanks for the great info but I would really be interested to know how to include the Atmel Studio project (solution) directory structure in an Arduino project, which includes CMSIS and more. It's to big to "flatten" and i really don't want to have to do what others have done in this thread - dig down to the binary register values. Since macros are still in use, I assume there is a file somewhere with the #define statements (pointing to register addresses) but where?

FYI, Atmel Studio is available for free from Atmel. It only runs in Windoze, however and you will need a JEDEC or some other interface in order to program Arduino's with Atmel code. The debugger is really handy, though. (I use a SAM-ICE hadware debugger/interface.)

Thanks,
Rusty

steadyState


Hi,

If I understand correctly, I can trigger an interrupt through the TC_IER register on RA, RB and RC compare, then on counter overflow, and others. Is the ISR called always this TCn_Handler()?

Does anybody know about a way to call different ISRs upon different trigger cases?


Thanks,
steady

ard_newbie


All enabled interrupts of  TC counter TCx will trigger TCx_Handler().


Inside the call back Handler, you:
1/ Read and save the status register, which saves  status bits and clears immediately bits so the interrupt can be triggered again

2/ you test in the saved status variable which bit is up (e.g. RA compare )

steadyState

2/ you test in the saved status variable which bit is up (e.g. RA compare )
Then, when you read the answer, suddenly all is so obvious... ;-)

Thank you very much, that makes it clear.

Go Up