9S08SG16 problem with trim value

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

9S08SG16 problem with trim value

1,153 Views
ttom
Contributor I

Hello,

I use the 9S08SG16 and want to do serial communication with 19200 Baud and use the internal clock reference. I use the ICS module with locked FLL and reading the factory set trim value and so I should get a accuracy of about 1%.

As far as I understand the appnotes, the value of NVOPT is automatically read at startup from flash and stored in the ICSTRM working register.

In my hardware, I see a difference in the baud rate (having about 21000 Baud instead of 19200). I have already checked the register values for initializing the SCI - interface.

But now, I found in the memory view at the location 0xffaf (NVTRIM), that the trim value is equal to zero. But the value ICSTRM register is 0x80 (default value).

 

I have checked in parallel with my demo board for 9S08SG32 (On the demo board I have a trim value of 0xB4).

I have the following differences between the demo board and my hardware (I have two simple projects with the same uart - module, because of two different controllers on demo board and my hardware):

 

On startup (when loading the flash with the hiwave - window), the process runs without any break on the demo board.

But on my hardware, I get a message "Initializing - error measureing trim values, device is secured. Erasing...", then comes up a Power Cycle Dialog, and then the flash is loaded to the device.

I see the value at 0xFFBF (NVOPT) = 0x7e, which means that device is unsecured (until next reset?) and a trim value of 0x00 at adress 0xFFAF (NVTRIM).  In the register ICSTRM (working register of ICS) there is the value 0x80.

 

On the demo board, I have a value of 0x7E for the NVOPT (0xFFBF) and a trim value of 0xB4 (at 0xffaf). In the ICSTRM register is the value 0xb3. I think, this is ok.

 

So I don't understand 3 things:

Why is the trim value == 0 (in flash) on my hardware with the S08SG16?

And why is this value not transferred to the working register ICSTRM?

Why is the trim value on the demo board (with 9S08SG32) in flash different to the value in the working register? (0xb4 and 0xb3).

 

May be silly qustions, sorry.

But I didn't find (or didn't understand?) answers in the appnotes or the other documentation. 

 

Thomas

Labels (1)
0 Kudos
1 Reply

327 Views
pgo
Senior Contributor V

Dear ttom,

 

I have found that the operation of the clock trimming in the various HCS08 devices rather confusing too!

 

Some comments:

===========================

For ICSTRM & FTRIM bit in ICSSC

===========================

For SOME devices (e.g. -SV16 -SE8) these locations are loaded from a hidden Flash location upon power-on-reset.  The location contains a factory-trimmed value.

 

For SOME devices (e.g. -SG16) these locations are reset to 0x80 & 0 upon power-on-reset.  It is up to your program to copy the values from regular flash locations (NVTRIM:NVFTRIM).  This is usually done in the reset code.

 

For SOME devices (e.g. -LG32) these locations are automatically loaded from the regular flash locations (NVTRIM:NVFTRIM) upon power-on-reset. 

 

To further confuse - Some devices have the  (NVTRIM:NVFTRIM) locations pre-programmed with factory trimmed values.  Others are programmed to zero (according to the manual!).

 

Note also that the value in ICSTRM & FTRIM bit in ICSSC are NOT affected by normal resets - only POR.

 

Finally - If operating in debug mode using a BDM then the above automatic initialisation from Flash locations doesn't happen and they are reset to default values of $80/0 only (I think!).

 

The outcome - very Carefully read the manual for the actual chip you are using to determine what happens.  The app notes may not apply directly to your chip!  The only safe alternative that works in all three cases is to assume the second case, do your own trimming & copying.

 

The above is further confused by whether the programmer you are using will:

Determine trim values.

Preserve the factory trim values.

 

 

Comments on your specific questions:

So I don't understand 3 things:

Why is the trim value == 0 (in flash) on my hardware with the S08SG16?

This sound like your BDM is not trimming the chip correctly OR

The program you are loading has a value for the trim location which is being used instead.

 

And why is this value not transferred to the working register ICSTRM?

See above - The transfer is not automatic for the -SG32.  In any case, the transfer wouldn't happen when using a BDM anyway.

 

Why is the trim value on the demo board (with 9S08SG32) in flash different to the value in the working register? (0xb4 and 0xb3).

 

Differ by 1 - No idea!  I don't even know why its getting initialised at all.

 

I hope the above helps rather than confuses.

 

bye

 

 

Example code to manually copy the trim values from Flash to clock registers:

 

// These locations _may not_ be copied automatically
// The volatile is needed to stop optimisation.
// The initialisation is needed to prevent the automatic creation of
// default variables with zero values.
volatile const byte NVFTRIM_INIT  @0x0000FFAE = 0xFF;
volatile const byte NVICSTRM_INIT @0x0000FFAF = 0xFF;

// This location is automatically copied to registers
// Alter to modify the security
const byte NVOPT_INIT    @0x0000FFBF = NVOPT_SEC01_MASK;

void init(void) {

   SOPT1 = SOPT1_BKGDPE_MASK; // Disable COP, enable BKGD pin
  
   if (NVFTRIM_INIT != 0xFF) {
     // Only done if trim locations have been programmed
     ICSSC  = NVFTRIM_INIT;
     ICSTRM = NVICSTRM_INIT; 

     // FLL Engaged Internal, BDIV=/1,
     ICSC1  = ICSC1_IREFS_MASK;
     ICSC2  = 0x00;//|ICSC2_BDIV0_MASK;
   }

}

 

 

 

 

 

0 Kudos