help serially communicating several different variables
realolman
Posts: 65
I would like to serially communicate, and then "transfer" values to and from several different variables in the propeller.
devoting ·a cog in the prop just for serial comms.
There is an array of "Parameters" ·that I want to fill from a visual basic program to the prop, and a cog on the prop to count pulses from an encoder (360°)... when the count is equal to, or 20 counts above the parameter, I want it to lite an LED.· In this program there are five variables I would like to compare to the count and lite LEDs.· In reality, I would like to expand this to maybe 20 or 30.· Also I would like to be able to transfer values back from the prop to the VB program.
I am having difficulty keeping them all straight and getting them to the correct variables.... doesn't seem to be very reliable.
Also I would like to transmit from the propeller· only variables that have changed.· maybe using if - then statements or something similar.
I think the part of interest would be in bold type
Could someone give me a hand with something that would be reliable... thanks
devoting ·a cog in the prop just for serial comms.
There is an array of "Parameters" ·that I want to fill from a visual basic program to the prop, and a cog on the prop to count pulses from an encoder (360°)... when the count is equal to, or 20 counts above the parameter, I want it to lite an LED.· In this program there are five variables I would like to compare to the count and lite LEDs.· In reality, I would like to expand this to maybe 20 or 30.· Also I would like to be able to transfer values back from the prop to the VB program.
I am having difficulty keeping them all straight and getting them to the correct variables.... doesn't seem to be very reliable.
Also I would like to transmit from the propeller· only variables that have changed.· maybe using if - then statements or something similar.
I think the part of interest would be in bold type
Could someone give me a hand with something that would be reliable... thanks
OBJ SER : "Extended_FDSerial" VAR byte ControlCharacter byte Control word Parameter[noparse][[/noparse]100] 'array of parameters for I/O long WhichVariable 'which parameter long InputVariable 'value of parameter long CountVariable 'for counter / encoder accumulation long Stack[noparse][[/noparse]40] 'place to run Serial communications long CountStack[noparse][[/noparse]40] 'place to run Counter for encoder long CompStack[noparse][[/noparse]40] 'place to compare counter accumulator 'to variables long OldCount 'put counter accumulator number after 'transmission to keep from re-transmitting long IndexCounter 'used to iterate thru parameters CON ' spin stamp '_CLKMODE = XTAL1 + PLL4X ' clock speed too low = 1X=10Mhz '_XINFREQ = 10_000_000 ' non-spin stamp _CLKMODE = XTAL1 + PLL8X ' clock speed too high = 80Mhz _XINFREQ = 5_000_000 PUB Main cognew (Serial, @Stack) 'serial comms [b]Pub Serial 'handle serial transmissions ser.start(31,30,0,38400) repeat If ser.rxcheck <> -1 ControlCharacter := ser.RxStr (Control) Case ControlCharacter "*": ser.str(Control) Control:=" " ControlCharacter := " " "#": WhichVariable := ser.rxDec 'receive a number and a carriage return chr(13) ser.dec(WhichVariable) 'transmit a number and carriage return Control:=" " ControlCharacter := " " Other : ser.dec(3333) PUB CountInput 'set counter to positive edge detector 'shifts the %01010 over to the appropriate position CTRA := %01010 << 26 ctra := ctra + 10 'sets counter to use pin 10 frqa:=1 'must set to non zero so it counts up 'read accumulator value and store in variable repeat CountVariable:=phsa ' reset counter to 0 when it reaches 360 If phsa=>1200 phsa:=0 pub CountCompare Dira[noparse][[/noparse]15..20]~~ 'set pins P15 - P20 as outputs repeat ' endless loop repeat IndexCounter from 15 to 20 ' 'compare parameter array to encoder counter 'if counter value is between the array value and the value of the array 20 places above it, 'turn on the corresponding output.. otherwise turn it off if CountVariable > Parameter[noparse][[/noparse]IndexCounter] AND CountVariable < Parameter[noparse][[/noparse]IndexCounter+20] outa[noparse][[/noparse]IndexCounter]~~ else outa [noparse][[/noparse]IndexCounter]~[/b]
Comments
Please attach your code using the Attachment Manager of the forum software. Using the CODE tags doesn't always work right.