How do I preserve Factory Trim values when programming? - MC9S08QG8

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

How do I preserve Factory Trim values when programming? - MC9S08QG8

3,230 Views
WillDesignForFo
Contributor I
Hi folks:
 
This is my first Freescale project, so it's been a learning experience.
 
I wrote my program in Codewarrior 5.1 (that came with the demo board)
and tested it on the DEMO board for the MC9S08QG8, and it downloads
and runs OK.
 
Then I made a batch of boards with the MC9S08QG8 on it, and used the
BDM pod to download the same code to my target board.  The code got
there OK, but I realized the running frequency was wrong because the
Serial Port was spitting out garbage.
 
I'm using the ICS to use less parts.
 
So when I figured out that I overwrote the 2 bytes for the Factory Trim values
(0xFFAE, 0xFFAF), I re-wrote them with various values until my running
frequency was once again 16.0MHz and the Serial Port worked fine.
 
So after that long introduction...how do I program more boards, this time
preserving the factory trim value?
 
Thanks in advance.
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-07-18 09:13 AM
Labels (1)
0 Kudos
13 Replies

737 Views
Ake
Contributor II
Hi,
When the 9S08 is passing the last test sequences in the factory, the ICSTRM byte is changed until it gives the corrrect fBUS frequency. The value is then written into the TRIM byte high up in the Flash EPROM memory.
 
This means that when you pick a brandnew 9S08, the Flash EPROM is erased, expcept for one byte, the TRIM value.
 
To use this byte in your code, just write
 
           ICSTRM = TRIM;
and it will copy the TRIM value into the ICSTRM.
Note that it is not called TRIM in all versions of 9S08. If you get errors, look in the include file that contains all the register names, and you can see what name to use.
Also note that there are, right now, three differenct versions of the clock circuit. They are called ICS, ICG and MCG, so the xxxTRM register might not be called ICSTRM in your MCU.
 
When the Flash EPROM is bulk erased, everything including the TRIM byte is erased.
But good enough, the erase program saves the TRIM value in advance, and then writes it back after you have erased the Flah.
 
If you by mistake have managed to erase the TRIM value for good, most programmers offer an automatic update of the value. PEMicro offerers you to either use a standard value of 31.25 kHz or your own value.
 
Note that if the TRIM value gets reset, to 0xff, the ICSTRM value willl treat it as the value 0x80.
In this way, if the TRIM value gets erased, the calbration value will be +/- 0%.
 
Regards,
Ake
0 Kudos

737 Views
peg
Senior Contributor IV
Hi Ake,

I believe I took you to task on this previously, but here we go again.



Ake wrote:

When the Flash EPROM is bulk erased, everything including the TRIM byte is erased.
But good enough, the erase program saves the TRIM value in advance, and then writes it back after you have erased the Flah.
 
I
I don't think this actually happens.
If it did why does the OP have a problem?
How do you instuct CW to do it if it is not default behaviour?
After it is erased you just have it calculate it again for you.



Ake wrote:

Note that if the TRIM value gets reset, to 0xff, the ICSTRM value willl treat it as the value 0x80.
In this way, if the TRIM value gets erased, the calbration value will be +/- 0%.
 
Regards,
Ake


Which device does this occur with? All I know treat $FF as $FF. Most example code will test for $FF and then replace it with $80 but it is not done automatically by the device AFAIK.

I always erase new devices and have the software/pod calculate a new value anyway. The trim value required is affected by many variables, the biggest one is the operating voltage. So you are better off ignoring the factory supplied value and recalculating yourself with the actual board operating conditions.


0 Kudos

737 Views
WillDesignForFo
Contributor I
Thanks to both of you for replying.
 
So Peg, I'll just ask the dumb question...
 
Is there a piece of software to calibrate the Trim values, or is it manually
doing exactly what I did on the real board with the real voltage regulator?
 
Thanks
0 Kudos

737 Views
peg
Senior Contributor IV
Hi,

I see you are using Codewarrior.
In Hiwave (the debugger) under the menu named after your connection (Possibly Multilink/CyclonePro)
Choose "Advanced Programming/Debug Options"
then tick the box next to "Calculate trim and programme the non-volatile trim register"
Or if you use the Expert mode (or P&E software directly) use the PT command.

Your code will still needs to move this value(s) to the working register(s).

BTW the previous mention by Ake of this which I challenged (and remains unchallenged back) is here.


Message Edited by peg on 2008-07-18 08:35 PM
0 Kudos

737 Views
WillDesignForFo
Contributor I
Peg:
 
Thanks for the reply.
 
Yes, I am using Hiwave debugger (build 6124) to program, but the menus and their
contents (as I'm sure you know) change, depending on your environment. 
So there are two different scenarios:
 
1.  To download the DEMO board, In Hiwave's  "ICD Connection Manager" window,
      I select "connect", download and program the flash.  In this mode, the Multilink
      Cyclone Pro menu does have an "Advanced" menu item where I can select
      automatic trim as you mentioned.
 
2.  To download my board with the 6-pin BDM header, I have to use a BDM pod
      (I got a cheaper one from Univelop, since I'm not planning on programming
       many of these).  So in that mode, I cannot download the same way.  I abort
       the ICD screen, and type "set gdi" in the command window.  I no longer have
       a "Mulilink" menu.  It changes to "Open Source BDM".
 
Regards,
Virgil
0 Kudos

737 Views
JimDon
Senior Contributor III
Well, for one thing, you didn't get a cheaper one, you got a different one.
OSBDM is completely different from a P&E Multilink, and near as I can tell it does not support calibration.
The UI you see with regards to the BDM is provided by the BDM manufacturer. P&E provides the best functionality.


The good news is you should be able to use your demo board as a BDM for your production boards.

You need to solder a 6 pin header on the demo board and get a 6 pin flat cable.




Message Edited by JimDon on 2008-07-19 04:42 PM
0 Kudos

737 Views
WillDesignForFo
Contributor I


JimDon wrote:
Well, for one thing, you didn't get a cheaper one, you got a different one.
 
I got it for $40 including shipping, so I believe it was cheaper.  When I started this job I didn't even know I needed a different device to program the part than what came in the Demo kit.  That was when I started reading stuff on these boards.  When all else fails, read the message boards!  These boards are quite useful.  Thanks to all who contribute good information!

JimDon wrote:
The good news is you should be able to use your demo board as a BDM for your production boards.

You need to solder a 6 pin header on the demo board and get a 6 pin flat cable.


I was wondering if I could do that, as I see that is physically possible.  I just didn't want to try it yet and fry the demo board.  The Demo boards pull nearly the current limit for a USB device, so I didn't want to try it yet.  I would remove the microcontroller first, so there is no confusion with two micros in parallel.
 
Thanks,
Virgil

0 Kudos

737 Views
JimDon
Senior Contributor III
Well, I suppose what I meant is that while you paid less for the OSBDM, you did not get a P&E BDM for 40.00, you got an OSBDM - which as you can see is not as well supported. Buying a VW instead of a BMW does not mean you got a BMW cheaper.

Yes, you must remove the chip. It is not required that the DEMO board power the target board - just be sure not the connect the VDD pins between the two if you are using a separate power supply. The P&E USB Multilink does not supply power to the target either.

0 Kudos

737 Views
Zahar
Contributor IV
Hello Jim,

I would like to mention that using a reference design to debug a processor external to an evaluation board is not supported by P&E. While it might work for some evaluation boards and processors this is not functionality that is tested and validated by P&E.

Once a customer is ready to move to designing his custom board, we highly recommend perchasing a USB ML 12 or a Cyclone Pro.

To answer an original question, P&E calculates and programs a non-volatile trim register with the accuracy of .2% if the appropriate setting is selected in Advanced Settings dialog box.

Best Regards,
Zahar
P&E


0 Kudos

737 Views
peg
Senior Contributor IV
Hello everybody,

In order to assist P&E with this "testing and validation" process, could anyone that finds a problem with using a demoboard in this manner which is subsequently alleviated by using a USB ML 12 or Cyclone Pro please report it here.

Thank You.

0 Kudos

737 Views
JimDon
Senior Contributor III


peg wrote:
Hello everybody,

In order to assist P&E with this "testing and validation" process, could anyone that finds a problem with using a demoboard in this manner which is subsequently alleviated by using a USB ML 12 or Cyclone Pro please report it here.

Thank You.




I did buy a P&E BDM USB Multilink and for 99.00 it is a great deal. If you are a professional developer, it is the way to go.

On the other hand, I help out many students, and have discovered that the DEMO boards seem to work fine. (BTW Students can get a Multilink for 85.00). Supposedly they are not as well protected, but since I don't have a schematic I can't comment of the differences. Also, if you need to burn RS the demo board will not provide the VPP, so that is one limitation.

If asked I would recommend the 99.00 PE over the OSBDM at what ever they go for, because 99.00 is not that much and PE does an excellent job of support and features. I am grateful that PE has supplied this level of support at a reasonable price - I've paid much more for BDMs with really crappy support.


0 Kudos

737 Views
WillDesignForFo
Contributor I
Thanks for the advice on using the demo board.
 
I added the 6-pin header and ribbon cable to my demo board for the MC9S08QG8, and
it works great.  It's actually much more reliable than the connection for the Univelop BDM.
Oh, and I removed the socketed S08 on the demo board.
 
And I can now automatically program the frequency trim values.  I removed the power pin
from the 6-pin connector so I use the regulated power on the actual board for a more
accurate environment.
 
Regards,
Virgil
0 Kudos

737 Views
peg
Senior Contributor IV
Hi,

Well let's hope it was cheaper, as this is the only benefit of OSBDM over a P&E Multilink.
The OSBDM does not support trim calculation.
The hard work of trim calculation is done by the pod. The clockrate of the OSBDM is not fast enough for this.
Another method is to use connect a known frequency source and have some code in the device work it out for you. Refer to this post for some notes on this.
0 Kudos