PWM Setup Issue - Can't make TPMCH0 work!

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

PWM Setup Issue - Can't make TPMCH0 work!

2,326件の閲覧回数
Ryanst
Contributor I
Hi everyone... Here is the deal. I wrote some simple code:

void main(void) {

EnableInterrupts; /* enable interrupts */

TPMMODH = 0x27; // set period to x10,000
TPMMODL = 0x09;
TPMC1VH = 0x13; // set duty cycle to x5,000
TPMC1VL = 0x88;
TPMC1SC = 0x24; // set channel 1 for PWM
TPMC0VH = 0x13; // set duty cycle to x5,000
TPMC0VL = 0x88;
TPMC0SC = 0x24; // set channel 1 for PWM
TPMSC = 0x08; // select bus clock and start timer

for(;:smileywink: {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}

Well... Actually I partially wrote it. Most if it came out of a sample application that came with the MC9S08QG8 demo board. When I load this onto the chip I can measure the output at TPMCH1 as 1.67V which is rough what I would expect at 50% duty cycle. For the life of me I can't get any output whatsoever on TPMCH0... even though I just copied and pasted the code from 3 lines above it and changed a couple numbers.

After fighting with this for the day I've decided to post here. If anyone has any ideas I would be greatly appreciative! I'm sure I'm just missing something obvious and crucial.

Thanks,

Ryan
ラベル(1)
0 件の賞賛
7 返答(返信)

518件の閲覧回数
Ryanst
Contributor I
With that code the port still doesn't toggle. I've tried three different chips now too and they all behave the same way. The code below waokrs if I adjust it for Port B6... that one toggles fine. Any more ideas?

R.


int delay;

SOPT1_COPE = 0; //Disable Watchdog

TPMMODH = 0x27; // set period to x10,000
TPMMODL = 0x09;
TPMC1VH = 0x13; // set duty cycle to x5,000
TPMC1VL = 0x88;
TPMC1SC = 0x24; // set channel 1 for PWM

PTADD_PTADD0 |= 1; // PTA0: output
PTAD_PTAD0 |= 1; // init to hi state

TPMSC = 0x08; // select bus clock and start timer

// toggle PTA0 in loop (approx 5.5 msec period)
for (;:smileywink: {
delay = 30000;
while ( --delay ) {}
PTAD_PTAD0 ^= 1; // toggle
}
0 件の賞賛

518件の閲覧回数
thisobj
Contributor III
Okay, next time I promise I'll look at the schematic FIRST. :smileyhappy:

The PTA0 line muxes with an A/D input whose voltage is set by RV1 pot. Depending on the position of this pot, it can place PTA0 near ground, causing loss of pulse output.

Try removing jumper RV1 on the USER EN jumper string to remove the voltage divider from PTA0 pin. That should fix the PTA0 output problem.
0 件の賞賛

518件の閲覧回数
PatrickW
Contributor III
Oh my goodness, you just saved me a lot of time.  For anybody searching the forums - My PWM was giving a very weak signal (only 100 mV p-p) which I for some reason assumed was a result of a software problem.  I never even stopped to think about an analog solution (the voltage divider on evaluation board was still connected to the pin).

Thanks a million.


0 件の賞賛

518件の閲覧回数
Ryanst
Contributor I
Thanks so much! That fixed the problem. I'm good to go now!
0 件の賞賛

518件の閲覧回数
Ryanst
Contributor I
Here is the updated code. Still no deal. I'm definitely confused.

void main(void) {
SOPT1_COPE = 0; //Disable Watchdog

TPMMODH = 0x27; // set period to x10,000
TPMMODL = 0x09;
TPMC1VH = 0x13; // set duty cycle to x5,000
TPMC1VL = 0x88;
TPMC1SC = 0x24; // set channel 1 for PWM
TPMC0VH = 0x13; // set duty cycle to x5,000
TPMC0VL = 0x88;
TPMC0SC = 0x24; // set channel 0 for PWM
TPMSC = 0x08; // select bus clock and start timer

for(;:smileywink: {} //Loop Forever
}

Thanks,

R.
0 件の賞賛

518件の閲覧回数
thisobj
Contributor III
I ran your latest code with no problems.
Are you testing the output on J1-20 or on pin 16 of the chip?

As a test, you might want to configure the pin as an output and toggling it hi/lo in your for(..) loop to test the pin. Something like this:

void main(void) {
int delay;

SOPT1_COPE = 0; //Disable Watchdog

TPMMODH = 0x27; // set period to x10,000
TPMMODL = 0x09;
TPMC1VH = 0x13; // set duty cycle to x5,000
TPMC1VL = 0x88;
TPMC1SC = 0x24; // set channel 1 for PWM

//TPMC0VH = 0x13; // set duty cycle to x5,000
//TPMC0VL = 0x88;
//!!!!!!!!!!!!!!!!!!! add the following 2 lines !!!!!!!!!!!!!!!!!!
PTADD |= 0x01; // PTA0: output
PTAD |= 0x01; // init to hi state
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//TPMC0SC = 0x00; //0x24; // set channel 0 for PWM
TPMSC = 0x08; // select bus clock and start timer

// toggle PTA0 in loop (approx 5.5 msec period)
for (;:smileywink: {
delay = 500;
while ( --delay );
PTAD ^= 0x01; // toggle PTA0
}

}
0 件の賞賛

518件の閲覧回数
thisobj
Contributor III
The watchdog timer is probably firing while you're setting up the PWM functions. The code probably isn't making it to the __RESET_WATCHDOG() loop.

To fix this, you can either disable the watchdog early in main() or sprinkle watchdog resets throughout your setup phase. I would also recommend not enabling interrupts until after the setup/init phase.
0 件の賞賛