PDA

View Full Version : PING, LCD, and cognew()



heathclf
12-31-2008, 11:22 AM
I'm able to grab range data, control a servo, and I'm able to write to an LCD. I'm just having trouble putting them together. I'm using objects from the propeller ObEx.

Ping Object
obex.parallax.com/objects/114/ (http://obex.parallax.com/objects/114/)

LCD Object
obex.parallax.com/objects/181/ (http://obex.parallax.com/objects/181/)

Right now, I am successfully getting range data from the Pinger, and writing it to the LCD, but when I try to control a servo (in order to move the ranger) using another cog, my program will no longer write my ranges, either bc it's not getting them, or bc it refuses to write, I'm not sure.

I originally tried controlling the servo in the main method, and writing to the LCD in the second method launched, in a new cog. This also does not work correctly. I have also tried increasing the memory in stack1[], which does nothing.

Any help would be much appreciated.

Thanks in advance.

Here's all of my code:




CON

_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

SERVO_Pin = 29
PING_Pin = 28
LCD_Pin = 27 ' I/O Pin For LCD
LCD_Baud = 19_200 ' LCD Baud Rate
LCD_Lines = 4

VAR byte i,j, stack1[100]
long HTa, range[10], rangeAve, HT, LT, TotTime, Hold

OBJ

LCD : "debug_lcd"
ping : "ping"

PUB main | CntNow

LCD.init(LCD_Pin, LCD_Baud, LCD_Lines)
LCD.backlight(false)
LCD.cursor(0)
LCD.cls

TotTime := 20000*80

dira[SERVO_Pin]~~
dira[10]~

HTa[0] := 1500*80 ' for servo positions
HTa := 1000*80
HTa := 2000*80

LCD.gotoxy(0, 0)
LCD.str(string("HighTime : "))
LCD.gotoxy(0, 1)
LCD.str(string("Range(in): "))

'cognew(ServoControl, @stack1[0]) 'if this line is NOT commented out, the program fails
'if it IS commented out, my servo (which moves the pinger) doesn't turn

repeat ' Repeat Forever
rangeAve := 0
repeat j from 0 to 9
range[j] := ping.Inches(PING_Pin) ' Get Range In Inches
waitcnt(clkfreq / 1000 + cnt) 'short pause for repop
rangeAve := rangeAve + range[j]
rangeAve := rangeAve / (j + 1) 'Average Range over 10 measurements

LCD.gotoxy(12, 0)
LCD.decf(HTa / 80, 4)
LCD.gotoxy(12, 1)
LCD.decf(rangeAve, 3) 'Print Range in Inches
LCD.str(string(".0 "))
CntNow := cnt

PUB ServoControl 'This routine is supposed to move my servo.
repeat
repeat j from 0 to 2
HT := HTa[j]
LT := TotTime - HT
waitcnt(LT + cnt)
outa[SERVO_Pin]~~
waitcnt(HT + cnt)
outa[SERVO_Pin]~

Oldbitcollector (Jeff)
12-31-2008, 11:36 AM
I'm sure one of our spin-code wizards will come up with a good answer,
but why not incorporate the servo object as well?

obex.parallax.com/objects/51/ (http://obex.parallax.com/objects/51/)

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Check out: Protoboard Introduction (http://jeffledger.googlepages.com/Protoboard_Introduction.pdf) , Propeller Cookbook 1.4 (http://ucontroller.com/Propeller%20Protoboard%20Designs%20for%20the%20Beg inner.pdf) & Software Index (http://forums.parallax.com/showthread.php?p=770318)
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us (http://propeller.warrantyvoid.us)
Got an SD card connected? - PropDOS (http://www.orrtech.net/propdos/)

Mike Green
12-31-2008, 12:22 PM
The main reason why your ServoControl method doesn't work is that each cog has its own I/O registers. You're setting the appropriate bit of the output register for the servo I/O pin, but the I/O pin is in input mode (in that cog). Take the "dira[ ServoPin ]~~" statement out of your main method and put it at the beginning of your ServoControl method (before the first repeat).

I haven't looked at the rest of your ServoControl method. You might have a look at the servo routine in BoeBotBasic which you can download from the Propeller Object Exchange. It's in BoeBotBasic.spin near line 1480, a method called ServoProcess. It's started around line 1260-1280 the first time a servo control statement is executed.

You might consider using BoeBotBasic for your experimentation. It uses the programming port for its console (at 9600 Baud) which is expected to be a terminal program on a PC rather than a serial LCD display.

heathclf
01-01-2009, 04:53 AM
Thanks, Oldbit.

Thanks, again, Mike.