Hello,
I want to make an RPM counter.
For RB0, configuring the INT0 interrupt, I introduce a frequency of 50Hz (period of 20ms) so that a counter is incremented with each pulse.
On the other hand, I have enabled the interruption of timer 1 to count a time of 1 second. When 1 second passes, I capture the value of the RB0 counter and present the value on the LCD and also enhance the calculation to convert the value of the pulses obtained (per second) to RPM.
The fact is that the display should be able to see the values of 50 pulses and an RPM of 3000.
The actual data displayed does not exceed 3 pulses and 180 RPM. From what you can see, the calculation is correct (3 pulses x 60 seconds = 180 RPM)
I am attaching the file in case you can help me clarify why the problem is occurring.
C.
Are interruptions not working for me?
-
- Posts: 123
- http://meble-kuchenne.info.pl
- Joined: Thu Oct 14, 2021 10:04 am
- Has thanked: 50 times
- Been thanked: 4 times
Are interruptions not working for me?
- Attachments
-
- Prueba_interupciones.fcfx
- (25.66 KiB) Downloaded 134 times
Last edited by Carmelo on Fri Nov 01, 2024 7:35 pm, edited 1 time in total.
-
- Valued Contributor
- Posts: 458
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 82 times
- Been thanked: 246 times
Re: Are interruptions not working for me?
In the int_tmr1 macro, Yes branch, could you toggle a (LED) output pin so that you can check that the 1 second timing is correct.
Also just noticed that the project settings have Watchdog Timer On
Also just noticed that the project settings have Watchdog Timer On
Re: Are interruptions not working for me?
Thanks for the reply.
The LED does change state every time the interrupt value is met, that is, it changes the state of the flag that I have placed in the YES branch.
What happens is that the blinking in the simulation is very, very fast and does not look anything like the 1 second configured.
The LED does change state every time the interrupt value is met, that is, it changes the state of the flag that I have placed in the YES branch.
What happens is that the blinking in the simulation is very, very fast and does not look anything like the 1 second configured.
-
- Matrix Staff
- Posts: 1994
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 630 times
- Been thanked: 666 times
Re: Are interruptions not working for me?
Hello.
Simulation wise, you won't get expected results as the timer interrupt runs much quicker for simulation , but its accurate on your embedded hardware.
As a suggestion you can try the attached which will hopefully simulate better as well as working on embedded hardware.
Simulation wise, you won't get expected results as the timer interrupt runs much quicker for simulation , but its accurate on your embedded hardware.
As a suggestion you can try the attached which will hopefully simulate better as well as working on embedded hardware.
- Attachments
-
- Prueba_interupciones v2.fcfx
- (28.54 KiB) Downloaded 115 times
Martin
Re: Are interruptions not working for me?
Thank you very much for the response Martin.
But since I don't have much knowledge about Flowcode and I'm learning, there are a couple of questions regarding the file you attached that I would like to know why they are used:
1º Within "timer_Interval", you have put a block "Required only for simulation".
Why is this so?
Additionally, within the main environment you placed a decision block checking the "Flag" status. What is its purpose?
2º I observe in the simulation that the time is being counted almost perfectly at the rate of 1 second, but if through the pulse input I introduce a frequency of 50Hz (each pulse occurs every 20ms) and therefore the "number of pulses" counter It should show the value of 50 almost constantly, except for small differences due to the time consumed by the execution of the rest of the instructions.
The value obtained is far from 50, I always observe oscillations between 22 and 28.
3º I imagine that you can use 2 "timer intervals", one using the TMR1 and the other using the TMR2.
Can one be used to count seconds and the other microseconds?
Thanks in advance for the responses, your time and sorry for the inconvenience.
Greetings
But since I don't have much knowledge about Flowcode and I'm learning, there are a couple of questions regarding the file you attached that I would like to know why they are used:
1º Within "timer_Interval", you have put a block "Required only for simulation".
Why is this so?
Additionally, within the main environment you placed a decision block checking the "Flag" status. What is its purpose?
2º I observe in the simulation that the time is being counted almost perfectly at the rate of 1 second, but if through the pulse input I introduce a frequency of 50Hz (each pulse occurs every 20ms) and therefore the "number of pulses" counter It should show the value of 50 almost constantly, except for small differences due to the time consumed by the execution of the rest of the instructions.
The value obtained is far from 50, I always observe oscillations between 22 and 28.
3º I imagine that you can use 2 "timer intervals", one using the TMR1 and the other using the TMR2.
Can one be used to count seconds and the other microseconds?
Thanks in advance for the responses, your time and sorry for the inconvenience.
Greetings
-
- Matrix Staff
- Posts: 1994
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 630 times
- Been thanked: 666 times
Re: Are interruptions not working for me?
1. There is a bug with the timer component simulation and the debug message is a temp fix to make it work.
As for the flag, I did make a mistake the verValores user macro requires dragging to the Yes branch of If Flag. It's purpose is to update the LCD printing to once every second when the Flag variable is changed to 1
If there is no value after a variable e.g. then that is the same as
2. Are you referring to simulation, on your embedded hardware or both?
Simulation is not 100% accurate for timing so the pulse simulation won't be spot on.
Its best to check on embedded hardware.
As for the flag, I did make a mistake the verValores user macro requires dragging to the Yes branch of If Flag. It's purpose is to update the LCD printing to once every second when the Flag variable is changed to 1
If there is no value after a variable e.g.
Code: Select all
If Flag
Code: Select all
If Flag is any value except 0
2. Are you referring to simulation, on your embedded hardware or both?
Simulation is not 100% accurate for timing so the pulse simulation won't be spot on.
Its best to check on embedded hardware.
Martin