Shop OBEX P1 Docs P2 Docs Learn Events
Pitfalls and crawling out... GetSec() behaves not as I expected, to slow and counting down - Page 3 — Parallax Forums

Pitfalls and crawling out... GetSec() behaves not as I expected, to slow and counting down

13»

Comments

  • JonnyMacJonnyMac Posts: 9,824

    I've attached my quadrature encode object that uses smart pins. Perhaps it will help you get started.

  • ErNaErNa Posts: 1,859
    edited 2026-04-15 19:31

    Thanks, Jon. Indeed, it was a great starting point. Btw: I like your versioning system. One remark: those rotary switches come in two variants: the solid versions intended for CNC machining and else actually show a quadrature signal. The cheap input switches often output a clock/direction signal. It can be decoded as a quadrature signal, but then four state changes stand for one increment.
    The smart pins are just great. They do the dirty work in real time and you fetch a result whenever needed. It's like watching a tanker passing by and just take it, if you are in the mood.

  • ErNaErNa Posts: 1,859

    Just a short question: I'm trying to use debug() on a P2 using a PropPlug, but lose debug communication. Another board with an USB-C works fine. Is this a known issue and is there a workaround? (I still use the outdated Propeller Tool 2.9.3

  • JonnyMacJonnyMac Posts: 9,824

    Old Propeller Tool can be twitchy; you could try PNut or Spin Tools (for a nicer environment). If you really want to use Propeller Tool, you could try lowering the DEBUG baud rate using the DEBUG_BAUD constant).

  • ErNaErNa Posts: 1,859

    Debug_baud didn't solve the problem. I have a KISS board and a PropPlug. I'm looking to attach a display to the prop2, I normally use as debug output, but as there is no driver, I can not display status information. But I have to stop writing the driver, as the documentation is about 200 pages and the esp example is huge, so I'll fall back on my small display for now.

  • evanhevanh Posts: 17,243

    Dodgy USB cables have caused no end of trouble in the past. Make sure you've swapped to a known good cable before looking elsewhere.

  • MicksterMickster Posts: 2,927

    @ErNa said:
    There is no way around the smart pins. Next task: adopt an incremental encoder. There is a quadrature counting mode, I will look for examples and it should work. One short question ahead: is there a way to use the index signal to reset the counter? Alternatively I have to look for the index just once and then handle the over- / underflow manually.

    Edit: Found some info in the hardware manual, chapter smart pins. Looks we can measure speed, have to study the docu..

    Only just saw this; No, the index can't zero the quad count. We can snapshoot the count and apply it as an offset. Typically, you look for a homing input, stop the motor, move off the the homing sensor (or not) and look for the next index pulse. For extra precision, the index can be gated with A and B but I believe that would have to happen in hardware (3-input AND) because I asked, some time ago whether we could directly read the level of the A and B pins when in quad mode and the response was negative.

    Speed control: Presumably we are talking PID?

    You have a servo sampling period of say, the typical 1KHz.
    Incrementing the CmdPosition per sample gives you velocity control. Below would result in 2000 mm/sec.

    CmdPosition = CmdPosition + 2mm
    MotorCmd = CmdPosition - ActualPosition

Sign In or Register to comment.