MC 9S12C128  PWM TESTING problems

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

MC 9S12C128  PWM TESTING problems

2,132 Views
Raptor
Contributor I
I recently purchased a NANOCORE12MAX128 which has a MC9S12C128 microcontroller form freescale on board. This is what is advertised and i can actually read this off top of the chip

mc9s12
c128cfae

When I load up codwewarrior and attempt to run the True-Time Simulator and Real Time Debugger, it says
Set derivative
The MCUID of this derivative is 0x2CF
Part ID returned from the connected derivative matches with multiple derivatives

and the only options it has are for MC9S12Q 64, 96, and 128. This is important as the Q variant only has 4 PWM channels unlike the C model which has 6. So I think that I have a C model, but the software / serial monitor is misidentifying the target. At first I just selected the Q128, and that worked well for a while, but when I tried to run this code to see if my pwm works. 

#include <hidef.h> /* common defines and macros */
#include <mc9s12c128.h> /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12c128"
#pragma CODE_SEG DEFAULT

void main(void)
{
//Enabling portT for PWM0
MODRR =0x05;
/*
The line MODRR=0x01 IS (IN MY ONE)
necessary if your PWM
in not multiplexed with the Timer module.
Check the block diagram of your circuit.
*/

PWMCLK=0x05;
PWMSCLA=0xFA; //HEX 250 C8
PWMPRCLK=0x07;

PWMPER0=0xFA; //HEX 250
PWMDTY0=0x7D; //HEX 125

PWMPER2=0xFA; //HEX 250
PWMDTY2=0x7D;

PWME=0x05;

while(1){
}
}

//f=4MHz/250/128 (prescale A)/250 (scale a) = 0.5 Hz

running this code causes the PWM channel 0 to beat at 0.5 Hz, (first led on school board) with a 50% duty cycle. But PWM channel 2 beats way faster, as if it is not being scaled down (a red led with 340 ohm resistance in series). What is causing this problem!!@@?? I have been able to vary the duty cycle on both the correctly 0.5Hz pins and the ones that flash tooo fast.
 
I have tested the first 5 channels of the PWM on port T using bit masks on the MODRR PWMCLK and PWME registers. and 0 and 1 work, 2 and 3 have the higher frequency malfunction and 4 works at 0.5 Hz.
Labels (1)
0 Kudos
4 Replies

493 Views
Raptor
Contributor I
Thanks Kef I read the manual and I programmed it properly.
 
PWMSCLB=0xFA;               //HEX 250 C8
PWMPRCLK=0x07|(0x07<<4);
 
 
0 Kudos

493 Views
Raptor
Contributor I
I did as you said. It did not change the behaviour. I think the serial monitor might be responsible for this mess, because it is unlikely the PWM channel would work at all if it was a hardware failure right?.
0 Kudos

493 Views
kef
Specialist I
Raptor,
 
PWM2 and PWM0 use different clocks, clock A and clock B. You set both PWM clocks for  for scaled B (SB) for PWM2 and scaled A (SA) for PWM0. But you set PWMSCLA only for clock SA, but not for SB.
0 Kudos

493 Views
Lundin
Senior Contributor IV
I believe you should write 0x1F to MODRR in order to get all PWM pins mapped to port T.
0 Kudos