|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||||
|
||||||
|
Re: Are we still using only 256 unique PWM steps?
Quote:
What you need is an output converter function (or sub-vi) that takes your desired 12-bit value and modulates the 8-bit PWM value. The modulation of the 8-bit PWM signal will increase your resolution. Here's an example of how to do it (get 12 bits from an 8-bit PWM): 1) Multiply the PWM output command (0.0 - 1.0 for your shooter motor that you should only command in one direction) by 127. You should end up with a PWM command with a whole part and a decimal part. 2) Take the decimal part and multiply by 16 and round to the nearest whole number. Call this number FractionalDuty. (Why 16? Because 12 bits has 16 time more resolution than 8 bits.) 3) Take the whole part of the number from step 1 and call it WholePWM. 3) In your fast loop, implement the following code: Code:
if (counter < FractionalDuty) PWMOut = WholePWM + 1; else PWMOut = WholePWM; counter++; if (counter >= 16) counter = 0; What this does is it adds a one-count duty cycle on top of the PWM signal. It does it by increasing the 8-bit PWM by one count for a portion of every 16 timer loops. For example, if your FractionalDuty is 4, then it will increase the PWM output by one count for 4 out of the 16 loops. This averages your PWM output to be an additional 1/4 count. This will increase the resolution of your output, providing that your system time constant is much larger than the frequency of your added one-count duty cycle. If you implement the above code in a 10 ms loop, you are modulating the PWM signal over a period of 160 ms. Most shooters this year spun up in about 2 seconds, giving them a time constant of about 500 ms. That makes the ratio of time constant to control cycle about 3/1, which isn't great, but it's not too bad. You might see your shooter speed oscillate by 5 RPM or so. Note that the above code is to get the 12-bits that you want. If you go to 11-bits, you only need eight 10 ms loops to modulate your PWM. That gives your control cycle to time constant ratio of about 6:1, which is getting pretty good. Disclaimer: I'm typing this while I'm being distracted by something, so my math might be off a bit. Last edited by Chris Hibner : 07-08-2012 at 23:27. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|