Hi all,
I want to use sin function from math library for something in my mind, what is the appropriate timer interrupt value ?
for example
when timer reaches the certain value, the following will be called
ISR(TIMER1_COMPA_vect){
x++;
float y=sin(2pif*x); //x is the time
Can you clarify what you want to do - regular interrupt to drive some regular event? For that
there's the timer overflow interrupt, not the output compare interrupt. TIMER1_OVF_vect
You have to configure the timer to run at the rate you want, which will interfere with analogWrite
on the relevant pins of course.
Or are you wanting to do an output compare to schedule your action - in which case you'll need
to program the relevant compare register, OCR1A, each time.
MarkT:
Can you clarify what you want to do - regular interrupt to drive some regular event? For that
there's the timer overflow interrupt, not the output compare interrupt. TIMER1_OVF_vect
You have to configure the timer to run at the rate you want, which will interfere with analogWrite
on the relevant pins of course.
Or are you wanting to do an output compare to schedule your action - in which case you'll need
to program the relevant compare register, OCR1A, each time.
I have 2 events for inverter project, so far everything is going well but I am stuck at the time needed for the OCR1A and B for overflow to activate
AWOL:
Better still, don't do time-consuming floating point calculations in interrupt context - use a table.
I tried table before, the results are not that good and the output is highly unstable with frequencies varies from 1Khz up to 100Khz while in my approach, I managed to get the stable 3Khz needed