S12X PLL, RTI, Timer Prescaler Problems

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

S12X PLL, RTI, Timer Prescaler Problems

9,787 Views
jarod31
Contributor I
Dear all,
 
I'm trying to move a small application from an S12 to an S12X and I'm having a few problems. First of all I want it to run at 40MHz bus speed so I've set the PLL to 80MHz compared to the S12 which used to run from a 16MHz crystal without PLL. From here the problems started... I tried to set the RTI interval at 512us (0x44) and I don't know if that's correct or if it's working. Next I'm having problems with the timer prescaler. How do I set the prescaler for 1us ? And last, I've noticed that the PWM is acting a little weird. I have a buzzer on my board and i set the pwm frequency to 1953 Hz on both MCUs. However, on the S12 I can hear the buzzer very loud compared to the S12X at the same volume setting. And the volume goes lower as i increase the PLL freq. or higher as i decrease it. The same happends with a motor which is controlled by the MCU. On the S12 i get a lot of power from the motor and on the S12X it is running very "soft".
 
Any help is greatly appreciated.
 
Thanks,
Jarod
Labels (1)
0 Kudos
Reply
8 Replies

1,531 Views
imajeff
Contributor III
Jarod,

The RTI frequency might be a simple problem because Steve says the RTI uses the OSCCLK instead of the Bus Clk. In your first post it appears that because you changed PLL to 80 MHz, you increased the divisor. Instead, the divisor should not change from previous because the oscillator clock did not change.

For the other prescaler, It might be a similar confusion of what clock is the source.

Message Edited by imajeff on 04-25-200607:39 AM

0 Kudos
Reply

1,531 Views
imajeff
Contributor III
Sorry I thought the 40 was something else, but would have known if you mentioned 0x40 and 8192 or 2^13 together.

I don't see that they fixed their documentation problem yet, it is hard to follow docs for the hardware modules in 9S12X. It appears I should be looking at the same pdf that is for the 9S12 ECT, unless there is another "S12XECT_16B8CV1.pdf" that they are not listing.

Assuming some things they are not clear about, the only prescaler is 3 bits in TSCR2. If that is right, then there is no way to divide the bus clk by any other value. That means you would have to either adjust the bus clk so the given divisors work, or rescale your code that decides what values to use in the timers.

P.S. have you found any documentation on PTPSR ?

Message Edited by imajeff on 04-25-200608:12 AM

0 Kudos
Reply

1,531 Views
imajeff
Contributor III
Ok, apparently Freescale wants me to guess more. "S12ECT16B8CV2.pdf" seems to be found by searching for keyword ECT_16B8C. Although that does not imply any connection to S12X, it does in fact document the PTPSR that does appear to be in the S12X. Great, huh.

So whatever prescale values it lists there, that's what you can do with it. I guess.

P.S. Although I found the V2 doc above by searching, the search used to never find any docs. Well, that would be better than nothing except that I did not know when it started working.

[Common, Freescale, get with the Documentation project !!]

Message Edited by imajeff on 04-25-200608:27 AM

0 Kudos
Reply

1,531 Views
Steve
NXP Employee
NXP Employee
imajef, you don't need to hunt for the description of the precision prescaler because it is in the S12XD databook (pages 443-). All the S12X parts and the newer S12 parts have a single databook with everything included.:smileyhappy:
Jarod, the precision prescaler is selected with a bit (PRNT) in the TSCR1 register. This causes the timer prescaler to change from being a binary prescaler (in TSCR2 per S12) to a modulus prescaler. The S12 mode is still there for backwards compatibility. The modulus prescaler allows you to divide by 1 (0x00) to 256 (0xFF) in single count steps. Have a look at the databook from page 477. If you want to divide by 40 then put 39 (decimal) in the precision prescaler and set PRNT. I think you already worked this out since 0x27 is 39.
Have a look at AN2615 which outlines the differences between S12 and S12X (including this) and would help you take advantage of the new features on the part.

Message Edited by Steve on 04-25-200605:54 PM

0 Kudos
Reply

1,531 Views
jarod31
Contributor I

Hi Steve !

Thank you for your advices. I got it to work in the end. The datasheet is a bit fuzzy but I understood it finally. RTI 0x40 for 16MHz crystal gets me close enough of 512us and the PTPSR 0x27 is working great !

Thanks again,

Jarod

0 Kudos
Reply

1,532 Views
jarod31
Contributor I
Yes, I've read the datasheet and i understood that. As i mentioned before, I've changed it back to 0x40 which is close enough to 512us. The problem now is that i don't know how to set the precision timer prescaler to 40. Is it correct if i set the PTPSR = 0x27 ?
 
Thanks,
Jarod
0 Kudos
Reply

1,532 Views
Steve
NXP Employee
NXP Employee

Jarod,

 You should start by confirming that the PLL is actually selected and at the speed you expect. It sounds as if there may be a problem there.

 The RTI always runs from the oscillator clock so your divider looks much too high, you should be dividing by 8192 from a 16MHz oscillator.

 You can have the timer prescaler giving a 1us tick by dividing by 40 (from 40MHz bus speed). You need to use the precision prescaler mode (see PTPSR and TSCR1 registers).

 If the bus speed isn't right the PWM will behave differently.

0 Kudos
Reply

1,532 Views
jarod31
Contributor I
Hi Steve !
 
Ok, I've thought about setting the prescaler to 40 but as i've seen in the datasheet it can only be set from 1 to 8 and then only to 16,32,64 etc. Could you give me a short code example of how to set the prescaler to 40 and initialize the precision timer ?
As for the RTI, I've set it to 0x40 which theoretically should give me around 507us with a 16Mhz crystal. Is this correct ?
 
Thanks,
Jarod
0 Kudos
Reply