newb question: why cant i get stop1 to work?

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

newb question: why cant i get stop1 to work?

Jump to solution
1,669 Views
thorin
Contributor I
As you can see, once the sampling loop is done, i want the chip to go into stop1 mode. I have leds tied to PTA 0,2,3,4. when the program hits the stop command, the leds remain in their last state. Isn't stop1 supposed to reset all ports?
thanks in advance.





#include
#include "derivative.h"

#define FREQ_BUS 8000000 // 8 MHz
#define NUM_BUS_CYCLES (FREQ_BUS * 100)/1000000
#define DELAY_X_VALUE (((((NUM_BUS_CYCLES - 6)*10)/4)+5)/10)-1
#define DELAY_TIME 500 // ms

// ICSTRM location in Flash
unsigned char ICSTRM_FLASH @0xFFAF;

// Flash security (NVOPT Register)
const unsigned char FLASH_SECURITY @0xFFBF = 0xFE;

/////////////////////////////////////////////////////////////////////////////////////////
// PeriphInit
// --------------------------------------------------------------------------------------
// Initializes various registers and peripherals
/////////////////////////////////////////////////////////////////////////////////////////
void PeriphInit(void)
{
// Disables COP
SOPT1 = 0b01100011; // Watchdog disable. Stop Mode Enable. Background Pin
// enable. RESET pin enable
SPMSC2 = 0b00000010;
SPMSC1 = 0b00000000;


PTAD = 0b00000000; // write 0 to all A ports
PTADD = 0b00011101; // activate A ports 1, 3, 4, 5
PTAPE = 0b00000000; // no pull up resistor for ad1
ADCCFG = 0b00010000;// AD full power mode, 8 bit conversion, clock/1
APCTL1 = 0b00000010;// disable pta1 as an IO pin.

// Configures ICS clock. Selects FLL Engaged Internal Mode (Divides ICSOUT by 1)
// fBUS about 8 MHz
ICSTRM = ICSTRM_FLASH;
ICSC2 = 0x00;
ICSC1 = 0x04;
// Waits until output FLL is selected (CLKST=00)
while (ICSSC & 0x0C)
;
}


/////////////////////////////////////////////////////////////////////////////////////////
// Delay_100us
// --------------------------------------------------------------------------------------
// This subroutine performs a specified delay in multiples of 100 us
/////////////////////////////////////////////////////////////////////////////////////////
void Delay_100us (unsigned char hundreds_us)
{
asm
{
lda hundreds_us
beq exit
delay_us:
ldx #DELAY_X_VALUE ; [2]
loop:
dbnzx loop ; [4]
dbnza delay_us ; [4]
exit:
}
}





/////////////////////////////////////////////////////////////////////////////////////////
// MAIN
// --------------------------------------------------------------------------------------
// Entry point
/////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{

unsigned int blink;
unsigned int x;

EnableInterrupts;
PeriphInit();

ADCSC1 = 0b00100001; // activates the AD1 converter channel. i think.

for (x=0;x255;x++) // sampling and readout loop
{


blink = ADCRL; // gets analogue result value

if (blink >= 225)
PTAD = (0b00010001); // possible loss of data?
else if (blink >= 200)
PTAD = (0b00010000); // possible loss of data?
else if (blink >= 175)
PTAD = (0b00001101); // possible loss of data?
else if (blink >= 150)
PTAD = (0b00001100); // possible loss of data?
else if (blink >= 125)
PTAD = (0b00001001); // possible loss of data?
else if (blink >= 100)
PTAD = (0b00001000); // possible loss of data?
else if (blink >= 75)
PTAD = (0b00000101); // possible loss of data?
else if (blink >= 50)
PTAD = (0b00000100); // possible loss of data?
else if (blink >= 25)
PTAD = (0b00000001); // possible loss of data?
else
PTAD = (0b00000000); // possible loss of data?


Delay_100us(255);
}


//PTAD = 0x01;
asm STOP;

}
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
693 Views
fabio
Contributor IV
Hi Thorin,

Some advises:

1- If you tell us which part you are using it is easier to help! :smileywink:

2- Some HCS08 do not have STOP1 mode;

3- While in debug mode the MCU can't enter STOP1 nor STOP2 modes;

4- The LVD circuit must be disabled in order to enter STOP1 and STOP2 modes (your code correctly disabled the LVD circuitry).

My book HCS08 Unleashed has some examples on Low power modes. The examples can be downloaded at www.sctec.com.br/hcs08 .

Best regards,


Message Edited by fabio on 2008-08-08 10:41 AM

View solution in original post

0 Kudos
Reply
1 Reply
694 Views
fabio
Contributor IV
Hi Thorin,

Some advises:

1- If you tell us which part you are using it is easier to help! :smileywink:

2- Some HCS08 do not have STOP1 mode;

3- While in debug mode the MCU can't enter STOP1 nor STOP2 modes;

4- The LVD circuit must be disabled in order to enter STOP1 and STOP2 modes (your code correctly disabled the LVD circuitry).

My book HCS08 Unleashed has some examples on Low power modes. The examples can be downloaded at www.sctec.com.br/hcs08 .

Best regards,


Message Edited by fabio on 2008-08-08 10:41 AM
0 Kudos
Reply