Shop OBEX P1 Docs P2 Docs Learn Events
PING, LCD, and cognew() — Parallax Forums

PING, LCD, and cognew()

heathclfheathclf Posts: 43
edited 2008-12-31 21:53 in Propeller 1
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/

LCD Object
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[noparse]/noparse, 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[noparse][[/noparse]100]
        long HTa, range[noparse][[/noparse]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[noparse][[/noparse]SERVO_Pin]~~
  dira[noparse][[/noparse]10]~
  
  HTa[noparse][[/noparse]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[noparse][[/noparse]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[noparse][[/noparse]j] := ping.Inches(PING_Pin)                      ' Get Range In Inches
      waitcnt(clkfreq / 1000 + cnt)                          'short pause for repop
      rangeAve := rangeAve + range[noparse][[/noparse]j]
    rangeAve := rangeAve / (j + 1)                           'Average Range over 10 measurements
  
    LCD.gotoxy(12, 0)
    LCD.decf(HTa[i] / 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[noparse][[/noparse]j]                          
     LT := TotTime - HT
     waitcnt(LT + cnt)
     outa[noparse][[/noparse]SERVO_Pin]~~
     waitcnt(HT + cnt)
     outa[noparse][[/noparse]SERVO_Pin]~
[/i]

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-12-31 04:36
    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/

    OBC

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

    Check out: Protoboard Introduction , Propeller Cookbook 1.4 & Software Index
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-31 05:22
    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[noparse][[/noparse] 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.
  • heathclfheathclf Posts: 43
    edited 2008-12-31 21:53
    Thanks, Oldbit.

    Thanks, again, Mike.
Sign In or Register to comment.