Menu

328p pwm

Help
2018-05-18
2018-05-19
  • stan cartwright

    stan cartwright - 2018-05-18

    I'm googleing mega328p pwm to control a hobby servo.
    I can set up 1 pin to control 1 servo-50Hz, change pulse width.
    Save me time looking, is it possible to pwm 4 pins at same frequency but different pulse width?
    ie control 4 servos.
    At the moment I use a 50hz interupt and pulse out servo value.
    I guess pulseout stops the program for the pulse and four 2.25 ms pulses every 20ms means rest of program runs at half speed.
    I saw a robot https://www.amazon.com/dp/B06ZZH8LZS that uses 4 servos . It uses a 10 channel pwm, i2c board. It's £30 from maker with discount code. https://www.sunfounder.com/diy-4-dof-robot-kit.html
    There's plans so I could my own..I know someone with a cnc laser. Wouldn't save much money and adapting code to gcb.

     
  • kent_twt4

    kent_twt4 - 2018-05-18

    Google GCB forum, and maybe you would have found this? https://sourceforge.net/p/gcbasic/discussion/projects%26guides/thread/66153766/#ae47

    Need more channels? then get a Mega Board and have a whole potful of timers to play with.

     
    • stan cartwright

      stan cartwright - 2018-05-18

      Thanks. I can do 1 channel even though I got to think. I downloaded avrcalc to help.
      I wondered about pics..PIC16f1572 and probably easier with gcb than avr.
      I could buy a 10 channel pwm chip with i2c for a few pound..mega board bit ott for robot but thinking of getting one anyway.
      Servos need a pulse every 20 ms or so.
      How about setting 50Hz pwm for pin A at 1ms mark.
      Use 200Hz interrupt.
      Use a counter 1 to 4, if 4 reset to 1.
      1st interrupt switch the pwm to pin B at different mark.
      next interrupt switch pwm to pin C.
      next nterrupt switch pwm to pin D
      then reset back to pin A.
      so each servo gets refreshed 50Hz and changing pwm faster than pulse out..
      or am I missing something?

       
      • kent_twt4

        kent_twt4 - 2018-05-18

        No reason why that wouldn't work, depends on what you are doing. If this is for bot motor control then I would tend to set the 50Hz interrupt then update all channels at once. Over time you could find the bot bot pulling to one side in a straight line?

         
  • stan cartwright

    stan cartwright - 2018-05-18

    timer1 can't be 4 pins.
    new pics with clc..??

     
  • kent_twt4

    kent_twt4 - 2018-05-18

    I have used the NXP PCAxxxx for driving leds before. They can work good, it still takes some work to set them up though, just like anything else.

     
    • stan cartwright

      stan cartwright - 2018-05-18

      Setting up a new device is interesting.
      Someone else said on this forum "arduino includes hide everything, it's cut and paste"
      Do I want to use a device or know everything about it?
      Do I have to be a mechanic to drive a car?
      What's the B in Basic stand for ?

       
      • kent_twt4

        kent_twt4 - 2018-05-19

        Understood, I am 1600 mi. from my gear for the next few weeks anyways. So no help on a library for now.

        I probably have the old PCAxxxx code sample, so I could look at that if you need help there when the time comes.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.