Odd behavior from my Propeller
DRMorrison
Posts: 81
I'm noticing some odd behavior from my Propeller, and am wondering if anyone else has seen this sort of thing, or can
tell me what I'm doing wrong here.
In the Main method below, upon startup, the first number printed for "i" is 22, unless I initiate it with i := 0
as shown below commented out. If I set i to zero at the top, then i gets printed as 0, as expected.
I understood that all local variables get set to 0 upon startup. Am I missing something here?
I've included the entire code, just in case my problem is someplace else and I'm not seeing it.
This is what it looks like on the LCD the first time thru:
-168938 delta
0 restarts
22 trials
0 pin 2
And then when I set i to zero, it looks like this:
-161433 delta
0 restarts
0 trials
0 pin 2
In both cases i increases by one each time thru the repeat loop, and is updated to the LCD screen.
And I've reloaded this numerous times. I've even tried loading this into EEPROM.
Daniel
tell me what I'm doing wrong here.
In the Main method below, upon startup, the first number printed for "i" is 22, unless I initiate it with i := 0
as shown below commented out. If I set i to zero at the top, then i gets printed as 0, as expected.
I understood that all local variables get set to 0 upon startup. Am I missing something here?
I've included the entire code, just in case my problem is someplace else and I'm not seeing it.
This is what it looks like on the LCD the first time thru:
-168938 delta
0 restarts
22 trials
0 pin 2
And then when I set i to zero, it looks like this:
-161433 delta
0 restarts
0 trials
0 pin 2
In both cases i increases by one each time thru the repeat loop, and is updated to the LCD screen.
And I've reloaded this numerous times. I've even tried loading this into EEPROM.
Daniel
CON _clkmode = xtal1 _xinfreq = 5_000_000 RC_Pin = 0 'circuit input pin LCD_TX = 1 'LCD comm pin VAR LONG Value, starts, r1, r2 OBJ LCD : "FullDuplexSerial.spin" PUB Initiate LCD.start(LCD_TX, LCD_TX, 00, 19_200) waitcnt(clkfreq/100 + cnt) LCD.tx(12) 'clear screen, Form Feed waitcnt(clkfreq/100 + cnt) ' must wait 5ms after a Form Feed LCD.tx(22) dira[1]~~ 'LCD tx on pin 1 dira[16]~~ Main PUB Main | i, pinstate 'i := 0 [COLOR=#ff0000] 'IF I DON'T USE THIS, i PRINTS AS 22 INITIALLY[/COLOR] repeat Check_Phone LCD.tx(128) 'line 0, pos 0 LCD.dec(r2 - r1) 'print diff. LCD.str(string(" delta ")) LCD.tx(148) 'line 1, pos 0 LCD.dec(starts) 'print average LCD.str(string(" restarts ")) LCD.tx(168) 'line 1, pos 0 LCD.dec(i) [COLOR=#ff0000] 'THIS IS PRINTING AS 22, UNLESS SET TO 0 FIRST[/COLOR] LCD.str(string(" trials ")) LCD.tx(188) pinstate := ina[2] LCD.dec(pinstate) LCD.str(string(" pin 2 ")) i += 1 PUB Check_Phone | delta 'Phone watchdog; check to see it phone is ON FN Measure r1 := Value outa[16]~~ 'Force leds to light waitcnt(cnt + clkfreq/2) Measure r2 := Value outa[16]~ ctra := 000 << 26 delta := r2 - r1 if delta <= 0 'if lights are on, return, else start phone return Start_Phone PRI Measure 'Use RC circuit to check phone's status ctra := 000 << 26 | RC_Pin ' Setup frqa := 1 outa[RC_Pin]~~ ' Set pin to 3.3V dira[RC_Pin]~~ ' Set pin as output waitcnt(cnt + clkfreq / 1000) ' charge the capacitor for 500u phsa := 0 ' clear counter dira[RC_Pin]~ ' set pin as input waitpne(|< RC_Pin,|< RC_Pin, 0) ' wait for to V get to 1.6V Value := phsa ' store the count in the array waitcnt(cnt + clkfreq / 10) PUB Start_Phone 'Cycle phone's power button FN starts += 1
Comments
-Phil
Thanks, Daniel