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: 9
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 190 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 614
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 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: 9
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: 9
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: 9
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 13052 times
IMG_1563.jpg
IMG_1563.jpg (120.02 KiB) Viewed 13052 times

User avatar
LeighM
Matrix Staff
Posts: 2178
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: 9
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: 614
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 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: 614
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 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: 9
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: 614
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 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

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

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

I have downloaded all the new updates, but the motor still runs at maximum speed regardless of the position of the potentiometer. What could the problem be?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 614
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: PWM Control for elektrical motor with potentiometer.

Post by chipfryer27 »

Hi

Whilst I don't have your board, I do have some L293D's kicking around and I should have an Arduino somewhere too. Later in the week, or possibly weekend I'll try and replicate. If you have a scope perhaps you could share the trace on the output pin at 25% / 50% / 100% duty? If this is correct then the problem is not your code or Arduino, but elsewhere in hardware. That would be my next move.

I also read in another "Arduino" related forum that someone had issues with your board in that at certain frequencies they only got a narrow band of control. Can't remember exactly though.

Regards

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

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

As a test I wrote a program that allows me to write the value of the potentiometer on the LCD. In the simulation of FC itself this works perfectly, but when I download this to my Brainbox AVR. The output remains high (255)independent of the position of the potentiometer.
Attachments
Potmeter LCD.fcfx
(10.06 KiB) Downloaded 113 times
Potmeter en LCD.jpg
Potmeter en LCD.jpg (116.75 KiB) Viewed 12389 times
IMG_1644.jpg
IMG_1644.jpg (127.84 KiB) Viewed 12389 times

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 Control for elektrical motor with potentiometer.

Post by medelec35 »

Hi DBMGTIL.
Two things to try.
Within Pot properties, Change Vref option to AVCC
See if that works first.
If that does not work what happens when you set PWM with a value of 127?
Martin

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

Re: PWM Control for elektrical motor with potentiometer.

Post by DBMGTIL »

Finally it works! Thanks for your good advice,If I have any problem in the future I know where to find you.

Post Reply