Need help on my project, repeat & If/Else statement not working correctly
jknightandkarr
Posts: 234
I need help with my project. Under the "PUB Speed(dLow, digits, s0, enabled)" area is where my problem is. Not sure why.
First problem:
When I put pin 13 high & hit reset, the display doesn't change, should go from 0603 to 0301, but doesn't. I tried ina[noparse][[/noparse]13]:=0 & the display stays 0301 wether pin 13 is high or grounded. So why isn't my code working as it's suppose to?
Second Problem:
When I remove the ' from 'repeat, the display fails to function entirely? I need the section too loop so I can have a constantly updated speed reading as well as adding
when the first part of the code is funtioning
What is wrong with these code lines? Thanks.
Here's my whole project code thus far....
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
First problem:
If ina[noparse][[/noparse]13]==0 'Look for Pin23 for 1 or 0
Mph:=vss*9 'Calibrate for 4000ppm sender if pin 13=Low
else
Mph:=vss*9/2 'Calibrate for 8000ppm Sensor if pin 13=High
When I put pin 13 high & hit reset, the display doesn't change, should go from 0603 to 0301, but doesn't. I tried ina[noparse][[/noparse]13]:=0 & the display stays 0301 wether pin 13 is high or grounded. So why isn't my code working as it's suppose to?
Second Problem:
PUB Speed(dLow, digits, s0, enabled)
'' Start the display
'' Parameters:
'' dLow - the pin number of the least significant digit
'' digits - the number of digits to display (up to 8)
'' s0 - the pin number of segment 0
'' enabled - the initial enabled state
dira[noparse][[/noparse]13]:=0 'Set pin 23 as input
repeat
vss:=67
If ina[noparse][[/noparse]13]==0 'Look for Pin23 for 1 or 0
Mph:=vss*9 'Calibrate for 4000ppm sender if pin 13=Low
else
Mph:=vss*9/2 'Calibrate for 8000ppm Sensor if pin 13=High
myValue := Mph 'Copy Mph to myValue
LowDigitPin := 8
HighDigitPin := 8 + ((4 - 1) <# 7) 'Limit to eight digits
Seg0Pin := 0
Seg8Pin := 0 + 7
dira[noparse][[/noparse]Seg0Pin..Seg8Pin]~~ 'Set segment pins to outputs
dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Set digit pins to outputs
outa[noparse][[/noparse]Seg0Pin..Seg8Pin]~ 'Turn off all segments
dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Turn off all digits
' if enabled 'Set initial enabled state
flags |= isEnabled
'else
'flags~
stop
runningCogID := cognew(ShowValue, @myStack) + 1
When I remove the ' from 'repeat, the display fails to function entirely? I need the section too loop so I can have a constantly updated speed reading as well as adding
Pub Start
cognew (Signal, @stack0) 'Vehical Speed Sensor Input/disable till display is working & calibrated
cognew (Speed, @stack1) 'Speedometer display
cognew (Odometer, @stack2) 'Odometer display/program not written yet.
Pri Signal
'Calibrate for 4000 & 8000 pulses per mile
'Use switch to switch between 4K & 8K inputs
Repeat
Dira[noparse][[/noparse]12]~
ctra:=0
ctra:=(%01010<<26)|(%001<<23)|(0<<9)|(12)
frqa:=1
phsa:=0
waitcnt(80_000_000+cnt)
vss:=phsa
ctra:=0
when the first part of the code is funtioning
What is wrong with these code lines? Thanks.
Here's my whole project code thus far....
{{General purpose Seven-segment display object. Can control from one to eight digits.
Author: Steve Nicholson
Version: 1.0 (4 Jan 2007)
Email: ssteve@mac.com
Copyright: none
Modified:Joe R.
}}
CON
_clkmode =xtal1+pll16x 'system clock
_xinfreq=5_000_000 'set 80 Mhz
isEnabled = %0001
VAR
long LowDigitPin, HighDigitPin 'The pins for specifying digits.
'Must be contiguous
'HighDigitPin can be from 0 to 7 more than LowDigitPin
long Seg0Pin, Seg8Pin 'The pins for the segments.
'Must be contiguous
'Segment 8 is the decimal point
long flags
long myStack[noparse][[/noparse]10]
long runningCogID
long myValue 'Value to be displayed
long vss 'Vehical Speed Sensor Input
long Mph 'Display In Miles Per Hour
PUB Speed(dLow, digits, s0, enabled)
'' Start the display
'' Parameters:
'' dLow - the pin number of the least significant digit
'' digits - the number of digits to display (up to 8)
'' s0 - the pin number of segment 0
'' enabled - the initial enabled state
dira[noparse][[/noparse]13]:=0 'Set pin 23 as input
'repeat
vss:=67
If ina[noparse][[/noparse]13]==0 'Look for Pin23 for 1 or 0
Mph:=vss*9 'Calibrate for 4000ppm sender if pin 13=Low
else
Mph:=vss*9/2 'Calibrate for 8000ppm Sensor if pin 13=High
myValue := Mph 'Copy Mph to myValue
LowDigitPin := 8
HighDigitPin := 8 + ((4 - 1) <# 7) 'Limit to eight digits
Seg0Pin := 0
Seg8Pin := 0 + 7
dira[noparse][[/noparse]Seg0Pin..Seg8Pin]~~ 'Set segment pins to outputs
dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Set digit pins to outputs
outa[noparse][[/noparse]Seg0Pin..Seg8Pin]~ 'Turn off all segments
dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Turn off all digits
' if enabled 'Set initial enabled state
flags |= isEnabled
'else
'flags~
stop
runningCogID := cognew(ShowValue, @myStack) + 1
PUB Stop
'' Stop the display
if runningCogID
cogstop(runningCogID~ - 1)
PUB Enable
'' Enable the display
flags |= isEnabled
PUB Disable
'' Disable the display
flags &= !isEnabled
PUB SetValue(theValue)
'' Set the value to display
myValue := theValue
PRI ShowValue | digPos, divisor, displayValue
' ShowValue runs in its own cog and continually updates the display
dira[noparse][[/noparse]Seg0Pin..Seg8Pin]~~ 'Set segment pins to outputs
dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Set digit pins to outputs
repeat
if flags & isEnabled
displayValue := myValue 'take snapshot of myValue so it can't be changed
' while it is being displayed
divisor := 1 'divisor is used to isolate a digit to display
repeat digPos from 0 to HighDigitPin - LowDigitPin 'only display as many digits as there are pins
outa[noparse][[/noparse]Seg0Pin..Seg8Pin]~ 'clear the segments to avoid flicker
outa[noparse][[/noparse]LowDigitPin..HighDigitPin] := byte[noparse][[/noparse]@DigSel + digPos] 'enable the next digit
outa[noparse][[/noparse]Seg0Pin..Seg8Pin] := byte[noparse][[/noparse]@Digit0 + displayValue / divisor // 10] 'display the digit
waitcnt (clkfreq / 10_000 + cnt) 'the delay value can be tweaked to adjust
' display brightness
divisor *= 10
else
outa[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'disable all digits
waitcnt (clkfreq / 10 + cnt) 'wait 1/10 second before checking again
DAT
'Common cathode 7-segment displays are activated by bringing the cathode to ground
DigSel byte %11111110
byte %11111101
byte %11111011
byte %11110111
byte %11101111
byte %11011111
byte %10111111
byte %01111111
Digit0 byte %00111111
Digit1 byte %00000110
Digit2 byte %01011011
Digit3 byte %01001111
Digit4 byte %01100110
Digit5 byte %01101101
Digit6 byte %01111101
Digit7 byte %00000111
Digit8 byte %01111111
Digit9 byte %01100111
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol

Comments
Is it just a typo ?
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
·
dira[noparse][[/noparse]Seg0Pin..Seg8Pin]~~ 'Set segment pins to outputs dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Set digit pins to outputs outa[noparse][[/noparse]Seg0Pin..Seg8Pin]~ 'Turn off all segments dira[noparse][[/noparse]LowDigitPin..HighDigitPin]~~ 'Turn off all digitsshould the last dira be an outa.
Graham
Yeah, it's just a typo, it was 23, but I changed it due to the design of the PropRPM, figured the Pin23 having 3.3V+ all the time I thought that might have been my problem.
I'll see if that makes any difference. Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
Just changed that dira to outa, made no difference.
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
All ready is enabled.
I disabled the stop with 'stop & got my 3 back, but 060 still to go. with repeat the display program is apperently freezing. Maybe I"ll hook ny bs2 up & use it to generate a signal & see if I even need the repeat loop.
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
Graham
I used my basic stamp 2 to generate a frequency, that should have displayed 0603 on the propeller, but now displays random numbers when they are connected togeather instead of my desired speed reading. When I have the Basic Stamp 2's signal disconnected, the propeller gives me 0000 as it should, but why am I getting random numbers?.
' {$STAMP BS2} ' {$PBASIC 2.5} DO FREQOUT 15, 1000, 67 LOOPwww.newarkknights.net/mycode.zip
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
-Phil
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
Post Edited (jknightandkarr) : 2/16/2010 10:22:01 PM GMT
The speed sensors should have a square-wave output; but I've never used one, so that's just a reaonable guess.
-Phil
I was using the basic stamp 2, so I could see the change on the propeller, just like if I was using a vehical speed sensor
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol