MC9S08AW internal clock trimming

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

MC9S08AW internal clock trimming

24,718 Views
franco
Contributor I

Ciao to every body,

May any body knows anythings about 9S08AW USBBDM trimming?:

Try this:

CW5.0 with ProcExp.

9S08AW derivative

Internal trimm initialized

Internal oscillator

FLL engaged

Bus speed 10MHz

SCI bean:

9600 baud.

what you will find is that 9600 baud has at least 20% speed error.

This is why the USBBDM (Pemicro tool) and/or CW didn't make any trimming

--> FFBE=FF....and OSCTRIM =FF.

Do you know it?

Do you have any suggestion?

Have a good day

Franco

Labels (1)
0 Kudos
Reply
30 Replies

3,137 Views
Zahar
Contributor IV

Hello Jingbo,

 

The versions of CW6.1 and higher allow you to set internal clock frequency that you would like to trim device to. This setting can be configured in the connection assistant as you try to establish communication with the device. Once the frequency is set, the Codewarrior in conjunction with P&E hardware interface (USB ML 12/Cyclone Pro) will calculate trim value with accuracy of .2% of the center frequency and program it into Non Volatile Memory registers that are dedicated to storing Trim values. It is left up to the user to copy these values into ICSTRM register of your device upon startup. 

 

There is no mathematical equation to calculate the trim on 9S08 device, since the actual untrimmed bus frequency varies within +-20% of the center frequency specified in the manual.

 

Best Regards,

Zahar

P&E

 

 

0 Kudos
Reply

3,137 Views
irob
Contributor V

jingbo, continuing with what Zahar said, here is some code I have used to implement what he suggests.  On the AW60:

 

 

ICGTRM = *(unsigned char*)0xFFBE;    // Initialize ICGTRM register from non volatile memory

 

 

On the QG8:

 

 

volatile byte NV_FTRIM_INIT @0x0000FFAE;volatile byte NV_ICSTRM_INIT @0x0000FFAF; // instantiate the nonvolatile ICS Trim RegisterICSTRM = NV_ICSTRM_INIT;  // load trim value if location not blank

 

 

I should note that this method works as described for my QG8 demo board, although it is still not quite working for my AW60 demo board.  With the AW60, I get miscellaneous garbage characters in my serial port terminal, as if the baud timing isn't quite right.

0 Kudos
Reply

3,137 Views
Encoder
Contributor I

I can add another small information piece on this matter. I do not know if pertinent...

I made only experimental sessions with DEMO9S08AW60 board and Codewarrior 3.1 with all the latest upgrades. I preferred version 3.1 instead of more recent ver. 5 (which is that supplied with the board) because of a better familiarity with this version: the newer version seams to have changed some auxiliary file like .prm etc.

I work only in Assembler: I am not familiar with C. First of all I edited the former "MC9s08aw60.inc" to a reduced format (I can't approve a 145kB initial declarations for an 8 bit processor). After this the programs work pretty well when I succeed to load them in flash. In fact this is not guaranteed: 2 out of 3 times the Codewarrior Real Time debugger fails to load the assembly code on the flash memory with the P&E debugger module.

I thought this could be related to the early version I use, instead of the newer ver. 5. The simptoms seem to indicate some difficulties to synchronize the baud rate.

In my programs I started copying the $FFBE location into ICGTRM supposing either Freescale or programmer module would have trimmed this variable. I was wrong: $FFBE was blank ($FF) and writing this value to the ICGTRM was bad. Loading default midscale value ($80) gave instead a pretty accurate result for timing.

Obviously even in a small production quantity it is impractical to trim the internal oscillator by experiments... Now I ask:

1) Is there anyone who has the same difficulties as mine to get in contact with the DEMO9S08AW60 board?

2) Is there a simple automated metode to trim the ICGTRM or the default location $FFBE during the code flashing with this board and Codewarrior?

Bye, Encoder

:smileysurprised:
0 Kudos
Reply

3,137 Views
RockyRoad
Contributor III

Encoder -

Other 08 and S08 parts with trimmable internal oscillators do automatically perform a trim calculation and store the value into a flash location during programming with CodeWarrior and the P&E Multlink or Cyclone Pro. The value in flash then must be copied to the trim register by the user's software during initalization.

We are trying to track down why this has been disabled for the 9S08QW60. I'll let everyone know when I get an answer to this.

- Rocky

0 Kudos
Reply

3,137 Views
franco
Contributor I

Ciao Rocky,

thanks a lot for your time.

I hope you find the "solution" asap.

 

Have a good day and week

Franco

 

 

0 Kudos
Reply

3,137 Views
peg
Senior Contributor IV

Hi franco,

Here's the official "solution" straight from the horses mouth, Mark Cukier of P&E Microsystems:

"For the intial release of these algorithms, we commented out the trim. However, individual users are free to uncomment the trim lines (the three commented lines) to enable trim for their systems."

Didn't really get an answer as to why, but anyway.....

Regards Peg


 

0 Kudos
Reply

3,137 Views
RockyRoad
Contributor III
Sorry that this has taken so long. In addition to what peg forwarded on from P&E, I just got word that they have now tested the routines that were commented out and they work correctly on the AW60.
 
We still don't have an answer to the 'why' question. No one that I've talked to here or at P&E knows any reason that they should have been left commented out in the release version of the file.
 
- Rocky
0 Kudos
Reply

3,137 Views
seanmac
Contributor I
Download and install the latest service packs from Freescale. This issue appears to have been sorted out.
 
 
or use the "Codewarrior Updater"
 
Cheers
Sean
 
0 Kudos
Reply

3,137 Views
jingbo
Contributor I
Hi Guys,
 
I was trying to post a new thread but saw this one already about clock trimming, still couldn't find a close match to what I was looking for.
 
I am using a S08QE64 which has a ICS instead of a ICG like the S08AW.
 
Basically I need to get a uS timer interrupt. I do not have any external clock sources. I do not have any idea about clock trimming but somehow think it can help. Can anyone give me a laymans idea about what trimming is actually and how can I use it?
 
I read thru the QE128RM and QE128RUG but still can't make out anything about trimming teh internal clock.
 
thnks
0 Kudos
Reply

3,137 Views
peg
Senior Contributor IV
Hello and welcome to the fora, jingbo

OK here goes...

These devices have an internal clock source. They way they make it, it is very difficult for them to make it accurate. So they provide a method to trim it. This allows the user to adjust the trim value to get the clock running at very close to the intended rate. It also now opens up the possibility to use the trim value to run at "custom" frequencies as long as they are within the scope of the trim register for a broad range of devices and operating conditions (temperature).

Note that this clock is then used as the main clock for the CPU and there are then selectable dividers that can be applied to this to provide different frequency clocks to different peripherals in the device. The timers then have the ability to select their modulo. With all this adjustment (including additional software methods) you should be able to produce and delays/frequencies that you desire.



Message Edited by peg on 2009-01-30 08:02 AM
0 Kudos
Reply

3,137 Views
jingbo
Contributor I
Thanks Peg,
 
Can you give me some code snippets which lets me set the timers and trim them?
 
I had a look at AN3499 which speaks about ICS but the examples are for u sing the ext ref. clock so its of no use.
 
I would like to know the equations involved in the calculation of values for the registers.
For instance, when targetting a bus frequency of 8/16MHz, where do I use these values to calculate the register values? Equations make life easy!
 
Thnks,
0 Kudos
Reply

3,137 Views
Stipey75
Contributor I

Hi everybody!

 

I'm confused! I have two hw of the same products with AC32 onboard.

what i need is to use the load application mode in hi wave, i have a s19 with bootloader and appfile together, is it possible to trim automatically the micro with this mode? my s19 file is the dump of memory from 0x8000 to 0xfff.

 

How can i port the same file among more boards without bdm??

 

Help! :smileyhappy:

 

 

0 Kudos
Reply

3,137 Views
peg
Senior Contributor IV

Hello,

 

If you are using the internal clock you generally need a custom value for the trim. For this reason you can't use an "image" that you simply drop into different devices. You still need to customise the trim value. You don't NEED a BDM but it is the easiest most reliable way to get it done.

0 Kudos
Reply

3,137 Views
Francuzzo
Contributor I

Ciao Stipey75 ,

don't forget that the "vergin" Freescale pcs has the factory trim programmed......may be it was done in a different temperature and voltage environment you have in your application, BUT is surely a valid one.

So if you dont erase OR you read it before erase, you can "merge" the same S19 with the "local" trim value.....of course the "same-S19" have to avoid the trim addrees inside.

 

Have a good day

Franco

0 Kudos
Reply

3,137 Views
Stipey75
Contributor I

Thanks for the quick answer!

I solved in this way...tell me your opinion.

 

I edited s19, changed the trim value (0xFFBE) to 0xFF, now when the BDM load the application find the location erased and so saves the automatically generated value. I tried with three hw and it works? What do you think??

 

P.S.

Ciao Franco!! :smileywink:

0 Kudos
Reply

3,137 Views
peg
Senior Contributor IV

Hello,

 

The programming algorithm is not being smart here. It is simply the FLASH characteristics that means you can't programme bits at 0 to 1. FF is probably being written over the top of the factory (existing) value but it is ineffective.

This should work for you as long as the trim is close enough for you.

0 Kudos
Reply

3,137 Views
Stipey75
Contributor I

Hi!

 

Thanks for the reply..

Just a few details more...

 

I create a s19 file with bootloader and app together in this way:

 

- use BDM pod to program Bootloader code itself

- use Bootlooader to load Application code via SCI

- connect BDM pod again and read all Flash content into a S19 file

- {if necessary remove the lines with empty Flash = containing FF bytes only}

 

 

With my final s19 complete (bootload+app) i have problems with SCI..i found it was trim value! Trim value is set at 0xFFBE by bdm when i flash the bootloader...then I program with sci the app and extract the complete file.

The problem is that this s19 complete file has a trim value set for that hw inside and when i use the load application option in hi wave bdm calculate trim value but doesn't write it because it's not blank! I made the trick...put 0xFF to the location 0xFFBE in s19 file and so it works because the TRIM value is blank during flashing app process...maybe now it's more clear! :smileyhappy:

 

 

Thanks

0 Kudos
Reply

3,137 Views
Zahar
Contributor IV

Hello Stipey75,

 

Which version of Codewarrior are you working with? From your previous posts, I assume that you are using CW6.x classic product.

 

One of the ways to trim your device is by utilizing automatic trimming functionality that is built into hiwave via P&E Expert Mode  FLASH programmer along with USB ML 12 Multilink and Cyclone Pro hardware interfaces. Which hardware interface are you currently using to debug and program FLASH of your target devices?

 

Once you connect to device with hiwave debugger, please go to Expert Mode Programmer under MultilinkCyclonePro drop down menu. Please specify the .s19 file you want to program into your device and execute Erase, Blank Check, Program, Verify and Program Trim commands. The program trim command actually calculates and programs trim into designated NVM locations. P&E trim has accuracy of .2%.

 

Please note that program trim command is automatically executed if you are starting a debug session from within your Codewarrior IDE and choose to program FLASH. However, using Expert Mode programmer allows you to work with multiple devices, which seems to me like something you are interested in doing.

 

P&E also sells a stand alone FLASH programming software for S08 devices calls progHCS08 with a command line FLASH programming capability that supports scripting.

 

You can get more information about USB ML 12 and progHCS08 software using links below:

 

PROGHCS08:

 

http://www.pemicro.com/products/product_viewDetails.cfm?product_id=27&menu_id=details&CFID=4898633&C...

 

USB ML 12:

 

http://www.pemicro.com/products/product_viewDetails.cfm?product_id=33&CFID=4898633&CFTOKEN=98382f014...

 

Best Regards,
Zahar

P&E

 

 

0 Kudos
Reply

3,137 Views
Francuzzo
Contributor I

Ciao Stipey75

even if the result is obviously the same and it works, instead of force the address FFBE to 0xFF, should be better to remove that address at all..... and better again, make it by the source code.

 

What I would like to underline you, is that the "Errors/mistakes" is always possible.

REMEMBER Murphy's low !!!

 

Don't forget that,  If/when you erase the FFBE Flash sector, you will loose the factory trim value. Save it before erase, and restore it just after. 

I underline this issue because if you don't, the first thing the SW normally do is copy the Flash value to ICGTRM register......you will continue to do it BUT now you will apply 0xFF that means at least 20% wrong speed....(was the effect of the first wrong programming algorithm.......reason why of this thread)

 

Franco

 

0 Kudos
Reply

3,136 Views
yb
Contributor IV
Hi,
>Other 08 and S08 parts with trimmable internal oscillators do automatically
>perform a trim calculation and store the value into a flash location during
>programming with CodeWarrior and the P&E Multlink or Cyclone Pro
 
No, look at the window in this jpg file (CW5.0 / MultinlinCyclonePro / Advanced Programming - debug options
 
Regards,

 

 

 

0 Kudos
Reply