PWM Control for elektrical motor with potentiometer.

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

I want to control the speed of the motor with a potentiometer, but the motor always runs at maximum speed, regardless of the position of the slider in the potentiometer. Attached you will find the program I wrote. Can you help me?
Attachments
PWM DC MOTOR VIA POT.fcfx
Program PWM control with potmeter
(9.78 KiB) Downloaded 18 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 298
Joined: Fri Jun 06, 2014 3:53 pm
Location: Jockland
Has thanked: 156 times
Been thanked: 132 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by chipfryer27 »

Hi

I'm not that familiar with the chip you are using however it appears to be simulating OK.

Do you have access to a scope to check what's actually happening on the pin? How are you interfacing the uC to the motor?

Sorry I can't offer further insight.

Regards

User avatar
Benj
Matrix Staff
Posts: 15257
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4774 times
Been thanked: 4300 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by Benj »

Hello,

Your loop is maybe too tight and hence you are almost constantly writing to the PWM registers, maybe try adding a delay inside the loop to give the PWM chance to run.

User avatar
Benj
Matrix Staff
Posts: 15257
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4774 times
Been thanked: 4300 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by Benj »

Hello,

Looking again the PWM component properties there is no value selected for the Timer, maybe ths could be causing a problem?

Let us know how you get on. If you're still having problems then I'll see if I can replicate here on an Arduino Leonardo.

DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

chipfryer27 wrote:
Wed Sep 29, 2021 7:55 pm
Hi

I'm not that familiar with the chip you are using however it appears to be simulating OK.

Do you have access to a scope to check what's actually happening on the pin? How are you interfacing the uC to the motor?

Sorry I can't offer further insight.

Regards
I've hooked up my potentiometer to a scope and the input goes high and low when I turn the cursor. So this one works.

DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

Benj wrote:
Fri Oct 01, 2021 4:20 pm
Hello,

Your loop is maybe too tight and hence you are almost constantly writing to the PWM registers, maybe try adding a delay inside the loop to give the PWM chance to run.

I added a delay and this doesn't solve the problem either.

DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

I have set the timer setting to timer1, but this also does not solve the problem.
Attachments
Timer1 for PWM.png
Timer1 for PWM.png (283.71 KiB) Viewed 428 times
IMG_1563.jpg
IMG_1563.jpg (120.02 KiB) Viewed 428 times

User avatar
LeighM
Matrix Staff
Posts: 2177
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by LeighM »

Try removing the 0 -> B6
If that does not fix the issue, please could you provide more info on the hardware that you are using?

DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

This also makes no difference. I use the Brainbox AVR from Bart Huyskens. He is aware of the problem and I have asked him to list the most important things you need from the hardware in function of this problem. Just wait for his answer.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 298
Joined: Fri Jun 06, 2014 3:53 pm
Location: Jockland
Has thanked: 156 times
Been thanked: 132 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by chipfryer27 »

Hi

If you are getting pulses at the correct pin then I'm guessing your code is fine and it is something else in the Hardware.

The Brainbox board you are using looks quite interesting and is certainly full of features, although I have no experience with it myself. Have you checked for any "Doh..!" moments? By that I mean have you double checked all connections / jumper settings etc?

The picture isn't too clear so I can't really see what your jumpers are. Have you verified that Jumper 2 is correct? This is the setting for the H-Bridge / PWM power.

Have you tried the free Flowcode PWM example from the Brainbox site?

Regards

Edit...

Just reread first post so as the motor runs I'm guessing J2 is correct. I think however you might be trying to run the L293D at too high a frequency. From memory I think they prefer much lower values. Does setting the prescaler to 8 or 64 make any difference?

Further edit....
From a few other forums it seems the board likes around 5KHz max. You are running at 62.5KHz. As above, try a prescaler value of 8 or 64 and let us know how you get on.

colinli
Posts: 4
Joined: Wed May 12, 2021 2:03 am
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by colinli »

I have a similar problem, I was planning to use a serial screen together and a microcontroller to control the brightness of the LED or the wind speed of the fan.
I heard that the PWM method is used, but I'm not quite sure how to control the PWM.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 298
Joined: Fri Jun 06, 2014 3:53 pm
Location: Jockland
Has thanked: 156 times
Been thanked: 132 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by chipfryer27 »

Hi

That looks like an interesting screen. Might explore that myself.

The wiki has good examples of using PWM including an LED example.

https://www.flowcode.co.uk/wiki/index.p ... :_General)

Regards

DBMGTIL
Posts: 6
Joined: Wed Sep 29, 2021 1:00 pm
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

I've checked all connections several times. The jumpers are also set correctly. My engine runs effectively but always at maximum speed. I have also adjusted the prescaler to 8 and 64, but that does not solve the problem.

I contacted the manufacturer of the hardware and he says it is due to an update in Flowcode itself. He tested my program in FC7 and there it works, He tested also in FC8 and then it doesn't work. I'm currently working with FC9 and it doesn't work there either. So I should be able to update my chippack from arduino in FC9. How I do that?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 298
Joined: Fri Jun 06, 2014 3:53 pm
Location: Jockland
Has thanked: 156 times
Been thanked: 132 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by chipfryer27 »

Hi

When FC starts it should look for updates automatically. However to do so yourself, open your project in FCv9, then on the top ribbon bar you will see a Library Update icon. Click this and it will automatically look for updates to the components in use. Once this completes click the Full Database option. Ignore warnings of "This may take some time", it doesn't really. This will update the complete FC library. Once done restart FC.

Hope this helps.

Regards

Post Reply