Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM with PIC18F4580

Status
Not open for further replies.

twins

New Member
Hello there. I am currently working on speed control for a DC motor using PWM for my project but have some problems which I'm not clear about. I've attached my codes here. A brief overview of how my code runs is that it checks the voltage to run the respective PWM.

My problem now is that when controlling the motor, I want it to run when at speed 1 but it doesn't even though I've already make it run at 100% for 0.6s so that it can get enough power to run at 30% duty cycle. It works as desired in the beginning but then doesn't after I've decreased voltage to zero and then increase my voltage again. Any ideas on solving this?
 

Attachments

  • ADC.asm
    2.4 KB · Views: 221
F=ma, it is a simple truth we cannot escape. Increase the gear ratio, or lighten the load, for more duty cycle range. Having to kick the motor in the pants to get things moving (robot?) is an indication of this problem.
 
May I know how can I increase the gear ratio? The motor I'm currently using is a hand-drill motor before going to the large dc motor.
 
At least we know what you are trying to drive now:).

Could be that the 10kHz PWM period is on the high side for the drill motor, i.e. not enough "ON" time. I would try increasing TMR2 prescale to 16 and see if that helps? And if it does, continue on with increasing PR2.
 
Will give a try when I do my next testing in the lab. Btw, I was wondering which would be better to work with for a dc motor, a high frequency or a low frequency duty cycle? The crystal I'm using is 20 MHz so lowest frequency I can go is 1.2 kHz and highest would be 19.5 kHz.
 
Will give a try when I do my next testing in the lab. Btw, I was wondering which would be better to work with for a dc motor, a high frequency or a low frequency duty cycle? The crystal I'm using is 20 MHz so lowest frequency I can go is 1.2 kHz and highest would be 19.5 kHz.
Don't have a ready made answer for the frequency question. I'm sure the motor will tell you audibly what frequencies to stay away.

Another observation; The CCPx special event mode is basically a single shot PWM. There are enough code instructions, and waiting for the a-d conversion, to make up a significant proportion of the duty-cycle (10+ µs) at Speed1. Using the standard mode PWM would negate that, at the expense of skipping a cycle till the next duty cycle is implemented. Not clear if the 18f4580 can do an auto a-d conversion in the special event mode or not.
 
Looks like an a-d conversion can take place with the special event trigger if the ECCP1CON register is used. Not sure why the special event trigger would otherwise be used in this instance, unless something else needs to be done with the interrupt flag. I think I got confused here, everything with CCP1CON should be running in the background. Best of luck.
 
I tried decreasing the frequency and still nothing changed. The motor only runs when I'm at speed2, speed3 and speed4. At speed0, it does stop but only having a problem with speed1. Speed1 is only functioning when I move from speed2 to speed1. I was thinking giving it a boost for 0.6 s could have helped it move in case it didn't have enough momentum to run but to no avail.

Anyways, from the result of my testing on a scooter dc motor(24V), the result I got instead was that in speed1 it did not run at all, speed2 it was barely running and speed3 and speed4 was working fine. Discussed it with my lecturer and it was decided to change the duty cycle range to 70% to 100% in steps of 10%. Though I haven't seen the result of the change as I ran out of time but will keep you posted.

About the ECCP1CON, I've looked into it before but have no idea how to do the programming for it and the control needed to connect it to a H bridge. Looked for the asm codes for it but mostly had them in C format. Sadly, I only know how to program in assembly language since I just started learning this 2 months ago.
 
Status
Not open for further replies.

Latest threads

Back
Top