Page 1 of 1
Very fast 1 secnd time
Posted: Tue Jul 09, 2024 4:02 pm
by Carmelo
I want to implement a 1sg delay in my project to check the status of a certain situation.
I want to do it with the interruption of timer 1 and in the properties I get that for an oscillation of 8MHz and a "Prescaler rate" of 1:2 that the interruption is executed every 15.259Hz.
Therefore, in the interrupt macro, I increment the value of a counter by 1 and wait for it to repeat 15 times, at which point I activate a flag to check it in the main.
With that it would give an approximate time of 1s.
The fact is that in the simulation the LED blinks very fast.
Can you tell me how to achieve that delay of approximately one second?
Thanks in advance.
Attached test file
Re: Very fast 1 secnd time
Posted: Tue Jul 09, 2024 4:27 pm
by medelec35
Rather than a timer interrupt, for better timing control on your hardware and simulation there is the Timed Interval component (Component Libraires > Math > Timing).
The advantage is you can enter an amount, directly in:

- Timed Interval component.png (21.37 KiB) Viewed 4712 times
Therefore, you can enter 1, 20, 300, 4000, 55689, 6000000 etc microseconds, ms, seconds, minutes, hours or days
So much more easier to set up than a timer interrupt.
As for the simulation, it's not a bug, or something you have done wrong
Simulation timing using interrupts is not accurate at all and is much faster than on embedded hardware.
Re: Very fast 1 secnd time
Posted: Tue Jul 09, 2024 4:41 pm
by Steve-Matrix
The code looks ok but the simulation seems much too fast. Timer interrupts in simulation are often not accurate though.
Does this flash too fast when you run on hardware?
Re: Very fast 1 secnd time
Posted: Tue Jul 09, 2024 6:28 pm
by Carmelo
medelec35 wrote: ↑Tue Jul 09, 2024 4:27 pm
Rather than a timer interrupt, for better timing control on your hardware and simulation there is the Timed Interval component (Component Libraires > Math > Timing).
The advantage is you can enter an amount, directly in:
Timed Interval component.png
Therefore, you can enter 1, 20, 300, 4000, 55689, 6000000 etc microseconds, ms, seconds, minutes, hours or days
So much more easier to set up than a timer interrupt.
As for the simulation, it's not a bug, or something you have done wrong
Simulation timing using interrupts is not accurate at all and is much faster than on embedded hardware.
Martin,
I have followed the instructions you have given me and transferred what you have attached to my project. But I notice that it doesn't work for me. I explain:
- I have copied the properties of the interval component of timer 1
- In the macro I have only set the seconds variable to be incremented by 1.
- In the main I check when this variable reaches 10, with this the output that was previously activated when the number of pulses reaches 10 must be deactivated.
- When performing the execution, when the pulses reach 10, the output is activated and the interval starts.
- But I don't notice that the output is deactivated and the execution remains inside the code between the label, waiting for the seconds to reach 10.
I have checked, lowering the simulation speed a little, the value of the seconds variable and I observe that it is always at 0.
Also within the interval macro I have put a witness to verify if it enters that part of the code and if it is executed but the variable is not incremented.
I attach the file.
Re: Very fast 1 secnd time
Posted: Tue Jul 09, 2024 6:30 pm
by Carmelo
Steve-Matrix wrote: ↑Tue Jul 09, 2024 4:41 pm
The code looks ok but the simulation seems much too fast. Timer interrupts in simulation are often not accurate though.
Does this flash too fast when you run on hardware?
Mañana lo probaré de forma física. Hoy no puedo.
Reportaré el resultado.