|
|
View previous topic :: View next topic |
Author |
Message |
webgiorgio
Joined: 02 Oct 2009 Posts: 123 Location: Denmark
|
setup_power_pwm(PWM_UP_DOWN) ?? |
Posted: Wed Nov 30, 2011 11:31 am |
|
|
Code: | setup_power_pwm(PWM_UP_DOWN)
| what does it means?
I use PWM_FREERUN but maybe is not convenient.
I have to control a 6-pulse 3-phase converter. When the voltage (reference sinewave 0-5V, 2,5V offset) read by the AD converter is zero the dutycycle must be 50%, 5V=100%, 0V=0%.
- I read the AD
- I multiply by some constant and the value GAIN (to change the max/min modulation) and addition-subtraction to obtain 50% duty-cycle when the adc voltage is 2,5V.
- I SET_PWM_DUTY(dc_value)
The problem is that the multiplication in int16 waste a lot of time (not constant!) and I have problems in synchronize the converter to the synchronous generator.
When the frequency is >20Hz I change the ADC to reading a look-up table with the values of the sinewave (int8).
I do every ms an interrupt to calculate the dc_value and update the SET_PWM_DUTY.
Maybe there is a better way..... that works! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Dec 01, 2011 4:36 am |
|
|
You'd probably have got a reply much quicker, if you said 'what chip'. As currently phrased your question is a bit like "what does this button on my dashboard do"?. Not easy to answer, unless you say the car involved.....
However the 'PWM_UP_DOWN' behaviour generally only applies to power PWM modules, and motor power PWM modules, and is pretty generic. The data sheet should really be the source you look at for this. The difference is simple. On the standard PWM operation, the clock counts up, to the defined count, and then resets, and counts up again. On the 'up/down' mode the PWM counts up, then counts down, then up again etc.. Basically half the working frequency.
Look at the data sheet for your chip. Sections on free-running mode, and continuous up/down mode.
Now, there is something slightly worrying about your comments on the int16 multiply taking variable time. I don't think the power_pwm module is available on any of the PIC16 chips, and on PIC18 and better chips, the int16 multiply uses the hardware 8*8 multiply in the chip, giving constant timings.
I'd suspect your problem is actually a beat between the event rates. The PWM, only updates it's frequency at the end of it's cycle. If you are interrupting 'every mSec', and this rate is not exactly synchronous to the PWM, you will get a beating effect in the updates. Several things:
1) Don't interrupt. Instead _poll_ the interrupt flag you are using. This is significantly faster. Start calculating the next value as soon as you have loaded the last one, and then poll for the flag to change, and load this.
2) Use an interrupt that is synchronous to your update rate. If (for instance), you are using the PWM running at 20KHz, then program timer2, to generate an interrupt at exactly every 20 cycles of the PWM frequency. Use _it's_ interrupt flag to synchronise your loop. Then the update won't 'beat' with the PWM.
Best Wishes |
|
|
|
|
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
|