|
|
View previous topic :: View next topic |
Author |
Message |
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
PWM duty is 255 100% or 1024 or ? |
Posted: Wed Nov 24, 2010 9:15 pm |
|
|
I've been reading up on this, I've read the data sheet and understand how setting the bits actually sets the duty cycle.
What I don't get is the 8 bit or 10 bit part. Do we set it as 8 bit or 10 bit ? I know depending on the frequency of the pwm the resolution is reduced with greater frequency.
Basically I want to be able to set my duty cycle but I'm not sure what the set_pwm1_duty function does. This is the code I'm using, I'm using pwm steering.
Code: |
setup_timer_2(T2_DIV_BY_16, PERIOD, 1); // Set 1000 Hz PWM freq
//set_pwm1_duty((int)(PERIOD*(speed*.25))); // Set PWM for 25% duty cycle
// Set up PWM so that all four outputs are active high.
setup_ccp1(CCP_PWM_H_H);
|
So, what should I set it for to have a duty cycle of 100%, 50% ? I'm using a 4Mhz internal clock on my 16f887.
Thanks for your time. _________________ Smart people know how stupid they are. |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Wed Nov 24, 2010 10:49 pm |
|
|
Ok I've been reading up on this quite a bit. I have looked into timer2 also. I'm still not sure where the PR2 value comes from, unless its the second argument in the setup_timer function.
Anyway this is my thinking is this right ? ? If it is then my frequency is really low and might be causing the problems I'm running into. For instance at duty of 255 I'm only getting 3.8v output on the pin, with a duty cycle of 100% I should get 5v.
Code: |
// 16f887 with 4MHz internal Clock
// setup timer 2 period = 1/(4MHz/4/16/Period) . . . 1/(245) = 4.08mS
// my frequency is 245 Hz
// Period register = PERIOD (what is this var ? assuming 255)
setup_timer_2(T2_DIV_BY_16, PERIOD, 1);
// set so we are using active high
setup_ccp1(CCP_PWM_H_H);
// set all outputs low
output_low(P1A);
output_low(P1B);
output_low(P1C);
output_low(P1D);
// set 100% duty cycle
set_pwm1_duty(PERIOD*4+1);
// set pulse steering on pins b and c
set_pulse_steering( CCP_PULSE_STEERING_B | CCP_PULSE_STEERING_C);
|
If my thinking is right please let me know. If so I think I need to turn up the frequency of timer 2 to about 15kHz.
I found this info Quote: | " It is important to experiment with these parameters to find the configuration that is right for your application because no two motors are the same. Some motors are better when the frequency is low (between 2 000-5 000 Hz). Other motors are best when the frequency is high, say between 15 000 and 20 000 Hz. Note that a low frequency (between 1 000 and 8 000 Hz) will produce an audible sound that can be very annoying. I have tested three robots with varying weight (500 g to 15 kg) and with different motors and have found that a frequency of 15 000 to 20 000 Hz gives good results. I have never seen any robot move with a duty cycle of less than 50%. If you want to do this, you have to find ways to control PWM in software, i.e. for a duty cycle of 25%, use a 50% duty cycle and turn PWM 50% of the time. Ideally, you will find motors that are not too fast at 50% and fast enough at 100%. " - http://mdubuc.freeshell.org/Robotics/Tips.html |
I'll test it tomorrow and see if that helps, ... oh no tomorrow is thanksgiving I might be busy ! _________________ Smart people know how stupid they are. |
|
|
|
|
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
|