Shop OBEX P1 Docs P2 Docs Learn Events
Cogs Competing for memory? — Parallax Forums

Cogs Competing for memory?

heathclfheathclf Posts: 43
edited 2008-11-06 00:52 in Propeller 1
Hey guys,

I just posted a few days ago, and Mike Green and BEEP definitely helped me with part of my problem, and now I'm hitting another wall which confuses me to death. Let me first say that all of my subroutines work just like they should (finally). The main program runs multiple cogs which keep time in various ways, monitor temperature, rpm's, blink lights, post serial out, etc. The problem is that I can run any 5 of of the six routines without a hitch (as far as I can tell, some inter dependencies make that a little tricky, but this seems to be the case. But when I run all 6, my Debugger won't report to my screen. (if anyone checks it out, I use Labview to parse it a little, so if it looks a little funny in hyper terminal, sorry. Just comma delimited numbers.) It seems that my servo is still being controlled correctly, but I have no way to tell if the sensors are still behaving.

Why won't all of them launch? I don't believe that my @stack arrays are running into each other, but I'm too new to this to be very confident in that statement.

The idea is simply this: A motor boat waits for a pin to be set high, at which point there is a countdown of 15 or so seconds. A blinking LED pattern is used as a warning. The motor ramps up, and ramps down. The temp, and rpms are monitored throughout, which are sent to a serial port at the moment, and which I'd like to log to a USB (and have done before, but the code is not included as I have other problems right now.) It's a pretty simple process, and I could probably consolidate a few of the time-keeping procedures, but I'd rather learn in this situation, instead of finding a kludge around it.

Unfortunately, it might be necessary for me to post all of my code, but I'll try to see if just posting the top few blocks is enough, just to spare you. If anyone wants to see more, just let me know, and I'd be glad to post it.




CON

  _xinfreq = 5_000_000                      
  _clkmode = xtal1 + pll16x

VAR
  Byte stack1[noparse][[/noparse]100], stack2[noparse][[/noparse]100], stack3[noparse][[/noparse]100], stack4[noparse][[/noparse]100], stack5[noparse][[/noparse]100], stack6[noparse][[/noparse]100]
  Byte lm34temp, secondsDelay, LEDPin, RPMPin, runState, servoPin
  
  long highTime, RPMs, counter, secondsTillLaunch, maxHigh, servoPeriod

OBJ
   Ser  : "FullDuplexSerial"

PUB main | minHigh, peakTime, slowRampCoeff, rampCoeff, relayPin, index

  'Servo
  maxHigh     := 1100*80
  minHigh     := 1000*80
  servoPeriod := 20000*80
  peakTime    := 2                'seconds
  runState    := 0                'what the motor is actually doing
  
  'The Coefficients affect the rate at which the motor ramps up and down
  slowRampCoeff := 1*80
  rampCoeff     := 1*80

  'Setting Pins
  servoPin  := 0
  RPMPin    := 15
  LEDPin    := 30
  relayPin  := 12

  'Serial Comm Vars          
  rxpin := 14
  txpin := 29
  mode  := 1
  baud  := 57600

  'WarningLED
  secondsDelay := 15

  ser.start(rxpin, txpin, mode, baud) 

  dira[noparse][[/noparse]relayPin]~

  highTime := minHigh
  
  coginit(1, PulseServo,       @stack1[noparse][[/noparse]0])

  repeat until ina[noparse][[/noparse]relayPin] == 1
     waitcnt(clkfreq / 5 + cnt)
      
  'Launching all the new Cogs
  coginit(2, TimerCountDown,   @stack2[noparse][[/noparse]0])
  coginit(3, ComputeMotorTemp, @stack3[noparse][[/noparse]0])  
  coginit(4, ReportingCog,     @stack4[noparse][[/noparse]0])
  coginit(5, RPM_Monitor,      @stack5[noparse][[/noparse]0])
  coginit(6, PulseWarningLED,  @stack6[noparse][[/noparse]0])
      
    'Makes sure propeller doesn't turn prematurely
    repeat while secondsTillLaunch
      waitcnt(clkfreq / 5 + cnt)
  
    'Ensures a SLOW ramp, moving the pulse ahead by VERY little for ~3 seconds
    runState := 1 
    repeat index from 1 to 30
      highTime := hightime + slowRampCoeff
      waitcnt(clkfreq / 10 + cnt)

    'FASTER ramp to max speed
    runState := 2
    repeat until  highTime == maxHigh
      highTime := highTime + rampCoeff
      highTime <#= maxHigh
      waitcnt(clkfreq / 30 + cnt)

    'Holding Maximum Speed for 'peakTime' seconds
    runState := 3
    waitcnt(clkfreq * peakTime + cnt)

    'Ramp Down sort of fast
    runState := 4
    repeat until hightime == minHigh
      highTime := highTime - rampCoeff
      highTime #>= minHigH
      waitcnt(clkfreq / 50 + cnt)

    runState := 0




Thanks, in advance for any help offered. Also, if anyone wants to pick on my code and suggest a better way, I'm definitely open to hearing it.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-05 23:12
    Do Not Use COGINIT! Use CogNew. The problem is that you're starting FullDuplexSerial and that starts up a cog to do the serial I/O, then you're doing COGINIT(1,...), COGINIT(2,...), and so on and probably the COGINIT(1,...) is overwriting cog 1 which was running FullDuplexSerial's I/O routine.
  • heathclfheathclf Posts: 43
    edited 2008-11-06 00:52
    Thanks, a lot Mike. If you ever need your lawn mowed or anything...you know...just holler.
Sign In or Register to comment.