PWM, can I control more than 2PWMs?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

PWM, can I control more than 2PWMs?

Post by kirstom14 »

Hi,
I am using Flowcode v3, and I need to interface a dc motor and a dc servo motor using a PWM H-bridge for each.
Thus this requires 4 PWM pins, but Flowcode only have 2!

What can I do, as I need to control both motors at the same time?

Thanks
tomcat14

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM, can I control more than 2PWMs?

Post by medelec35 »

You need to set the other two channels up manually using C code. I don't believe bit bang method is the way to go if you have more than two dedicate PWM o/p's.
If you have not got more than two then bit bang would then be the way to go.

If you are using H-bridge, and have spare o/p's, then can't you use just two PWM channels (one for each motor).
You can just use a transistor to invert pwm o/p in your driver stage, since drivers are required. So if done correctly, you will not require additional hardware.
I have not achieved this on real hardware. Its only a theory.

I believe it would be a good idea for a tutorial on creating more than 2 pwm channels using pwms of controllers (not bit bang method, that's already been covered) in the articles section...hint Steve :P
Martin

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Re: PWM, can I control more than 2PWMs?

Post by kirstom14 »

Hi,

Well I came out with a circuit that controls the speed and direction of the motor using only 1 PWM for each motor, with the aid of some simple logic.
The problem that I am encountering is that, I am controlling the direction of the motor, but when I vary the ADC (using a pot), the PWM must change
accordingly. But nothing is happening. I tried to supply the PWM with the use of a signal generator (gave a maximum frequency of 5kHz) and the hardware worked fine.

What can I do to control the speed of the motor with the PIC?

I am using the ECIO-40.
tomcat14

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM, can I control more than 2PWMs?

Post by medelec35 »

Hello kirstom14.
First you need to set up the target frequency e.g 19.6 MHz, then pwm frequency e.g 5KHz, which will stay fixed.
PWM Frequency is adjusted by clicking onto down arrow, then properties of pwm component. For 5KHz, setting clock source to clk/4 and period register to 245, with give a pwm at 4.995KHz
You will need to enable PWM's. ndlx(BYTE) 1 = channel 1 and 2 = channel 2.
Then if you read ADC and assign with a value, this value will then be used to control PWM 1
and/or PWM 2 by using SetDutyCycle or SetDutyCycle 10bit.
Eg ndlx(BYTE),nDuty(BYTE) = 1,50
This will set PWM Channel 1 to run at a duty of 20%
Note: nDuty(BYTE) is not directly %. so 50 is not 50%
If you are still stuck and you don't mind sharing, post what you have done, and state the PWM frequency, and duty required for pot min and pot max then I will get it working for you.
Also take a look at:
http://www.matrixmultimedia.com/mmforum ... =26&t=7319
Martin

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Re: PWM, can I control more than 2PWMs?

Post by kirstom14 »

Hi medelec35,

I have adjusted the settings like you told me. I have set the ECIO PWM freq to 3kHz. But the problem is that on the simulation
the PWM is varying, but when I dump the program and send it to the ECIO, there is a square wave on the scope. But when I am
varying the pot, there is only a slight difference. The mark of the wave is very small when compared to the space of the waveform.
This is the same when the pot is fully closed and fully open, the difference is very small.

I cannot understand why this is happening!!

Thanks again for your help.
Attachments
h-bridge_2.gif
cct schematic
(89.41 KiB) Downloaded 2425 times
h-bridge 2.fcf
(8.5 KiB) Downloaded 404 times
Last edited by kirstom14 on Fri May 21, 2010 5:07 pm, edited 1 time in total.
tomcat14

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM, can I control more than 2PWMs?

Post by medelec35 »

Hello kirstom14.
Unfortunately not got hardware to test your software.
Settings and software looks OK. You could try using PWM 2 instead of PWM1. There could be a bug for PWM 1, but don't know that for sure. Perhaps someone at Matrix could be kind and look into whats going on? You could try and manually enable PWM See http://www.matrixmultimedia.com/mmforum ... =26&t=7319
If you get stuck with manually enabling with C code, I will see if i can assist you further.
Martin

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: PWM, can I control more than 2PWMs?

Post by Dan81 »

Hello kirstom

2 remarks :

- RA0 : is an input and there are 2 objets : a LED and a potentiometer.
I think the voltage is drawn near 0 by LED (and the led is biased through the Potentiometre).
Can you measure the voltage of RA0 when you move the potentiometer (or try to remove the Led)

- RA1 : there are also 2 parts: a led and a switch .
Try to connect the switch and the potentiometer to some others pins.

I've modifed your flowchart but I can't test it (I haven't got an ECIO).
(duty cycle is automatically modifed every second, see simulation)


Daniel

PS : may be you can post a schematic of your harware.
Attachments
h-bridge_v2.fcf
not tested
(7.5 KiB) Downloaded 433 times

Post Reply