Hello
I'm using Flowcode 6 with PIC pack.
The chip I'm using is PIC12F675
Internal Oscillator 4MHz, no clock out
Power Up Timer enabled
MCLR internal (IO pin active)
NO Brown Out Detect
NO Watchdog timer
NO Code Protection
For the purpose I'm trying to accomplish I possibly detected
a bug in the Calculation Function, when I try to increment a
variable by 1 ( variable = variable + 1 ) .
The descriptions the program and problems are bellow.
Flowcode flowchart, asm file and function timing diagram (this last one for how it should behave,
not for how it is actually behaving) are attached for better understanding.
NOTE: I did not used the Flowcode help/report a bug because there I can not attach the
files I needed to attach here.
Program Description (as it should behave)
Simplified description:
When a push button is clicked, a time window will start.
All clicks on the push button, within this time window, will be counted
(but only the 1st click starts the time window and the subsequent ones will
not restart it).
The time window ends by itself and at its end the program will see how many clicks occurred.
Only two clicks on the push button, during the started time window, will produce an output action
(when the time window ends) to an output pin: It will be complemented
(if it was 0 it will be set to 1 and if it was 1 it will be set to 0).
Any other number of push button clicks, during the same time window, will not produce any output action.
Every time the time window ends, besides producing an output action or not, all is (re)started from the
beginning and the program will be again waiting for new push button clicks.
More detailed description:
All variables are initialized as 0
Pin A5 (GP4) is initialized as 0
Pin A5 (GP5) is initialized as 1
Every time the push button (active low) connected to GP2/INT is clicked,
an interrupt (at the falling edge) is generated.
The program jumps to the INT0_Service macro where CameraControlPulseCount
variable is incremented by 1 to count the push button clicks and, at the 1st one, timer1
( internal clock source and a 1:8 prescaler, 1.907Hz ) is started (to create a time window
of 1.048 seconds as we will see).
On each timer1 interrupt TMR1_INT_COUNTER variable is incremented and, when it reaches
value 2 (1.048 seconds passed) timer1 interrupt will be disabled, gate pulse stopped, and its
registers loaded with 0 (to prepare for the next cycle).
After this the program will see if during the time window there was 2 clicks on the push button.
* If CameraControlPulseCount=2 BuzzerFlag will be set to 1
* If CameraControlPulseCount is different from 2 BuzzerFlag will be set to 0
After this all variables associated with timer1 counting will be set to 0
On main program, GP5 output is controlled
* if BuzzerFlag is 1, GP5 will be set to 0 (to sound an active low buzzer)
* if BuzzerFlag is 0, GP5 will be set to 1 (to stop sound an active low buzzer)
Also, as a mere time window visual reference, during timer1 counting
GP4 will be set to 1 to activate a LED (through TimerIsCounting variable).
The problem:
Simulated through Flowcode 6 simulator:
It indicates that apparently all is working well and CameraControlPulseCount variable starts
at 0 and is incremented correctly by 1 on each push button click .
Simulated through PIC Simulator IDE from oshonsoft.com :
When the 1st click occurs in the push button (the moment timer1 starts to count),
CameraControlPulseCount variable (PIC user register address 42 - found through .asm),
which was been initiated as a 0 from the beginning of the main program, is incremented
immediately by 2, instead of being incremented to 1 (jumping from value 0 to value 2).
After this wrong increment, the subsequent ones are correctly incremented by 1 .
Real PIC behavior:
If push button is clicked only once within the time window, at its end GP5 is cleared,
sounding the active low buzzer.
This is coherent with PIC Simulator IDE from oshonsoft.com as, for this to occur this way,
CameraControlPulseCount variable needed to be incremented from 0 to 2 with this only one push button click.
It would need 2 push button cklicks within time windows for GP5 to be cleared and sound the active low buzzer,
and not only one.
The most strange part is if I initialize CameraControlPulseCount with a value of 1 or more
from the beginning (when variables are initialized in main program), it is correctly incremented by
1 on each and every push button click.
.
Possible Bug with Calculation on incrementing variable by 1
Moderator: Benj
-
- Posts: 20
- Joined: Fri Dec 04, 2015 1:14 pm
- Location: Portugal
- Been thanked: 2 times
- Contact:
Possible Bug with Calculation on incrementing variable by 1
- Attachments
-
- timing diagram(as it should behave).JPG (42.06 KiB) Viewed 6283 times
-
- SymaX5SC1-BuzzerFinder_for_forum.asm
- (9.65 KiB) Downloaded 250 times
-
- SymaX5SC1-BuzzerFinder_for_forum.fcfx
- (14.1 KiB) Downloaded 269 times
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
Could you attach flowchart for us to investigate/ to reproduce the problem?
Ill just keep the good work up!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
Hello,
Thanks for providing such a detailed example. Liking your comment style
It seems strange that the problem is happening both in the external simulator and the hardware.
I do single increments all over the place in components so I don't think this has a problem. Seems to me the interrupt is firing twice for some reason.
With the hardware are you wiring up your switch as shown here with a bias resistor.
http://www.matrixtsl.com/wiki/index.php ... 9#Examples
You may also want to check your switch for bounce by adding a large capacitor 1uf - 100uf between GND and the switch pin, this should kill any bounce conditions and see if the problem still exists.
Thanks for providing such a detailed example. Liking your comment style
It seems strange that the problem is happening both in the external simulator and the hardware.
I do single increments all over the place in components so I don't think this has a problem. Seems to me the interrupt is firing twice for some reason.
With the hardware are you wiring up your switch as shown here with a bias resistor.
http://www.matrixtsl.com/wiki/index.php ... 9#Examples
You may also want to check your switch for bounce by adding a large capacitor 1uf - 100uf between GND and the switch pin, this should kill any bounce conditions and see if the problem still exists.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 20
- Joined: Fri Dec 04, 2015 1:14 pm
- Location: Portugal
- Been thanked: 2 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
Hi Benj
About the input:
It has a 1uF capacitor since the beginning, like in the attached file,
to filter out any noise.
About the real application :
Please note, although the Flowcode simulation has a push button to drive the external
interrupt input, in reality this pulse comes from my drone Syma X5 own microcontroller,
and even in this situation ( where there is button bounce ) at the 1st pulse the variable
is incremented by 2 (even with its rotors stopped to test with no additional noise) .
The goal is to use the remote control camera button, which, when clicked send a pulse
to the drone to take a shot.
I'm using this signal to do what the push button is doing in the simulation.
The Flowcode flowchart is at the PIC I put into the drone to receive this pulse.
If you can analyse my flowchart more deeply I will appreciate this very much,
as this problem is causing me big delays in the system I'm developing.
I although I can't see what is wrong, your're the expert ...
Thanks for your time.
I'm waiting to ear from you
About the input:
It has a 1uF capacitor since the beginning, like in the attached file,
to filter out any noise.
About the real application :
Please note, although the Flowcode simulation has a push button to drive the external
interrupt input, in reality this pulse comes from my drone Syma X5 own microcontroller,
and even in this situation ( where there is button bounce ) at the 1st pulse the variable
is incremented by 2 (even with its rotors stopped to test with no additional noise) .
The goal is to use the remote control camera button, which, when clicked send a pulse
to the drone to take a shot.
I'm using this signal to do what the push button is doing in the simulation.
The Flowcode flowchart is at the PIC I put into the drone to receive this pulse.
If you can analyse my flowchart more deeply I will appreciate this very much,
as this problem is causing me big delays in the system I'm developing.
I although I can't see what is wrong, your're the expert ...
Thanks for your time.
I'm waiting to ear from you
- Attachments
-
- button input.JPG (20.9 KiB) Viewed 6203 times
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
-
- Posts: 20
- Joined: Fri Dec 04, 2015 1:14 pm
- Location: Portugal
- Been thanked: 2 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
Hi
This is for Matrix staff:
Will this topic stay eternally without any further investigation ?
I'm starting to think your focus on your forum support needs a deep reformulation.
I'm very unsatisfied with your lack of attention here.
One answer here, another one there... I think definitely this is not what your Flowcode buyers need.
Isn't it time to have a permanent, dedicated forum only person (with Flowcode profound knowledge,
off course), to answer (every business day) all that questions that all we see staying for ever without answer ?
Sorry but, do you really cherish your customers ?
Thanks in advance,
This is for Matrix staff:
Will this topic stay eternally without any further investigation ?
I'm starting to think your focus on your forum support needs a deep reformulation.
I'm very unsatisfied with your lack of attention here.
One answer here, another one there... I think definitely this is not what your Flowcode buyers need.
Isn't it time to have a permanent, dedicated forum only person (with Flowcode profound knowledge,
off course), to answer (every business day) all that questions that all we see staying for ever without answer ?
Sorry but, do you really cherish your customers ?
Thanks in advance,
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
.
Thanks in advance,
---------------------------------------------
Miguel Garcia
Electronics Technician
Electronic Systems Developer
.
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
My fail, need glasses, thanks medelec! x)
Last edited by EtsDriver on Wed Dec 30, 2015 3:15 pm, edited 1 time in total.
Ill just keep the good work up!
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Possible Bug with Calculation on incrementing variable b
Hi miggarcbs,
What I believe is happening is:
When INT falling edge is detected and INT ISR is accessed then timer1 interrupt is enabled.
This is causing the interrupt flags to be rechecked.
Since INT flag has not been reset as INT ISR macro has not been exited, INT macro is being accessed again!
That would not show as occurring within Flowcode simulator
If I have got that correct then the solution is to enable Timer1 using
Or
Timer1 interrupt can be initilised using interrupt icon at the start of the flowchart just before Main loop.
I have modified your flowchart to test the theory out
Martin
What I believe is happening is:
When INT falling edge is detected and INT ISR is accessed then timer1 interrupt is enabled.
This is causing the interrupt flags to be rechecked.
Since INT flag has not been reset as INT ISR macro has not been exited, INT macro is being accessed again!
That would not show as occurring within Flowcode simulator
If I have got that correct then the solution is to enable Timer1 using
Code: Select all
st_bit(t1con,0);
Or
Code: Select all
st_bit(t1con,TMR1ON);
I have modified your flowchart to test the theory out
Martin
- Attachments
-
- SymaX5SC1-BuzzerFinder_for_forum 2.fcfx
- (13.58 KiB) Downloaded 256 times
Martin