Programming PWM

Hi, I need to program a PWM but I have no idea how.

Does anyone have a program for PWM or just a good article on how I can make my.

 

I have a project where I need a total of 6 PMW's but the largest amount of hardware PWM pins I can find on a chip is 4.

 

I use Flowcode or C

What hardware are you
What hardware are you using?

If there aren’t any hardware PWM channels, you may be able to bit-bang additional channels.

Just use an ATmega328 board

Just use an ATmega328 board compatible with Arduino, lots of examples right in the IDE :slight_smile:

I believe that he’s using a
I believe that he’s using a PIC. I think it’s for a class, which means that he doesn’t have full control of what he’s using. This is a guess from previous posts.

As for software, it’s in the last line of his post: Flowcode or C.

He could always use 2 PIC’s, one to handle the right half, one to hand,e the left half. Though if he’s trying to control a six wheel bot like the Wild Thumper, then he really only needs two PWMS sources. Again, I have no idea what his real goal is.

Just on a side note, I’ve

Just on a side note, I’ve been reading up on the Arduino PWM because I am using a Mega2560 to control 12 DC motors. The mega 2560 has 17 PWM outputs. I need 24 PWM outputs to control the 12 DC motors ( for biderectional control). The arduino has a 2 millisecond duty cycle on it’s PWM( it can vary between 0 and 2 milliseconds HIGH in one cycle) , which to me seems quite long since the output pins can be written to (if using micros() ) for a period as small as 40 microseconds. This suggests that you can use the micros() timer to write to any of the digital pins with a higher resolution and much smaller duty cycle just using some clever code. I’m currently trying to write some code that will create a pseudo PWM by creating an array assigned ‘grid’ for my 12 DOF which will use micros() timings to turn the pins individually on and off according to the individual DOF PID error. If I can do this, it shows that in fact that using PWM is not necessarily better than actually jsut writing to the output pins for desired lengths of time with your code. My code would allow the loop to run unhindered by any delay() or delayMicroseconds() commands if it succesful and if I manage to write it.

No motor controller that
No motor controller that I’ve ever used required two channels of PWM for each motor.

It usually requires one channel of PWM and one or two pins to tell the controller about braking and direction.