Menu

Think first

2018-06-05
2018-06-16
  • stan cartwright

    stan cartwright - 2018-06-05
     
  • stan cartwright

    stan cartwright - 2018-06-06

    I bought a 16 channel pwm driver after realising my pic and uno didn't have 4 channel at the same frequency but different pwm. Not working after too long trying.
    So I just sent off for an arduino 2560 cos someone said it got 14 pwm channels.
    Then I thought can all pwm be 50 or 60 hz and different pwm.
    and gcb avr pwm is different to pic pwm..is it?
    this is arduino stuff.
    can I get 14 channe pwm at 60hz each different pwm .75 to 2.25 ms ?

    prescaler = 1 ---> PWM frequency is 31000 Hz
    prescaler = 2 ---> PWM frequency is 4000 Hz
    prescaler = 3 ---> PWM frequency is 490 Hz (default value)
    prescaler = 4 ---> PWM frequency is 120 Hz
    prescaler = 5 ---> PWM frequency is 30 Hz
    prescaler = 6 ---> PWM frequency is <20 Hz

    (prescalers equal t 0 or 7 are useless).

    Those prescaler values are good for all timers (TCCR1B, TCCR2B, TCCR3B, TCCR4B) except for timer 0 (TCCR0B). In this case the values are:

    prescaler = 1 ---> PWM frequency is 62000 Hz
    prescaler = 2 ---> PWM frequency is 7800 Hz
    prescaler = 3 ---> PWM frequency is 980 Hz (default value)
    prescaler = 4 ---> PWM frequency is 250 Hz
    prescaler = 5 ---> PWM frequency is 60 Hz
    prescaler = 6 ---> PWM frequency is <20 Hz

     
  • stan cartwright

    stan cartwright - 2018-06-06

    Since I want to control maybe 8 servos I thought 1 pwm and a 1 to 8 demux chip like74238 or similar.
    Another idea was mcp i2c expander and a 20ms interrupt to turn on 8 lines to servos then start a timer and switch each servo off when the timer reaches the servo pulse width value...must try.
    it's down to cost,extra circuitry or micro controller. Any ideas? mega2560 already recommended.

     
  • stan cartwright

    stan cartwright - 2018-06-06

    Anobium, Is it ok if I send you a PCA9685 board to "enjoy"?

     
    • Anobium

      Anobium - 2018-06-06

      OK. Send thru.

       
  • kent_twt4

    kent_twt4 - 2018-06-06

    Tossed in the towel on the PCA9685? Should have been a capable performer, oh well.

    The 2560 mega board has an enormous amount of resources. DO NOT toss in towel on the 2560! it is a proven platform with GCB.

    There are four 16bit timer/counters, 1, 3, 4, and 5. Each 16bit timer has 3 channels, A, B, and C. So there are 12 independent PWM's right there.

    We have gone over how to get 50Hz PWM in the demonstration code for one channel using TC1.
    https://sourceforge.net/p/gcbasic/discussion/projects%26guides/thread/66153766/#ae47
    Apply that knowledge to set up the B and C channels. Then, move on to the other timers 3, 4, and 5.

    I will be back to my stuff next week if we need to go over it again. I do not have 12 or more servos, but can test a couple three?

     
  • Anobium

    Anobium - 2018-06-16

    @Stan.

    A library that works. The libraries on the web made lots and lots of assumptions, and to be frank do not work unless the conditions were 100% perfect. I am sure that this library make one assumption... I know it does.

    https://github.com/Anobium/Great-Cow-BASIC-Library-Development/tree/master/PCA9685

    This library supports the following pubic methods.

    '    PCA9685_SetFreqency ( frequency_wordvalue ) a value from 24 to 1526
    '    PCA9685_SetChannelDuty(  channel as byte , duty as word )  where duty is 0 to 100%
    '    PCA9685_SetChannelOnOnly ( channel as byte , OnValue as word ) where Onvalue is 0 to 4095
    '    PCA9685_SetChannelOffOnly ( channel as byte , OffValue as word ) where Offvalue is 0 to 4095
    '    PCA9685_WriteChannel( channel as byte, OnValue as word, OffValue  as word ) ranges of 0 to 4095
    

    @Stan. Based upon using the public methods shown above the following methods needs to be completed as I dont have the servo's to hand.

    '      PCA9685_EnableServoMode
    '      PCA9685_SetServoAnglePulseLimits
    '      PCA9685_GetServoAnglePulseLimits
    '      PCA9685_SetServoAngleLimits
    '      PCA9685_GetServoAngleLimits
    '      PCA9685_SetChannelAngle
    

    There are a LOT of constants but these are the key constants to use.

    ~~~
    PCA9685_ADDRESS
    PWM_DUTY
    PCA9685_ALL_CHANNELS
    PCA9685_LED0, PCA9685_LED1 etc to PCA9685_LED15
    PCA9685_LED_ON
    PCA9685_LED_OFF

    Download and test the basics, then, the update to add the Servo methods and then we can change into a libray. DO NOT MUCK WITH THE CONSTANTS OR THE OVERALL LAYOUT OF THE METHODS. I WANT TO MAKE THIS A LIBRARY.

    https://github.com/Anobium/Great-Cow-BASIC-Library-Development/tree/master/PCA9685

     
  • stan cartwright

    stan cartwright - 2018-06-16

    Well done. I'll have a device to try tues/wed.
    I have SG90 9g servos. Don't think 0.75ms to 2.25ms pulses is 0 to 180 degrees...more 10 to 170.
    I think servos vary.

     

Log in to post a comment.