Having trouble with the PWM setup

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Having trouble with the PWM setup

2,172 次查看
HT
Contributor I
HI,
Using Code warrior special edition
version 5.7.0
Build 1932
Full chip simulation but i intend to use a HC12 (S12DP512)

Im currently trying to configure PWM channels to work with 16 bits

From the .pdf file i found:

"The PWMCTL register contains four control bits, each of which is used to concatenate a pair of PWM channels into one 16-bit channel."
 

Here is my code

Code:

void setupPWM(void){  PWMPOL = 170; /* outputs are high at the beginning of the period, then go low when the duty count is reached. */  PWMCAE = 0;   /* operate in left aligned output mode. */  PWMCLK = 0;   /* Clock B is the clock source for PWM channel 7 and 3, Clock A is the clock source for PWM channel 1and 5. */  PWMPRCLK = 0; /* Clock A = Clock B = Bus Clock */  PWMCTL = 255; /* Channel 0-1 , 2-3 , 4-5 , 6-7 concatenated */  PWMSDN = 0;   /* Disable Emergency shutdown */  PWMPER01 = 8000; /* setup for PERIOD */  PWMDTY01 = 4000; /* setup for DUTY CYCLE */  PWME = 255;   /* Enable PWM function on Port P for all channel */}void main(void){  setupPWM();  EnableInterrupts;  for(;;){  }}


 

Then im using the true-time simulator
with a LED as the visualisation for the adress 0x258 of the PTP byte
and i have no reaction

The documentation mentionned to set PWMPERx > PWMDTYx
which i did

then i tried this ( these examples are for a duty cycle around 50%)

Code:

PWMPER01 = 8000;PWMDTY01 = 3841;


 and with this the LED is working properly

I think the simulator does a comparison between each 8 bits PWMPER1 and PWMDTY1 or PWMPER0 and PWMDTY0 to check the condition "PWMPERx > PWMDTYx"

well can someone help me

标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

588 次查看
HT
Contributor I
well i really need to know if i did something wrong with my prog or if there is a bug with the emulator that would compare each 8 bit sequence of the number 4000 with 8000

4000= 0F | A0
8000= 1F | 40
This should work since DTYx is inferior to PERx but i think it blocks with the part A0 beeing superior to 40 even if 0FA0 is inferior to 1F40

This doesnt work while 3841 instead of 4000 works

3841= 0F | 01 this time 01 is inferior to 40 so that both 8 bits DTyx parts are inferior to the 8 bits parts of the Perx register

I cant check right now if this works or not with a real target though ...

Message Edited by HT on 2006-07-17 03:09 PM

0 项奖励
回复

588 次查看
admin
Specialist II

Not sure if it's related, but I was also having some difficulty with the PWM setup.  I documented my woes in this thread:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=1646

but unfortunately got no response.  Maybe someone can cure both our ills.

-Tomahawk