Shop OBEX P1 Docs P2 Docs Learn Events
While Loop Problems — Parallax Forums

While Loop Problems

Atal1101Atal1101 Posts: 11
edited 2014-02-26 14:18 in Propeller 1
Hey all! Working on a project to control a stepper motor on a power drawbar for a milling machine. The program should run the motor in one direction if the UnclampSwitch is triggered until the UnclampedSwitch is triggered, with the same being true for the ClampSwitch and ClampedSwitch. In addition, lights should turn on if either the UnclampedSwitch or ClampedSwitch are triggered (UnclampedLight and ClampedLight, respectively). Here's the code I have so far:
CON
  _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
  _xinfreq = 5_000_000
  UnclampSwitch=0
  UnclampedSwitch=1
  UnclampedLight=18
  ClampSwitch=2
  ClampedSwitch=3
  ClampedLight=19
  PulseFrequency=1000 {In Hz}
  PulseWidth=50 {In uSeconds}
  StepPin=16 {Step pin of driver}
  DirPin=17 {Direction pin of driver}
VAR
  long Period
  long PauseTime
PUB Monitor
  dira[UnclampSwitch]~
  dira[UnclampedSwitch]~
  dira[UnclampedLight]~~
  dira[ClampSwitch]~
  dira[ClampedSwitch]~
  dira[ClampedLight]~~
  dira[StepPin]~~
  dira[DirPin]~~
  Period:=clkfreq/PulseFrequency
  PauseTime:=Period-PulseWidth
  Repeat
    If ina[ClampSwitch]~~ & ina[ClampedSwitch]~
      Clamp
    Elseif ina[UnclampSwitch]~~ & ina[UnclampedSwitch]~
      Unclamp
    If ina[ClampedSwitch]~~
      outa[ClampedLight]~~
    Elseif ina[UnclampedSwitch]~~
      outa[UnclampedLight]~~
    waitcnt(clkfreq/1000)
PUB Clamp
  outa[DirPin]~
  Repeat While (ina[ClampedSwitch]~)
    outa[StepPin]~~
    waitcnt(PulseWidth+cnt)
    outa[StepPin]~
    waitcnt(PauseTime+cnt)
  RETURN
PUB Unclamp
  outa[DirPin]~~                     
  Repeat While (ina[UnclampedSwitch]~)
    outa[StepPin]~~
    waitcnt(PulseWidth+cnt)
    outa[StepPin]~
    waitcnt(PauseTime+cnt)
  RETURN

I'm suspecting that its some small syntax problem somewhere, but I've got no clue what it might be. Anyone got any ideas?

Comments

  • davejamesdavejames Posts: 4,047
    edited 2014-02-26 14:10
    Hello Atal1101 - welcome to the Forum.

    I believe you need to relate what the problem is. That part seems to be missing.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-26 14:18
    I don't think you're using the right syntax for comparisons.

    Your code below:
    If ina[ClampSwitch]~~ & ina[ClampedSwitch]~
    

    looks like it's attempting to set the ina values. I don't recall ever seeing comparisons done this way and my guess is they wouldn't work as expected.

    I'd suggest changing this and other comparisons to something like this.
    If ina[ClampSwitch] == 1 & ina[ClampedSwitch] == 0
    
Sign In or Register to comment.