|
|
View previous topic :: View next topic |
Author |
Message |
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
basics of pwm in pic18 |
Posted: Mon Jan 23, 2012 3:25 am |
|
|
hi..
i am working on a project where i need to work with pwm for speed control of 9v dc motor.
i am using PIC18F4431.
i would like to know how to work with PWM in this.
what are all can be done.?? how??
i gone through the example file ex.pwm.c but i can't get the essence.
plz help me...
main issue:
is it possible to have capture interrupt and PWM interrupt at the same time?????
i already use capture interrupt. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Jan 23, 2012 4:07 am |
|
|
Generally it is rare to use interrupts with PWM. There isn't a 'PWM interrupt' as such.
The PWM hardware does one job. It allows you to setup a frequency for a clock, and then at will change the pulse width being generated at that frequency. The change normally only occurs at the start of the next pulse (the hardware does this automatically).
The only interrupt normally associated with the PWM, is the interrupt from the clock used to generate it (normally timer2). With this every so many pulses of the clock, you can generate an interrupt, and this can be used if you want your code to change things 'synchronously' to the PWM. You'd never normally generate an interrupt at the full PWM frequency, because this is just 'too fast'.
You might for example though have a PWM at 20KHz, and then set the timer to generate an interrupt every ten pulses of the PWM. Then your 'update loop' code which may take varying times according to the maths involved, when it has a new value calculated, sits and waits for this interrupt to trigger, before actually changing the pulse width (often not actually calling an interrupt handler, but just waiting for the interrupt flag to set), giving a fixed 'update' rate at 2000*/second. Having a fixed update rate, can improve the control loop code.
Do a search here, and on the web, on 'PID'. Variants of this would be the normal approach for controlling a motor, with some form of speed sensing being used, and the PWM pulse width then being adjusted to give the required speed.
Best Wishes |
|
|
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
|
Posted: Mon Jan 23, 2012 5:09 am |
|
|
sir.... ttelmah....
i've said wrongly as PWM interrupt....
ok fine...
correct me if my logic is wrong.....
when the current exceeds some marginal value in one direction i need to run motor in opposite direction. so i planned to use this.
i'll monitor the current using external OPAMP circuitry.
the analog value of current sensor will be coming to PIC continuously.
when it exceeds the PWM will have to give out pulses
when the pulses are given to the H-Bridge the average voltage applied to the motor can be controlled. so speed will be controlled in reverse direction
will this work???????
1.in PIC18F4431 in what terminals the PWM pulses will come.?????
2. whether it'll come in one pin or many at the same time..??????. bcoz i could see many pins in the name PWM (from 0-7) |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
PID and loop control |
Posted: Wed Jan 25, 2012 5:20 pm |
|
|
You've got at least two problems.
1) Understanding your PIC.
2) Understanding control loops.
1) I don't have your PIC, so can't help you on that one.
2) You don't control motor speed by monitoring current alone. You need to stand back from the problem and work out the basics, BEFORE you start to worry about issue 1 and software. For example, if when current exceeds a limit value you immediately reverse the motor drive, the current can become ENORMOUS!!!!!
I suggest you get a handle on motor control in the analogue domain first, then try digital methods. In other words, work out some pseudo code.
If you really must start with a PIC, then get things going open loop, see how the system behaves and proceed from there.
Mike |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|