Shop OBEX P1 Docs P2 Docs Learn Events
help serially communicating several different variables — Parallax Forums

help serially communicating several different variables

realolmanrealolman Posts: 65
edited 2010-06-19 14:11 in Propeller 1
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

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

  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-19 14:11
    You really need to start smaller. First you need to produce a program that just communicates between your Propeller and your PC. Use dummy values. After you get that working, you can combine it with the rest of what you want to do. You can put your communications program into a separate cog without changes for the transmit part (from the Propeller to the PC). The main problem you'll run into is on the receive side. Because the receive side will be changing variables on the Propeller, you have to make sure that the other Propeller cogs won't be changing the same variables at the same time. That depends on the details of what you're doing, but get the communications working first.

    Please attach your code using the Attachment Manager of the forum software. Using the CODE tags doesn't always work right.
Sign In or Register to comment.