jerdee
02-25-2012, 04:53 AM
Hello...
I'm just digging into the spin code, so my question is very basic.
I am using Terminal to monitor voltages in a repeat loop. What I'd like to accomplish is the loop repeating string commands to terminal unill any any key is pressed on the keyboard. Basically I need CASE 3 to repeat until I press any button on a keyboard. As you can see I'm using terminal control in a separate COG. At the moment...the code waits for commands to send another set of string commands to monitor in Terminal...I want it to continuously monitor until I press a key. I have a strong feeling that the wait command is an issue.
I'm sure this is very easy to implement...but this a stumbling block for me at this time.
Thanks for your help in advance.
Jeremy
CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
OBJ
Debug : "FullDuplexSerialPlus"
ADC : "MCP3208"
fMath : "FloatMath"
fString : "FloatString"
VAR
Long value, dump, stack[128]
Byte pattern, pin1, pin2
Pub Main
cognew(Terminal, @stack[0])
cognew(Pulsewidth, @stack[50])
Pub Terminal
Debug.start(31, 30, 0, 115200)
waitcnt(clkfreq*3 + cnt)
Debug.tx(16)
repeat
Debug.Str(String(13,"__________________________________________________ ____________"))
Debug.Str(String(13,"1 = Inductor Settings | 2 = Cap Settings | 3 = Batt Voltages |"))
Case Debug.getDec
1:Debug.Str(String(13,"Microsecond / Pulse = "))
value := Debug.getDec
Debug.tx(13)
2:Debug.Str(String(13,"1 = Hold | 2 = Peak ADC |"))
Case Debug.getDec
1:Debug.Str(String(13,"Hold Value = "))
dump := Debug.getDec
Debug.tx(13)
2:Debug.Str(String(13, "Peak ADC = "))
Debug.tx(13)
3:Debug.Str(String(13,"Press any key to return to Main Menu"))
repeat until Debug.getdec
Debug.Str(String(13,"Input = "))
BattV((fmath.FFloat(adc.in(0))),0.0357142857142857 1428571428571429)
Debug.Str(String(" Output = "))
BattV((fmath.FFloat(adc.in(1))),0.0357142857142857 1428571428571429)
Debug.Str(String(" Batt Avrg = "))
AverageV
waitcnt(clkfreq*2 + cnt)
PUB Pulsewidth
value := 100 'Define Starting clock division
pin1 :=16 'Start pin for output pulsing
pin2 :=17 'End pin for output pulsing
dira[pin1..pin2] ~~ 'declare what series of pins as outputs
repeat
if pattern == 0 'Resets pattern
pattern := 'Flips first pin on in binary
waitcnt(clkfreq/1000000*value + cnt)
outa[pin1..pin2] := pattern 'Assign Pins to pattern
pattern >>= 1 'Shifts Pin State to the right
PUB BattV(adc_in,multfactor)| c
c := fmath.FMul(adc_in, multfactor)
debug.str(fstring.FloatToString(c))
PUB AverageV | a, b, c, d
a := fmath.Fmul((fmath.FFloat(adc.in(0))),0.0357142857)
b := fmath.Fmul((fmath.FFloat(adc.in(1))),0.0357142857)
c := fmath.Fadd(a,b)
d := fmath.Fdiv(c,fmath.FFloat(2))
debug.str(fstring.FloatToString(d))
I'm just digging into the spin code, so my question is very basic.
I am using Terminal to monitor voltages in a repeat loop. What I'd like to accomplish is the loop repeating string commands to terminal unill any any key is pressed on the keyboard. Basically I need CASE 3 to repeat until I press any button on a keyboard. As you can see I'm using terminal control in a separate COG. At the moment...the code waits for commands to send another set of string commands to monitor in Terminal...I want it to continuously monitor until I press a key. I have a strong feeling that the wait command is an issue.
I'm sure this is very easy to implement...but this a stumbling block for me at this time.
Thanks for your help in advance.
Jeremy
CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
OBJ
Debug : "FullDuplexSerialPlus"
ADC : "MCP3208"
fMath : "FloatMath"
fString : "FloatString"
VAR
Long value, dump, stack[128]
Byte pattern, pin1, pin2
Pub Main
cognew(Terminal, @stack[0])
cognew(Pulsewidth, @stack[50])
Pub Terminal
Debug.start(31, 30, 0, 115200)
waitcnt(clkfreq*3 + cnt)
Debug.tx(16)
repeat
Debug.Str(String(13,"__________________________________________________ ____________"))
Debug.Str(String(13,"1 = Inductor Settings | 2 = Cap Settings | 3 = Batt Voltages |"))
Case Debug.getDec
1:Debug.Str(String(13,"Microsecond / Pulse = "))
value := Debug.getDec
Debug.tx(13)
2:Debug.Str(String(13,"1 = Hold | 2 = Peak ADC |"))
Case Debug.getDec
1:Debug.Str(String(13,"Hold Value = "))
dump := Debug.getDec
Debug.tx(13)
2:Debug.Str(String(13, "Peak ADC = "))
Debug.tx(13)
3:Debug.Str(String(13,"Press any key to return to Main Menu"))
repeat until Debug.getdec
Debug.Str(String(13,"Input = "))
BattV((fmath.FFloat(adc.in(0))),0.0357142857142857 1428571428571429)
Debug.Str(String(" Output = "))
BattV((fmath.FFloat(adc.in(1))),0.0357142857142857 1428571428571429)
Debug.Str(String(" Batt Avrg = "))
AverageV
waitcnt(clkfreq*2 + cnt)
PUB Pulsewidth
value := 100 'Define Starting clock division
pin1 :=16 'Start pin for output pulsing
pin2 :=17 'End pin for output pulsing
dira[pin1..pin2] ~~ 'declare what series of pins as outputs
repeat
if pattern == 0 'Resets pattern
pattern := 'Flips first pin on in binary
waitcnt(clkfreq/1000000*value + cnt)
outa[pin1..pin2] := pattern 'Assign Pins to pattern
pattern >>= 1 'Shifts Pin State to the right
PUB BattV(adc_in,multfactor)| c
c := fmath.FMul(adc_in, multfactor)
debug.str(fstring.FloatToString(c))
PUB AverageV | a, b, c, d
a := fmath.Fmul((fmath.FFloat(adc.in(0))),0.0357142857)
b := fmath.Fmul((fmath.FFloat(adc.in(1))),0.0357142857)
c := fmath.Fadd(a,b)
d := fmath.Fdiv(c,fmath.FFloat(2))
debug.str(fstring.FloatToString(d))