m64 does not restart after power down

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I posted this issue on an old post which was somewhat related, but decided to create a clean new post just to get it fixed.

I read the input voltage ~15V to a 7805 voltage regulator with the ADC, and if the voltage drops below 9.5V, i write a value to eeprom before power is totally out (i test it by unplugging the adapter from the wall) - after a few minutes, i turn the power on again and the m64 DOES NOT restart. Only if i press the RESET button it restarts, and i see that the value was successfully written to eeprom - and also, after RESET the status LED (at PE6) turns on.

In the code, Ew is increased every second, and the value is sent via the USART_TX and an xbee to my laptop. If power goes down and on again (AFTER HAVING TO PRESS RESET) the value of Ew continues from where it was before power down, and does not re-start from 88 (initial value) - indication that it was written successfully to eeprom.

OCDEN, JTAGEN & BODEN fuses enabled - BODlevel 2.7V

ANY IDEAS WHY THE CHIP IS NOT RE-STARTING AFTER A POWER DOWN??!! (yes, i do wait for the input voltage to drop to 0V before powering it up again)

Thank you!
ps complete code is attached

/************** DATA **************/
char Ew_str[4];			
volatile double Ew;			// EEPROM
/**********************************/

/************* EEPROM *************/ 
unsigned char EEMEM eepowerOut = 0;	// NEEDS TO BE UNSIGNED
unsigned int EEMEM eeEtotw = 88; //--> E wind tot!!!
unsigned char powerOut;	// is / was power out?
unsigned char written = false;
volatile unsigned int Vcheck; 
/**********************************/

int main(void)				
{
	USART_init();	
	initADC();
	sei();

    volatile int temp0,temp1;	
		
    for(temp0=0; temp0<0x0040; temp0++)	// Wait for external clock crystal to stabilize
    {	for(temp1=0; temp1<0xFFFF; temp1++);	}

    TIMSK &=~((1<<TOIE0)|(1<<OCIE0));	//Disable TC0 interrupt
    ASSR |= (1<<AS0);					//set Timer/Counter0 to be asynchronous from the CPU clock 
										//with a second external clock(32,768kHz)driving it.
	OCR0 = 0x00;						//PAGE 131 ATmega16 manual
    TCNT0 = 0x00;
    TCCR0 = 0x05;				
/* 0101 - CS22 CS21 CS20 --- 
Prescale the timer to be clock source / 128 to make it exactly 1 second for every overflow to occur */

	while(ASSR&0x07);					//Wait until TC0 is updated
    TIMSK |= (1<<TOIE0);				//set 8-bit Timer/Counter0 Overflow Interrupt Enable
  	
	/****** EEPROM ******/
// read state of powerOut flag - should be 0 if not initialized
	powerOut = eeprom_read_byte(&eepowerOut);
	Ew = eeprom_read_word(&eeEtotw);

	if (powerOut != false || powerOut != true)	// 1st time the chip runs
	{
		powerOut = false;
	}
	
// status LED & XBEE sleep pin
// PE6 high, PE7 low. Power to LED & xbee pin 9 --> low
	DDRE = 0b01000000;
	PORTE = 0x40;

	timer = 0;	

	while(1)
    {	
		Vcheck = 0;
		Vcheck = Vin();			// time between readings? 

		if (Vcheck <= 9500)		// --> [mV] power out
		{
			powerOut = true;	// before sending to sleep (ISR condition)
			
			PORTE = 0x00;		// 0b10000000 PE6 low LED. PE7 high sends xbee to sleep.
			
			if (written == false)
			{
				// WRITE
				cli();
				eeprom_write_byte(&eepowerOut, powerOut);
				eeprom_write_word(&eeEtotw, (unsigned int)Ew);			// Ew is declared double
				sei(); 
				written = true;	
			}
		}
		else if (Vcheck > 9500 && powerOut == true)	// there was outage - back with power
		{
		//	PORTE = 0x40;		// 0b01000000 - turning power LED & xbee back on		

			powerOut = false;	
			written = false;	// already written to eeprom

			// READ to restablish values prior to outage
			Ew = 0;		

			cli();
			Ew = eeprom_read_word(&eeEtotw);
			sei();
		}
		else		// power is ok
		{
			if (dataSent == false)
			{					
				wind_API();			// send Ew USART
				dataSent = true;
			}

			if (timer >= 10)				// send every 10 seconds		
			{						
				timer = 0;
				dataSent = false;
			}
		}
    }
return 0;
}
/************************************************************************************************/

ISR(TIMER0_OVF_vect)				//overflow interrupt vector
{
	Ew = Ew + 1;	
	timer++;
}

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the MCUSR value?

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MCUCSR?

In my original code i have

int main(void)				
{
	MCUCSR = (1<<JTD);					// this disables the JTAG - Atmel require 2 writes in 4 cycles
	MCUCSR = (1<<JTD);

	USART_init();	
	initADC();

since i needed to use the ADC pins that are shared with the JTAG. But i deleted these lines in this code, and i'm not setting any bits in MCUCSR. Any ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

ANY IDEAS WHY THE CHIP IS NOT RE-STARTING AFTER A POWER DOWN??!! (yes, i do wait for the input voltage to drop to 0V before powering it up again)


What else is connected to the AVR? Are any of the attached signals high, providing parasitic power?

Delay 123ms. at the start of main(). Betcha a cold one. ;)

(your AVR will come out of reset as soon as a proper Vcc level is reached. But that will be when the raw voltage is (probably) just a bit more than Vcc. You are testing (as I would) for a raw supply level that far exceeds Vcc; thus, you are immediately again tripping. Your AVR >>is<< starting; it is your >>app<< that is sending it back to limbo..)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it is named MCUCSR in m64, all other AVRs have MCUSR.
Just read the chapter applying to MCUCSR and post us its value (to read the valid value, you must clear it before reset) once the chip gets operational (set a breakpoint at main()).

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You are testing (as I would) for a raw supply level that far exceeds Vcc; thus, you are immediately again tripping. Your AVR >>is<< starting; it is your >>app<< that is sending it back to limbo..)

I am not sure i understand what you mean. I'm not tripping if the voltage is low, just writing to eeprom and setting a flag - if the voltage stays low (2.7

BUT!

int main(void)				
{	
	_delay_ms(500);

	USART_init();	
	initADC();
	sei();

PROBLEM SOLVED! Why? not sure! :P

THANK YOU LEE. can i ship a cold beer from chicago (is it a allowed to ship alcohol?!)? :)

EDIT. Thanks Brutte to you as well for the input!