Hi there
I have a question getting my Arduino DUE timer works correctly
I will have a function later (header file) which contains a variable "Sampling_time" to set the sampling time
So I just tried to test my code and to get sure that the timer works I added a variable in the Timer handler which increments its vlaue each time the programm calls the Handler but somehow it dosent work
Here is my code it just about 10 lines
rhanks in advance
// Global Variabels
int Interrupt_test; // incrementer to test the Interrupt
int Sampling_time = 20;// Sampling time for the function
// End global Variabels
// Timer Setup
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);
}
// End Timer Setup
// Timer Handler
void TC3_Handler()
{
// My function will come here if the timer code worked
Interrupt_test ++;
}
void setup() {
Serial.begin(9600);
//Start timer
startTimer(TC2, 0, TC3_IRQn, Sampling_time);
}
void loop() {
Serial.print("Interrupt_test "); // Interrupt Test Variable increments the interuppts value
Serial.println(Interrupt_test);
}