Microcontroller › AVR › AVR ATMEGA32 watchdog problem
- This topic has 1 reply, 2 voices, and was last updated 8 years ago by
GANEEV SINGH.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
March 19, 2011 at 11:24 am #807
vikas
Participant#include <avr/io.h>#include <avr/signal.h>#include <util/delay.h>#include <avr/eeprom.h>#define F_CPU 12000000ULvoid COUNT_PULSES(void);void PULSE_OUT(void);unsigned int PULSES1=0;float PULSES=45;float PULSES2=45;int FLAG=0;int FLAG1=0;char lcd_buffer[20];unsigned int ech EEMEM=0;int main(){TCNT1H=0x00;TCNT1L=0x00;ICR1H=0x00;ICR1L=0x00;OCR1AH=0x00;OCR1AL=0x00;OCR1BH=0x00;OCR1BL=0x00;TCCR1A=0b00000000;TCCR1B=0b00000111; //SELECT CLOCK HRER CS// Port A initializationPORTA=0x00; //ACDDDRA=0x00; //input// Port B initializationPORTB=0x00; //PUSH BUTTONSDDRB=0x00; //input// Port C initializationDDRC=0xFF; //LCDPORTC=0x00; //output// Port D initializationPORTD=0x00;DDRD=0x00; //INPUT// Watchdog Timer initialization// Watchdog Timer Prescaler: OSC/256kWDTCR=0b00011111;//WDTCR=0b00001111;_delay_ms(8000);TIMSK=0b00000100;sei();//READ FROM THEPULSES2 = (unsigned int) eeprom_read_word((uint16_t *) 10);_delay_us(20);WDTCR=0b00011111;WDTCR=0b00001111;while(1){if((PINA & 0x01) != 0 && FLAG1==0 ){FLAG1=1;TCNT1=0;COUNT_PULSES();}else{if((PINB & 0x01) != 0 && FLAG==0){if((PINB & 0x01) != 0){FLAG=1;PULSE_OUT(); //pulse out 1 or 2WDTCR=0b00011111;WDTCR=0b00001111;_delay_ms(100);FLAG=0;}}}_delay_ms(10);WDTCR=0b00011111;WDTCR=0b00001111;}return 0;}void COUNT_PULSES(){WDTCR=0b00011111;WDTCR=0b00001111;_delay_ms(1500);WDTCR=0b00011111;WDTCR=0b00001111;PULSES=TCNT1;PULSES2= PULSES;if (PULSES2 > 4){eeprom_write_word ((uint16_t *) 10, (uint16_t)PULSES2);_delay_us(20);}else{PULSES2 = (unsigned int) eeprom_read_word((uint16_t *) 10);_delay_us(20);}WDTCR=0b00011110;WDTCR=0b00001110;while((PINA & 0x01) != 0 ){_delay_ms(5);WDTCR=0b00011110;WDTCR=0b00001110;}FLAG1=0;}void PULSE_OUT(){PULSES2 = (unsigned int) eeprom_read_word((uint16_t *) 10);_delay_us(10);PULSES= PULSES2;WDTCR=0b00011111;WDTCR=0b00001111;if (PULSES == 0){__asm__ __volatile__( “SBI 0x15,2” ); // 2 cycles_delay_us(10);__asm__ __volatile__( “CBI 0x15,2” ); // 2 cycles}else if (PULSES > 0 && PULSES < 10){__asm__ __volatile__( “SBI 0x15,2” ); // 2 cycles_delay_us(20);__asm__ __volatile__( “CBI 0x15,2” ); // 2 cycles}else if (PULSES == 10){__asm__ __volatile__( “SBI 0x15,2” ); // 2 cycles_delay_us(1);__asm__ __volatile__( “SBI 0x15,4” ); // 2 cycles_delay_us(20);__asm__ __volatile__( “CBI 0x15,2” ); // 2 cycles__asm__ __volatile__( “CBI 0x15,4” ); // 2 cycles}
else
{
__asm__ __volatile__( “SBI 0x15,2” ); // 2 cycles_delay_us(1);__asm__ __volatile__( “SBI 0x15,4” ); // 2 cycles_delay_us(20);__asm__ __volatile__( “CBI 0x15,2” ); // 2 cycles__asm__ __volatile__( “CBI 0x15,4” ); // 2 cycles}
}
I am not getting the pulses defined in the PULSE_OUT() function.
Input to controllers are fine. Code is working accordingly without the watchdog.
Watchdog is of 2 sec.
EEPROM is working.
With watchdog, just not getting pulses (in asm code pulse_out()).
Can anybody trace the bug?Thanks
January 22, 2017 at 3:45 pm #14356GANEEV SINGH
ParticipantHi Vikas
I do not see watchdog timer being disabled anywhere in this code. What you are doing is you are clearing off the WDTOE bit everytime you write the second command i.e. WDTCR=0b00001111; rather you should write WDTCR=0b00010111;
For further understanding, I will suggest you to go through with Atmega32's datasheet and especially the WACHDOG TIMER stuff.
Hope this helps
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.