I need help setting up the PWM - HCs12C32

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I need help setting up the PWM - HCs12C32

1,797 Views
StefX2
Contributor I
Hello,

I'm new with this kind of kind of microcontrollers. I have a HCs12C32 development board and I'm trying to get tha hang of it.

I want to use the PWM to drive a small servo-motor.

What I coulnd't understand by myself is how to set the dutycicle for my PWM. What is the usual syntax?
I want to use it along with the ATD. I want to copy the value form the ATD register and by this modify the dutycicle.

Here is small part of my software:

 PWMPOL_PPOL1=1;
 PWMCLK_PCLK1=1;
 PWMPRCLK_PCKA0=1;
 PWMPRCLK_PCKA1=1;
 PWMPRCLK_PCKA2=1;

p=(uint)ATDDR0H;
PWMDTY1=p;

First I get an warning message telling me: "Posible lose of data".
I tested it on a LED and it seems to work OK. The LED seemed to change it's brightness OK. However With the motor it doesn't work to fine. I'm having problems with dutycicles above(70%-It is a guess).

My basic question: How do i set the dutycicle corectly? Do I simply enter 1 for 1%, 23 for 23% 100 for 100%? (PWMDTY=23:smileywink:

Thank you!
Stefan
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-01-23 06:42 AM
Labels (1)
0 Kudos
Reply
2 Replies

910 Views
DPB
NXP Employee
NXP Employee
In the posted code there is no mention of PWMPERx, however this register must also be configured.

The PWM duty cycle is directly related to the ratio of PWMDTYx to PWMPERx  (where x denotes the channel number).
Thus for the case PPOLx=1 as in the given example then
Duty cycle = [PWMDTYx / PWMPERx] * 100%

For  Polarity = 0 (PPOLx = 0) then
Duty cycle = [(PWMPERx - PWMDTYx)/PWMPERx] * 100%
This explained in more detail in section 12 of the S12C-Family reference manual...
http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S12C128V1.pdf?pspll=1
See pages 368 and 375-379

DPB
0 Kudos
Reply

910 Views
StefX2
Contributor I
    Thank you a lot!

Sometimes the answer is in front of you but you need somebody to open your eys.
0 Kudos
Reply