Custom interrupt for Nano Timer1
Posted: Wed Oct 02, 2024 4:41 am
Hi
In the article - Arduino Uno SPWM Inverter,
https://yopiediy.xyz/
https://yopiediy.xyz/arduino-uno-invert ... sine-wave/
Author used Timer1 to create the SPWM by using one Lut (table).
The Time1 code:
TCCR1A = 0b10110000;
/* 0b10xxxxxx Clear OC1A/OC1B on compare match when up-counting. Set on compare match when down counting
0bxx11xxxx Set OC1A/OC1B on compare match when up-counting. Clear on compare match when down counting.
0bxxxxxx00 WGM1 1:0 for waveform 8 (phase freq. correct). */
TCCR1B = 0b00010001;
/* 000xxxxx
xxx10xxx WGM1 3:2 for waveform mode 8.
xxxxx001 no prescale on the counter.
*/
TIMSK1 = 0b00000001;
/* xxxxxxx1 TOV1 Flag interrupt enable. */
ICR1 = 800; /* Counter TOP value (at 16MHz XTAL, SPWM carrier freq. 10kHz, 200 samples/cycle).*/
sei(); /* Enable global interrupts.*/
DDRB = 0b00011110; /* Pin 9, 10, 11, 12 as outputs.*/
Question
How can I set the custom code for Timer1 (in Nano)?
PS
I found one example (attached), fixed by Ben years ago.
Would be great if somebody can help me.
Thanks
In the article - Arduino Uno SPWM Inverter,
https://yopiediy.xyz/
https://yopiediy.xyz/arduino-uno-invert ... sine-wave/
Author used Timer1 to create the SPWM by using one Lut (table).
The Time1 code:
TCCR1A = 0b10110000;
/* 0b10xxxxxx Clear OC1A/OC1B on compare match when up-counting. Set on compare match when down counting
0bxx11xxxx Set OC1A/OC1B on compare match when up-counting. Clear on compare match when down counting.
0bxxxxxx00 WGM1 1:0 for waveform 8 (phase freq. correct). */
TCCR1B = 0b00010001;
/* 000xxxxx
xxx10xxx WGM1 3:2 for waveform mode 8.
xxxxx001 no prescale on the counter.
*/
TIMSK1 = 0b00000001;
/* xxxxxxx1 TOV1 Flag interrupt enable. */
ICR1 = 800; /* Counter TOP value (at 16MHz XTAL, SPWM carrier freq. 10kHz, 200 samples/cycle).*/
sei(); /* Enable global interrupts.*/
DDRB = 0b00011110; /* Pin 9, 10, 11, 12 as outputs.*/
Question
How can I set the custom code for Timer1 (in Nano)?
PS
I found one example (attached), fixed by Ben years ago.
Would be great if somebody can help me.
Thanks