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
Very fast 1 secnd time
-
- Posts: 132
- http://meble-kuchenne.info.pl
- Joined: Thu Oct 14, 2021 10:04 am
- Has thanked: 53 times
- Been thanked: 4 times
-
- Matrix Staff
- Posts: 2086
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 644 times
- Been thanked: 701 times
Re: Very fast 1 secnd time
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: 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.
The advantage is you can enter an amount, directly in: 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.
- Attachments
-
- Prueba v2.fcfx
- (14.44 KiB) Downloaded 327 times
Martin
-
- Matrix Staff
- Posts: 1548
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 214 times
- Been thanked: 362 times
Re: Very fast 1 secnd time
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?
Does this flash too fast when you run on hardware?
Re: Very fast 1 secnd time
Martin,medelec35 wrote: ↑Tue Jul 09, 2024 4:27 pmRather 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.
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.
- Attachments
-
- Prueba_C.fcfx
- (21.38 KiB) Downloaded 316 times
Last edited by Carmelo on Tue Jul 09, 2024 6:34 pm, edited 3 times in total.
Re: Very fast 1 secnd time
Mañana lo probaré de forma física. Hoy no puedo.Steve-Matrix wrote: ↑Tue Jul 09, 2024 4:41 pmThe 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?
Reportaré el resultado.