Hi
First time I am posting here. Would appreciate any help since this is now driving me crazy. After 4 days I just cannot see the error I made in my program.
I wrote this rather simple code for 14M2 to count pulses for a duration of 1 second. The "count" value is placed in the variable b1. I then test with IF statements to switch on different LED's (one of eight) depending the value of b1 (the "count" value). Ironically the pwm generation and pulse count works fine (if checked with the debug) but the easier part (at least I thought so!) is a problem.
Now the problem:
For any value of 13 or less for b1 (as set in the little "Generic" window of the "simulation" panel) the correct "IF" is executed, i.e. the correct LED is switched on. However for any value 14 or above the program executes the "IF" of the third LED as well as the following one (the fourth LED)! If you increase the value more to let say something that should only switch only the fifth LED, all IF statements are executed, from the IF of the third LED to the IF of the fifth LED! This in now all in the Simulator (I am using Picaxe Programming Editor).
In real life (the circuit) only the LED up to the third one is switched on even for b1 values (as confirmed in the DEBUG window) that should switch on the fifth LED.
Please help. Will appreciate. Thanks in advance.
Below is the code:
First time I am posting here. Would appreciate any help since this is now driving me crazy. After 4 days I just cannot see the error I made in my program.
I wrote this rather simple code for 14M2 to count pulses for a duration of 1 second. The "count" value is placed in the variable b1. I then test with IF statements to switch on different LED's (one of eight) depending the value of b1 (the "count" value). Ironically the pwm generation and pulse count works fine (if checked with the debug) but the easier part (at least I thought so!) is a problem.
Now the problem:
For any value of 13 or less for b1 (as set in the little "Generic" window of the "simulation" panel) the correct "IF" is executed, i.e. the correct LED is switched on. However for any value 14 or above the program executes the "IF" of the third LED as well as the following one (the fourth LED)! If you increase the value more to let say something that should only switch only the fifth LED, all IF statements are executed, from the IF of the third LED to the IF of the fifth LED! This in now all in the Simulator (I am using Picaxe Programming Editor).
In real life (the circuit) only the LED up to the third one is switched on even for b1 values (as confirmed in the DEBUG window) that should switch on the fifth LED.
Please help. Will appreciate. Thanks in advance.
Below is the code:
Code:
main:
pwmout B.2, 23, 60 ; this statement just generates pulses for the IR LED that is driven for the IR receiver which generates the pulses for count (which gives me the rpm)
count 3,1000,b1
if b1 > 3 and b1 < 5 then ; LED NUMBER 1
high C.4
pause 500
low C.4
end if
if b1 = 5 or b1 > 5 and b1 < 8 then ; LED NUMBER 2
high C.2
pause 500
low C.2
end if
if b1 > 8 or b1 = 8 and b1 < 12 then ; LED NUMBER 3
high C.1
pause 500
low C.1
end if
if b1 > 13 or b1 = 13 and b1 < 17 then ; LED NUMBER 4
high C.0
pause 500
low C.0
end if
if b1 > 17 or b1 = 17 and b1 < 20 then ; LED NUMBER 5
high B.5
pause 500
low B.5
end if
if b1 > 20 or b1 = 20 and b1 < 25 then ; LED NUMBER 6
high B.4
pause 500
low B.4
end if
if b1 > 25 or b1 = 25 and b1 < 31 then ; LED NUMBER 7
high B.3
pause 500
low B.3
end if
if b1 > 31 then ; LED NUMBER 8
high B.1
pause 500
low B.1
end if
debug
b1 = 0
goto main
Last edited by a moderator: