Page 1 of 1

Are interruptions not working for me?

Posted: Wed Oct 30, 2024 3:12 pm
by Carmelo
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.

Re: Are interruptions not working for me?

Posted: Fri Nov 01, 2024 4:50 pm
by LeighM
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

Re: Are interruptions not working for me?

Posted: Fri Nov 01, 2024 7:35 pm
by Carmelo
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.

Re: Are interruptions not working for me?

Posted: Mon Nov 04, 2024 11:38 am
by medelec35
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.

Re: Are interruptions not working for me?

Posted: Tue Nov 05, 2024 10:02 am
by Carmelo
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

Re: Are interruptions not working for me?

Posted: Tue Nov 05, 2024 10:58 am
by medelec35
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.
LCD Print update..png
LCD Print update..png (26.64 KiB) Viewed 2943 times
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
then that is the same as

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.

Re: Are interruptions not working for me?

Posted: Tue Nov 05, 2024 1:36 pm
by Carmelo
Michas gracias por las aclaraciones.

C .