Shop OBEX P1 Docs P2 Docs Learn Events
Pin glitch when cog stops. — Parallax Forums

Pin glitch when cog stops.

wch7693wch7693 Posts: 4
edited 2008-12-11 03:25 in Propeller 1
Hello all,

I am interfacing the Propeller to a stepper motor driver circuit implementing the L297 stepper motor controller. The L297 has a direction and step input, and generates the proper bit output sequence to drive an H-Bridge or whatever you're using to drive the stepper motor. I have developed a routine called RunMotor that sends the appropriate amount of pulses to the L297 to move it a specific number of steps at a given rotational speed. This routine works great, but when I put it in a separate cog to run it in the background, something happens on the direction and step pins when the routine ends and the cog stops that makes the motor go an additional unwanted step. I have verified that it happens at cog shutdown by putting a one second delay right before the routine ends, and the motor will move the correct amount of steps, wait a second, and then go an additional step.

So, my question is, is there a way to make a cog shut down such that when pins are low at the end of the routine, they stay low through shutdown and do not glitch?

Thanks,

Bill H.

Comments

  • RaymanRayman Posts: 14,243
    edited 2008-12-10 17:17
    I think you could set them to output low in your main cog before calling the other cogs.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-10 18:17
    You probably need to add pulldown and/or pullup resistors to set the default states of the L297's input pins. When a cog quits, the values it had set for DIRA revert to zeroes, leaving the pins it had exclusive output control over floating. When this happens, a pin can take any state, pretty much at random. This may be what's causing the glitch you're seeing.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
  • wch7693wch7693 Posts: 4
    edited 2008-12-10 19:02
    I put a 10k pull-down resistor on the step pin, it works great now! I also tried what Rayman suggested, but that did not work, I'm assuming because that involves or'ing a zero with the random state, which just gives you the random state.

    Thanks alot for your fast responses!
  • RaymanRayman Posts: 14,243
    edited 2008-12-11 00:52
    Did you set DIRA to 1 and OUTA to 0 on the pin in question in Spin before calling the cog? If you do this, and have the cog set DIRA and OUTA on this pin to 0 before stopping it, I think it should work...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-11 02:36
    Rayman,

    Your idea will work. However, it's not necessary for the cog that's terminating to do anything. DIRA is set to 0 automatically upon stopping.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
  • wch7693wch7693 Posts: 4
    edited 2008-12-11 03:08
    I tried setting the pin to an output and clearing it before starting the new cog, but it doesn't stop the glitch. The step input to the L297 is extremely sensitive, if you touch it with a wire it will trigger once and then if you scuff your shoes on the carpet the motor will start stepping multiple times (don't worry, I don't torture Propeller pins like this tongue.gif). So any kind of tiny fluctuation on the propeller output pin that's normally insignificant must be triggering it when the cog exits.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-11 03:25
    wch7693,

    The key to Rayman's proposal is to set DIRA to 1 and OUTA to 0 from a cog that remains alive. The cog that starts the L297 cog may, itself, terminate, rendering such settings impotent. OTOH, if the starting cog is the top-level cog, and it subsequently sets DIRA to some other value for another purpose, the prior setting will be lost. His idea will work. It just has to be implemented correctly.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
Sign In or Register to comment.