PWM Control for elektrical motor with potentiometer.
PWM Control for elektrical motor with potentiometer.
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 225 times
-
- Valued Contributor
- Posts: 773
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: PWM Control for elektrical motor with potentiometer.
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'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
- 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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: PWM Control for elektrical motor with potentiometer.
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.chipfryer27 wrote: ↑Wed Sep 29, 2021 7:55 pmHi
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
Re: PWM Control for elektrical motor with potentiometer.
I added a delay and this doesn't solve the problem either.
Re: PWM Control for elektrical motor with potentiometer.
I have set the timer setting to timer1, but this also does not solve the problem.
- Attachments
-
- Timer1 for PWM.png (283.71 KiB) Viewed 19068 times
-
- IMG_1563.jpg (120.02 KiB) Viewed 19068 times
- 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.
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?
If that does not fix the issue, please could you provide more info on the hardware that you are using?
Re: PWM Control for elektrical motor with potentiometer.
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.
-
- Valued Contributor
- Posts: 773
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: PWM Control for elektrical motor with potentiometer.
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.
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.
Re: PWM Control for elektrical motor with potentiometer.
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.
I heard that the PWM method is used, but I'm not quite sure how to control the PWM.
-
- Valued Contributor
- Posts: 773
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: PWM Control for elektrical motor with potentiometer.
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
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
Re: PWM Control for elektrical motor with potentiometer.
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?
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?
-
- Valued Contributor
- Posts: 773
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: PWM Control for elektrical motor with potentiometer.
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
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
Re: PWM Control for elektrical motor with potentiometer.
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?
-
- Valued Contributor
- Posts: 773
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: PWM Control for elektrical motor with potentiometer.
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
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
Re: PWM Control for elektrical motor with potentiometer.
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 163 times
-
- Potmeter en LCD.jpg (116.75 KiB) Viewed 18405 times
-
- IMG_1644.jpg (127.84 KiB) Viewed 18405 times
-
- Matrix Staff
- Posts: 9521
- 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.
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?
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
Re: PWM Control for elektrical motor with potentiometer.
Finally it works! Thanks for your good advice,If I have any problem in the future I know where to find you.