Shop OBEX P1 Docs P2 Docs Learn Events
PWM and stuff — Parallax Forums

PWM and stuff

sconyscony Posts: 14
edited 2014-11-24 10:17 in Propeller 1
Howdy,

I am building a quadcopter as my masters thesis. The goal of thesis is to compare few different platforms as core of quadcopter. For now I've choosen arduino and raspberry PI. I need third one, so I found parallax propeller. I'm very excited about 8 cores(cogs). However I am still not convinced should I buy it.

First of all, I would like to ask simple question for thoose who have propeller in home.
Say this is my code:
void xxx() 
{
  while(1)           
  {
    high(26);  //high or low, generally change of pin state
  }
}

int main()
{
  cog_run(&xxx, 10);
}
My question is, how many times per second will the line:
high(26);  //high or low, generally change of pin state
be executed ? I am asking, because I am curious how frequent and what resolution PWM can I generate just like that.

The second question is, can I generate PWM using some more complex approach ?

My goal generally is to produce PWM of at least 200Hz frequency with resolution of 1000 points, so I can set exactly say 49.9% duty cycle.

Comments

  • jmgjmg Posts: 15,173
    edited 2014-11-23 14:24
    scony wrote: »

    I am building a quadcopter as my masters thesis. The goal of thesis is to compare few different platforms as core of quadcopter. For now I've choosen arduino and raspberry PI. I need third one, so I found parallax propeller. I'm very excited about 8 cores(cogs). However I am still not convinced should I buy it.
    'core' is rather a loose term, and many Quadcopter designs may use more than one processor core.
    Weight is another factor.


    scony wrote: »
    My goal generally is to produce PWM of at least 200Hz frequency with resolution of 1000 points, so I can set exactly say 49.9% duty cycle.

    This is a good example, and shows where different 'cores' may have issues. (strengths/weakness)
    How many of these PWM channels do you need ?
    A single Prop COG can run at 20MOPs, and a software point rate of 200,000/s is what your spec calls for.
    You can 'fit' up to 100 opcodes into that 5us

    Browse the OBEX for PWM examples of various PWM approaches,with varying numbers of channels..
  • ErNaErNa Posts: 1,752
    edited 2014-11-23 14:32
    This may give you other hints on what can be done with a propeller: http://forums.parallax.com/showthread.php/137197-QuickStart-Servo-Tester
  • sconyscony Posts: 14
    edited 2014-11-23 14:44
    jmg wrote: »
    'core' is rather a loose term, and many Quadcopter designs may use more than one processor core.
    Weight is another factor.
    I know. I've already build quadcopter... I know I can use more cores, this is why I am excited (also important thing is, that is still realtime).
    jmg wrote: »
    How many of these PWM channels do you need ?
    As far as it is quadcopter, I do need 4 channels.

    Btw. Thanks ! This whole 'obex' seems legit. I see I ll probably need to use counters, so I can achieve better resolution.
  • jmgjmg Posts: 15,173
    edited 2014-11-23 15:10
    scony wrote: »

    Btw. Thanks ! This whole 'obex' seems legit. I see I ll probably need to use counters, so I can achieve better resolution.

    There are only 2 counters per COG, and they do not naturally do Low Frequency PWM (classic 2 edge per period) - they do however have a high frequency PWM mode, suited to RC DAC use.

    Software PWM can meet your resolution specs, quite easily, and with a little care, I think the SW-PWM could manage 1/25000 classic PWM ( 14.6 bits precision) on up to 18 pins (or 9 or 32) , using two cogs. (5ms period)

    One COG runs WAITCNT and pin updates 'flat-out' and the other COG converts the user PWM value to an array of WAITCNT : PinValues deltas + any other stuff at the 5ms rate.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-23 15:33
    Tachyon has a 32 channel 8-bit 7.6kHz PWM that only uses one cog and takes 1K of RAM for the pattern array. If you increase that table to 4K then you would achieve 10-bits of resolution at 1.9kHz update. Since it is table based you can still have some channels with high frequency and lower resolution or even just arbitrary patterns mixed in there too. This also allows for implementing dead-bands with variable offsets relative to other PWM signals.

    https://docs.google.com/document/d/1f4YFx_B5asn-ARQCsG16yNJoPDlvuH6ok6ZRIu_F5U4/pub#h.5ztoqjcun1ve
  • sconyscony Posts: 14
    edited 2014-11-23 15:35
    jmg wrote: »
    There are only 2 counters per COG, and they do not naturally do Low Frequency PWM (classic 2 edge per period) - they do however have a high frequency PWM mode, suited to RC DAC use.

    Software PWM can meet your resolution specs, quite easily, and with a little care, I think the SW-PWM could manage 1/25000 classic PWM ( 14.6 bits precision) on up to 18 pins, using two cogs. (5ms period)

    One COG runs WAITCNT and pin updates 'flat-out' and the other COG converts the user PWM value to an array of WAITCNT:PinValues deltas + any other stuff at the 5ms rate.

    Yeah right. I've been looking for solution for 1 cog that scales up, but I forgot, due to multicore environment I can make some co-op approach like you did.

    Well, thank you all. I am convinced now. I'lll order Propeller tomorrow.
  • MJBMJB Posts: 1,235
    edited 2014-11-24 01:35
    scony wrote: »
    Yeah right. I've been looking for solution for 1 cog that scales up, but I forgot, due to multicore environment I can make some co-op approach like you did.

    Well, thank you all. I am convinced now. I'lll order Propeller tomorrow.
    take your time to check the different available boards (unless you buld your own)
    either from parallax or other sources.
    They come in different sizes and with different IO capability. Servo headers, small motor drivers etc. some with ADC ... SD-Card ...
  • ratronicratronic Posts: 1,451
    edited 2014-11-24 08:33
    scony if you are going to use a Propeller for your quad Jason Dorie has posted some code here - http://forums.parallax.com/showthread.php/136787-QuadX-my-latest-Propeller-with-Propellers?highlight=quadx

    IIRC the flight code runs @ 250Hz.
  • sconyscony Posts: 14
    edited 2014-11-24 10:17
    ratronic wrote: »
    scony if you are going to use a Propeller for your quad Jason Dorie has posted some code here - http://forums.parallax.com/showthread.php/136787-QuadX-my-latest-Propeller-with-Propellers?highlight=quadx

    IIRC the flight code runs @ 250Hz.

    Thanks, I'll check this out. Anyway, I'll port my arduino's C code.
Sign In or Register to comment.