S08LL64/36 Difficulty controlling LVD

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

S08LL64/36 Difficulty controlling LVD

804 Views
PG1
Contributor I

I am wondering if anyone else is having problems with the LVD module in the S08 LL36/64. 

 

1. My microcontroller is using 76uA and it should be using less than 2uA per the Freescale Battery Life Calculator in STOP3,

 

2. Here is an interesting experiment and results that should avoid having to tackle the issues of floating inputs and misconfigured modules.

A, Freescale Battery Life Calulator predicts 76uA current draw with LVD on and many other details in a known state.

B. My Microcontroller draws 76uA with LVD SET TO OFF and many other details matching Freescale Battery Life Calculator.

C. I changed my software so LVD IS SET TO ON.

D. Now my microcontroller draws 76uA with LVD SET TO ON! There is no change!

 

What could be wrong? Here are my assumptions:

 

1. LVD is controlled exclusively  in SPMSC1 register. The code below should turn off LVD. See the section marked RELEVANT TO PROBLEM. (I put assembly code in startup08.c  to get control of silicon before the c run-time environment is set up to eliminate vulnerabilities)

 

 

  312:    asm {
  313:             SEI          //kill any ints that want to happen
  0000 9b       [1]             SEI  
  314:            LDA #SOPT1_INIT
  0001 a663     [2]             LDA   #99
  0003 451800   [3]             LDHX  #6144
  315:            STA 0x1802        //hard coded address for sopt registers easier than rearranging metrowerks .h and .c files
  0006 e702     [3]             STA   2,X
  316:            LDA #SOPT2_INIT
  0008 a606     [2]             LDA   #6
  317:            STA 0x1803            
  000a e703     [3]             STA   3,X
  318:            STA 0x1800             //reset wdt 
  000c f7       [2]             STA   ,X
  319:             LDA #SPMSC1_INIT
 *************RELEVANT TO PROBLEM*************** 

  000d a600     [2]             LDA   #0
  320:             STA 0x1808
************************************************ 

000f e708     [3]             STA   8,X
  321:             LDA #SPMSC2_INIT
  0011 a600     [2]             LDA   #0
  322:             STA 0x1809
  0013 e709     [3]             STA   9,X
  323:           LDA #SPMSC3_INIT
  0015 a600     [2]             LDA   #0
  324:           STA 0x180B
  0017 e70b     [3]             STA   11,X
  325: 
  326:        };

2. The LVD cannot be turned on or off from anywhere else...for instance the Multilink BDM does not change the state of the LVD.

Labels (1)
0 Kudos
7 Replies

439 Views
bigmac
Specialist III

Hello,

 

You do not seem to have taken into account that SPMSC1_LVDE is a write-once bit.  Since the code shown turns off the LVD module, you will not be able to enable later.

 

I am not sure why you would want to use inline assembly code for the functionality of the code snippet shown.  Additionally, I don't think that modifying the standard startup08.c file is good idea.  There are a couple of possible alternatives.

 

  1. When you create the project, disable ANSI startup code (leaving only the initialisation of the stack), and explicitly initialise global and static variables, after the MCU registers have been initialised.
  2. If you wish to retain ANSI startup code, it is possible to execute "prestart" code prior to startup.  A suitable framework is shown in the attached file.  In this case, the reset vector would be set to prestart function, rather than _Startup.

 

Regards,

Mac

0 Kudos

439 Views
PG1
Contributor I

Hello Big Mac.

 

1. It is necessary to use INLINE assembly  at that point because there is no C RUN_TIME ENVIRONMENT at that point.

 

2.  I disagree that SPMSC_LVDE is a write once bit. Would you please provide a citation? (Perhaps you are confusing SPMSCx with SOPTx.)  In any event, I compiled code with it SET , then I recompiled code with it RESET so it is not an issue.

 

3. With regard to modifying the startup08.c file, I have done it for over 20 projects back to when codewarrior was metrowerks. We simply add a small block of asm at the right place in the file. Of course, you can screw things up if you do not know what you are doing (putting the added assembly code in the wrong line in the file) , but there are good reasons: The first two machine instructions set critical protections for the CPU.

 

There are many "right" ways to achieve this.

 

4. Can anyone suggest why there is no change in current when LVD is ON or OFF....the Freescale Battery Life Calculator predicts I will save about 75uA with LVD off! (You can get on ON SEMI LVD reset chip that draws 0.5uA for 11 cents US).

 

0 Kudos

439 Views
bigmac
Specialist III
Hello,

 

When you measure the current draw, do you disconnect the BDM Multilink module, just in case there are side effects?  How do you actually measure the current draw at the very low levels?  I assume that any unused GPIO is set to output, including that which is not bonded to a pin.

 


PG1 wrote:

1. It is necessary to use INLINE assembly  at that point because there is no C RUN_TIME ENVIRONMENT at that point.

 


I do not understand what you mean.  I don't think that the compiler will be concerned whether an ASM block or C statements.  I can see that there are two conditions required - the stack pointer must point to a RAM location (which need not be the same location as the eventual setting), and interrupts must be globally disabled.  Both these conditions are automatically achieved after any reset.

 

With respect to my previous example, the following prestart code, that executes immediately after a reset, should accomplish what you require.  In fact, the explicit disabling of interrupts is redundant.  It does not matter that _Startup() will alter the stack pointer from the reset default location (0x00FF), because this function does a direct jump to main(), and the latter does never exit.  Therefore prestart() never exits.

 

#pragma NO_ENTRY#pragma NO_EXITvoid prestart( void){   __asm sei;             // Disable interrupts   // Prestart initialisation code   SOPT1  = SOPT1_INIT;   SOPT2  = SOPT2_INIT;   SPMSC1 = SPMSC1_INIT;   SPMSC2 = SPMSC2_INIT;   SPMSC3 = SPMSC3_INIT;   __RESET_WATCHDOG();   _Startup();  // Copydown process}

PG1 wrote:

3. With regard to modifying the startup08.c file, I have done it for over 20 projects back to when codewarrior was metrowerks. We simply add a small block of asm at the right place in the file. Of course, you can screw things up if you do not know what you are doing (putting the added assembly code in the wrong line in the file) , but there are good reasons: The first two machine instructions set critical protections for the CPU.

 

There are many "right" ways to achieve this.


What you have done can obvioulsy be made to work.  However, the disadvantage is that you are modifying a standard file that is automatically generated by the CW project wizard.  This will not be obvious to others reading the code, and is likely to be problematic should it ever be required to re-create the project for a different derivative.  As mentioned above, I do not see where there is the criticallity of the first two machine instructions.

 

Regards,

Mac

 

0 Kudos

439 Views
PG1
Contributor I

Thanks for showing another way to write pre-start code.  We prefer to have the watchdog and LVD initialized immediately after a reset, in the first 5 or 6 fetch/decode/execute cycles after the reset. With supporting documentation everything has worked out well.We will try it if when we  get this problem solved.

 

I have to admit we are really bad, bad boffins. We also modify standard .PRM files  that are produced by codewarrior to control stack size, emulate NVRAM, do CRCs on flash banks, and leave space for production programming to add their traceability data.

 

For I/O I have done the following.

1) Initialize GPIO pins as outputs-- or when they must be inputs, I have verified that the external pull ups are working by ensuring  voltages are near the rail with an Agilent 10Gohm impedance DMM. (We use 499K pull ups to save power and still operate around 1.8V- even a 10Megohm meter gives deceptive results.)

 

2) I have even accounted for the direction of GPIO pins which are multiplexed with other peripherals--we disable, enable and clock gate these modules on and off to save power in the final application. We never turn off the LCD, but I have intiialized the GPIO pins multiplexed with the LCD as outputs since I do not know what the Freescale circuitry does.

 

All current measurements  consist only off current entering the microcontroller  through the VDD, VAA. VREFH pins. These pins are lifted off the PCB, tied together, tied to a 1.0uF chip cap glued to top of the chip and then fed 3.0V through an Agilent DMM/ammeter. This should the equivalent of the current calculated by the Freescale Battery Calculator.

 

The programs are loaded with BDM. We simplify initialize and execute a STOP statement (we are setup to use STOP3 mode)  leaving the LCD running in regulated/charge pump mode. Next, the BDM is disconnected, and target power is toggled to do a reset so anything the BDM forced on is now off. We use the Internal LPO so there is no issue regarding clock sources or trimming.


We see 1100 uA with BDM connected.

We see 800+  uA with BDM disconnected

After toggling power  with BDM disconnected we see 76uA. We should see 1uA.

 

After disabling everything but the ICS, TOD, and LCD module, the clocks to the remaining modules are gated off.

 

The VREF1 and VREF2 modules are both disabled (one of them does not exist or is not bonded out)-- there are bits to gate clocks to both modules.

 

The LVD module is turned off, and the BANDGAP is turned off.

 

When we make new code to do all of the above except TURN THE LVD ON and BANDGAP ON, the current remains at

76uA. We would expect the current to increase from the prior case if we were indeed controlling the LVD.

 

 

 

 

 

0 Kudos

439 Views
PG1
Contributor I

Here is the answer:

 

To get the specified STOP3 current on the LL36/64 <1uA**, you must disable ICSIRCLK. Enabling ICSIRCLK increases the current consumption by 72uA.  If you want to operate your LCD in STOP3, you must use the clock from the TOD module. The TOD module MUST get its clock from the ~1khZ LPO which is used for WDT.  The TOD Module CANNOT USE THE ICSIRCLK, or you will have to pony up the extra 72uA.

 

Here are the states of the peripherals being used to get this current- all peripherals (except ICS of course) disabled via control register and clcok gated off*. GPIO can be inputs or outputs. However the voltage on GPIO must be VDD or VSS, so inputs need pullup or pulldowns. GPIO which is multiplexed with LCD is set to outputs. Of course the LL54/36 must not be supplying any current to a load. We are using the Internal Oscillator, not a crystal or external clock source.

 

My advice is to build your protoypes starting with the microcontroller until you get the power modes straight, then add the rest of the circuit.

 

Naturally the BDM must be discconnected, and the DBG module must be clock gated off.

 

*STOP3 kills the bus clock so I dont think there is a need to gate clocks in the SCG registers until you are in a RUN/WAIT MODE.

 

**Warning the data sheet allows up to 20uA even if you follow these steps.

0 Kudos

439 Views
PG1
Contributor I

I am sorry, indeed LVDE is a write-once bit, I want if off because it costs 75uA to operate LVD and you can get the same thing with an external chip that draws 0.5uA.

 

But as I have stated, I compiled with the bit set. Then I compiled with the bit reset.

 

There was no change in current.

0 Kudos

439 Views
PG1
Contributor I

I cannot read the state of the bits that may be causing the problem!. Unfortunetly, there is a big discrepancy between the Reference Manual and the True  Time Simulator.   And based on the behavior I am observing, the reference manual is incorrect.

 

 

 

The first picture is the manual.

The second is picture is the true time simulator.

The simulator conflicts with the manual.

 

 

 

 

0 Kudos