Shop OBEX P1 Docs P2 Docs Learn Events
Need more cogs! — Parallax Forums

Need more cogs!

DiverBobDiverBob Posts: 1,110
edited 2014-02-01 20:25 in Propeller 1
For the first time I've come into the situation that I need more than 8 cogs. Since that is a fixed limitation, I'm looking at different objects that can perform the same or similar functions with either no additional cogs or reduce the cogs being called. The application uses 3 cogs, one each for motors that need to be able to run independently of each other. Another cog is used to continuously update global variables from 4 ADC channels using a MCP3208. The remaining cogs are using the following objects
• Parallax serial Terminal - 1 cog, used for troubleshooting software, will not be needed later but critical at this stage
• Servo32_9 - 2 cogs, great servo controller but I think this could be replaced by a 1 cog option.
• Float32full - 2 cogs, I think Float32 can perform the same basic functions with 1 cog

I think I need to really replace servo32-9. It looks like either jm_servo8_adv or pwm_32 would be a good choice and both only use one cog.
Another option would be to take the ADC off its own cog and let the routines call the ADC routine when they need the value.
I'll be doing some experimenting with the above but wanted to see if others had some different approaches. Any opinions out there or are there other options I'm not seeing?

As always, thanks for the help!

Bob

Comments

  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-01 11:59
    As long as you're using 8 servos or less, my servo object gives you servo control plus ramping in a single cog.

    I've attached my latest version. At the moment, I'm working on an update to allow up to 16 servos and improve the ramping resolution by switching from microseconds to system ticks (internal values only -- user interface won't change).
  • John AbshierJohn Abshier Posts: 1,116
    edited 2014-02-01 12:04
    F32 provides the functionality of Float32full and only uses one cog.

    http://obex.parallax.com/object/229

    Servo32 (I looked at version 7) only uses one cog if you don't sue the ramp function.

    John Abshier
  • DiverBobDiverBob Posts: 1,110
    edited 2014-02-01 13:07
    JonnyMac wrote: »
    As long as you're using 8 servos or less, my servo object gives you servo control plus ramping in a single cog.

    I've attached my latest version. At the moment, I'm working on an update to allow up to 16 servos and improve the ramping resolution by switching from microseconds to system ticks (internal values only -- user interface won't change).
    Since I'm already using your MCP3208 object, I'll give this one a try! I've only got 3 motors to control via HB25's so they act like servos... I use 10K pots for position feedback into the code.

    I tried out Float32 and it seems to work OK, what's the difference between it and F32?

    I moved my ADC routine out of a cog but managed to break the code, troubleshooting that mess now. I may just move it back into its own cog again if I don't figure this out before my frustration level gets much higher... I hate it when a supposedly simple change just has much larger impact than ever expected!
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-01 13:23
    I've used my MCP3208 (Spin-only) object in a couple motor-control projects -- one with DC motors (camera platform), the other with servos (focus/zoom controller).

    In both cases, we structured the main loop something like this:
    main | t, ch, acc[3], pot
    
      t := cnt
      repeat
        longmove(@acc, 0, 3)                                        ' clear accumulators
        repeat 4                                                    ' get four samples
          repeat ch from 0 to 2                                     ' loop through channels
            acc[ch] += adc.read(ch, adc#SE)                         ' accumulate readings
      
        repeat ch from 0 to 2
          pot := acc[ch] >> 2                                       ' average samples
          ' other math here
    
        waitcnt(t += (clkfreq / 50))
    


    Total loop timing needs to be adjusted for channels, averaging, other processes.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2014-02-01 14:55
    F32 is and improved (my opinion) by lonesock. The only negative is loss of the user-defined function mechanism. I have never used the user-defined function mechanism. I don't know why Parallax has not replaced Float32full or at least added F32.

    John Abshier
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-01 15:18
    Are the three motor cogs PWM?

    What sort of resolution and what frequency do you need?

    I'm pretty sure I've posted my four motor PWM object (though not in the OBEX) .

    BTW, pwm_32 isn't a good choice for motors. the "frequency" is much too fast for some controllers.

    Edit: I think my four channel PWM object also monitors four quadrature encoders. I'm sure I could be persuaded to clean out the encoder section if you just want to use the PWM section.
  • RforbesRforbes Posts: 281
    edited 2014-02-01 16:31
    Maybe use simple serial insteas of PST? It's slower but might be suitable for your needs.
  • DiverBobDiverBob Posts: 1,110
    edited 2014-02-01 16:48
    Good suggestions! Let me try these out and I'll report back on progress
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-01 17:06
    I like to use the counters for motor PWM -- easy to code in Spin and you can get control of two motors and PWM frequencies up to about 30kHz (if I'm remembering correctly).

    I've attached the project files from my July 2011 N&V column.
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-02-01 17:26
    with propforth,
    - add more cogs by adding physical prop chips, (MCS)
    - control 8 servos with one cnt on one cog (I forget exactly how many can be controled, but you run out of pins before you run out of counters)
    - use the float extension if you don't mind slow or use double and do it integer if you want fast.

    But you have to start with the forth so that would be cheating
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-01 17:46
    But you have to start with the forth so that would be cheating

    <snark>Yes, suggesting he start from scratch with a new language he may not know is always very helpful...</snark>
  • DiverBobDiverBob Posts: 1,110
    edited 2014-02-01 17:55
    Thanks for the Forth suggestion but learning a new language right now is something I'd like to avoid for the time being!

    Johnny, I tried your servo object, the Set command works pretty well. The move command works but as it accelerates there are some hesitations like a counter is rolling over/overflowing or something like that. I'm not planning on using the move command but thought you might like to know. Since I'm actually controlling DC motors in a linear actuator via an HB25 using 10K pots for position feedback the movement time is considerably greater than you would have experienced with a standard servo.

    Anyway, it works on a test program, now I'll shoehorn it into my ramping routine and se how it behaves.

    Bob
  • DiverBobDiverBob Posts: 1,110
    edited 2014-02-01 18:29
    After I put the ADC routine back under its own cog (I forgot that it has to be in its own cog so it can update the global ADC variables that the motor cogs can call) the ramping is working with the new jm_servo8 object. I've changed to float32 (1 cog) for floating point math. That leaves the PST object (1 cog), 3 cogs for motors and 1 cog for ADC. That's 7 cogs which leaves one cog for running the RGB light strip! Sure hope I don't find I need to add any thing else! I will free up the PST cog later but I really need it to test this beast.

    Thanks for the quick help, this is definitely the place to go to get it. I want to play with your dual motor code once I get a break.
  • msrobotsmsrobots Posts: 3,709
    edited 2014-02-01 19:25
    Bob,

    way to go. I follow your thread for a while now and am impressed with your work.

    You are talking about getting rid of PST later, but how do your Leg controllers will talk to each other / some master controller?

    I guess you still need that PST cog fore some form of communication between them, or not?

    Anyways - one cog for LED strips is cool. Even animations possible. What a beast.

    Enjoy!

    Mike
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-01 20:25
    Johnny, I tried your servo object, the Set command works pretty well. The move command works but as it accelerates there are some hesitations like a counter is rolling over/overflowing or something like that.


    I've never seen that myself, but I'll look into it. As said, I'm working on a version that [internally] uses system ticks instead of microseconds -- at 80MHz this result in an 80x improvement in granularity (at 80MHz system clock). I believe it will help, especially in ramping.
Sign In or Register to comment.