CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM on 18f1230/1330

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PICnMIX
Guest







PWM on 18f1230/1330
PostPosted: Sun Mar 15, 2009 5:35 am     Reply with quote

Hi

I am trying to use 18f1x30 to produce 3 PWM sinusoidal signals to control the speed of a motor.

I have selected the 8Mhz internal oscillator and centre aligned PWM with 250us period. I need to initiate a PWM interrupt every period to update the duty cycle registers.

Can anyone tell me how this is achieved? At present the MPLAB simulator indicates that PTMR registers are counting down only with no setting of the PTIE bit when it counts through 0.

Incidentally, can anyone explain the significance of setting the initial value of the timebase in setup_power_pwm(). I have seen examples which set this to 0 but the C Compiler manual gives an example of 10000.

Thanks very much.
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 9:45 am     Reply with quote

Presumably you want the 3 pwms 90° out of phase, and I dont think that can be done.
Ttelmah
Guest







PostPosted: Sun Mar 15, 2009 4:03 pm     Reply with quote

You'd normally want 120 degree phases, not 90 degree....

Yes, the power control PWM, can do this, the topology needed, will depend on the wiring of your phases. Simplest using H bridge drive, with a star layout. Obviously not a a true sine wave (PWM _simulating_ the effect of a sine wave). You will have problems with some parts of the code, the interrupt update rate in particular is easier handled in assembler, or requires very careful coding (see my notes in the past about using the 'fast' interrupt option, and writing a handler for this). A lot will depend on just what frequencies you want to generate?.
What is your interrupt postscaler set to?.
Post the setup you are using for the PWM, and your compiler version. Not all versions setup the register 'right', and when the interrupt occurs, depends on how you have the PWM setup...

The initial timebase value, is just what it says. The value fed into the PTMR register(s) on setup.

Your arithmetic is going to get complex, if you are synthesising the three phases, and adjusting frequency as well. You might want to consider a lookup table for the synthesis, and then perform an integer scaling of the values.

Best Wishes
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Mon Mar 16, 2009 12:05 am     Reply with quote

Ttelmah wrote:
You'd normally want 120 degree phases, not 90 degree....


Yeah thats what I meant Smile
Guest








PostPosted: Mon Mar 16, 2009 3:45 pm     Reply with quote

Thanks for replying guys

This is a split single phase motor and I am using it star connected. My phase shifts are 0, 180, 288 degrees. Provided the amplitude of all three sine waves are equal then the 180 degree phase shift between main in and auxilliary in will give the 90degree phase shift between main and auxiulliary regardless of the phase of the (common) star point - basic geometry! The choice of common phase depends upon the motor turns ratio.

I am using a look up table and scaling to obtain pwm duty values and have a routine which reliably reads the correct values in the correct order into the duty cycle registers.

My problem comes when I try to initiate an interrupt each period (250us)
to load the next three values.

I am using centre aligned pwm (continuous up down count) PTCON0 = 0x02, except that when I try to simulate operation on MPLAB sim, although PTCON1 contains 0x80 (count up), PTMRx actually counts down to 0, rolls over to 0xFF and continues counting down. The PTIF interrupt trigger just ignores everything and stays set at 0.

As far as the pwm time base initial value is concerned, maybe my question should not be what but why?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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