Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Atmega328 timer1 reload interrupt

2 posters

Go down  Message [Page 1 of 1]

1Atmega328 timer1 reload interrupt Empty Atmega328 timer1 reload interrupt Tue Nov 07, 2023 6:46 pm

Marshall_Banana



Hello,
it looks like the timer reload isr of timer1 (TIMER1_CAPT_vect) doesn't execute in SimulIDE.
The attached sketch outputs a variable duty cycle pwm (PWM frequency 62500 Hz) on pin 9 of an arduino uno. It works in real hardware. The output, filtered by a simple RC filter,  becomes a 244 Hz sine wave.
But in SimulIDE the output is just a 62.5 kHz square wave with 50% duty cycle.

I tried SimulIDE 1.1.0-RC0 rev. 1908 and rev. 2036
Attachments
Atmega328 timer1 reload interrupt AttachmentPWM_Sinus_ICR1.zip
You don't have permission to download attachments.
(2 Kb) Downloaded 4 times

2Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Tue Nov 07, 2023 7:51 pm

arcachofo

arcachofo

Hi.

Not sure if I understood your code correctly but as far as I know TIMER1_CAPT_vect if for Input Capture unit.

3Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Tue Nov 07, 2023 9:12 pm

Marshall_Banana



Hi,
thanks for your quick response.

In Mode 14 (Fast PWM) the ICF1 flag is set when the counter reaches the value of ICR1, see p. 102 of the datasheet.
So the Input Capture Interrupt can be used to set a new value for OCR1A to change the duty cycle.

With a real Arduino Uno the output at PIN9 looks something like this:
Atmega328 timer1 reload interrupt Out_ha10

But in SimulIDE it looks something like this:
Atmega328 timer1 reload interrupt Out_si10

I forgot one typecast in the arduino sketch of the first post, attached is a corrected version.
Attachments
Atmega328 timer1 reload interrupt AttachmentPWM_Sinus_ICR1.ino.txt
You don't have permission to download attachments.
(2 Kb) Downloaded 3 times

4Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Tue Nov 07, 2023 9:23 pm

arcachofo

arcachofo

In Mode 14 (Fast PWM) the ICF1 flag is set when the counter reaches the value of ICR1, see p. 102 of the datasheet.
So the Input Capture Interrupt can be used to set a new value for OCR1A to change the duty cycle.
Ok thanks for the explanation.
As far as I can remember this is not implemented, I will have a look.

5Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Thu Nov 09, 2023 8:36 pm

Marshall_Banana



With
Code:
TIMSK1 |= (1<<TOIE1);
ISR(TIMER1_OVF_vect) { ...
it works as expected.

Atmega328 timer1 reload interrupt Grafik11

6Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Thu Nov 09, 2023 8:49 pm

arcachofo

arcachofo

Nice.
I still have to implement the Input Capture Interrupt at Output Compare match in fast mode.

And I guess it does not work the same, the proper moment to update OCR value is as you did.

Marshall_Banana likes this post

7Atmega328 timer1 reload interrupt Empty Re: Atmega328 timer1 reload interrupt Wed Nov 22, 2023 6:31 pm

arcachofo

arcachofo

I think this issue is solved at Rev 2048.

Keep an eye in this discussion for new executables:
https://simulide.forumotion.com/t550-simulide-trunk-tester-builds#2961

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum