fateme91
Member level 2
- Joined
- Nov 18, 2014
- Messages
- 48
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 18
- Location
- Iran,Mashad
- Activity points
- 349
Code dot - [expand] 1 2 3 4 5 6 7 8 9 10 11 interrupt [TIM0_OVF] void timer0_ovf_isr(void) { PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); MCUCR=0b00111000; #asm("sleep"); }
Disable sleep mode MCUCR &= ~(1<<SE); by resting the SE bit and interrupt should wake up micro controller.You didnt tell what kind of interrupt you have at pin 6 so hard to answer with out code or and other useful information.
**broken link removed**
And one more thing I advice you to read datasheet in details in other of your post most of information you get in there.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 interrupt [TIM0_OVF] void timer0_ovf_isr(void) { PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); } void main() { timer_inital(); // your timer 0 initialize function here sei(); //set interrupt MCUCR &= ~((1<<SM1)|(1<<SM0)|(1<<SM2)); //for idel sleep mode while(1) { MCUCR=0b00111000; //set the SE bit #asm("sleep"); MCUCR=0b00011000; //reseting the SE bit } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 Chip type : ATmega128 Program type : Application AVR Core Clock frequency: 16.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 1024 *****************************************************/ #include <mega128.h> #include <delay.h> #include <sleep.h> // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isr(void) { MCUCR =0; PORTD.0=1 ; delay_ms(1000); PORTD.0=0 ; } // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; } // Declare your global variables here void main(void) { // Declare your local variables here PORTA=0x00; DDRA=0x00; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0x01; PORTE=0x00; DDRE=0x00; PORTF=0x00; DDRF=0x00; DDRG=0x00; // Timer/Counter 0 initialization ASSR=0x00; TCCR0=0x05; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // Timer/Counter 2 initialization TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // Timer/Counter 3 initialization TCCR3A=0x00; TCCR3B=0x00; TCNT3H=0x00; TCNT3L=0x00; ICR3H=0x00; ICR3L=0x00; OCR3AH=0x00; OCR3AL=0x00; OCR3BH=0x00; OCR3BL=0x00; OCR3CH=0x00; OCR3CL=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: On // INT1 Mode: Falling Edge EICRA=0x08; EICRB=0x00; EIMSK=0x02; EIFR=0x02; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; ETIMSK=0x00; PORTD.0=1 ; delay_ms(2000); PORTD.0=0 ; delay_ms(2000); // Global enable interrupts #asm("sei") while (1) { ASSR=0b00001000; MCUCR=0b00111000;// Enable sleep mode #asm("sleep"); } }
If you look at the example in the link which i posted in earlier post then your code should like this
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 interrupt [TIM0_OVF] void timer0_ovf_isr(void) { PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); } void main() { timer_inital(); // your timer 0 initialize function here sei(); //set interrupt MCUCR &= ~((1<<SM1)|(1<<SM0)|(1<<SM2)); //for idel sleep mode while(1) { MCUCR=0b00111000; //set the SE bit #asm("sleep"); MCUCR=0b00011000; //reseting the SE bit } }
but what is your interrupt for waking up cpu in my example code interrupt occurred when timer overflows every 250ms and controller wakes up with this interrupt trigger.
Code C - [expand] 1 2 // start timer0 with /1024 prescaler TCCR0 = (1<<CS02) | (1<<CS00);
you need to set the pre scaler for timer
Code C - [expand] 1 2 // start timer0 with /1024 prescaler TCCR0 = (1<<CS02) | (1<<CS00);
for debugging try to make overflow timer in ms seconds first.
Please use code tag or c syntax when you post code so its easy to read your code and answer fast.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // Timer 0 overflow interrupt service routine //your ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; } // Timer 0 overflow interrupt service routine //modified ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(2000); PORTD.0=0 ; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 /***************************************************** This program was produced by the CodeWizardAVR V2.05.3 Standard Automatic Program Generator © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l. [url]http://www.hpinfotech.com[/url] Project : Version : Date : 12/30/2014 Author : PerTic@n Company : If You Like This Software,Buy It Comments: Chip type : ATmega128 Program type : Application AVR Core Clock frequency: 16.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 1024 *****************************************************/ #include <mega128.h> #include <delay.h> #include <sleep.h> #include <stdint.h> // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isr(void) { MCUCR =0; PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; delay_ms(100); } // Timer 0 overflow interrupt service routine //modified ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(50); PORTD.0=0 ; delay_ms(50); PORTD.0=1 ; delay_ms(50); PORTD.0=0 ; delay_ms(50); } // Declare your global variables here void main(void) { // Declare your local variables here PORTA=0x00; DDRA=0x00; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0x01; PORTE=0x00; DDRE=0x00; PORTF=0x00; DDRF=0x00; DDRG=0x00; // Timer/Counter 0 initialization ASSR=0x00; TCCR0=0x05; TCNT0=0x00; OCR0=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: On // INT1 Mode: Falling Edge EICRA=0x08; EICRB=0x00; EIMSK=0x02; EIFR=0x02; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; ETIMSK=0x00; PORTD.0=1 ; delay_ms(2000); PORTD.0=0 ; delay_ms(2000); // Global enable interrupts #asm("sei") while (1) { ASSR=0b00001000; MCUCR=0b00111000;// Enable sleep mode #asm("sleep"); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // Timer 0 overflow interrupt service routine //your ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(100); PORTD.0=0 ; } // Timer 0 overflow interrupt service routine //modified ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { MCUCR=0; PORTD.0=1 ; delay_ms(2000); PORTD.0=0 ; }
Few things you are controlling the same output with two interrupt and as i posted above there is time delay difference in your two ISR and 100ms less to identify the ISR.
If you use without pre scale then your cpu clock will be your timer clock so try to run the timer slower as I said try to set some time value for overflow timer
One more thing clear MCUCR=0; in while one.And you can use timer in CTC mode.
**broken link removed**
look at above example its not for atmega 128 but i think you can convert it.
My goal is reached
.So I think you set power down sleep mode as i told you to read data sheet page number 45 read the paragraph about power down sleep mode and other sleep mode.only external INT or RESET make CPU wake up.
I know i bothers u so much!
No No my mode is power save. MCUCR=0b00111000;// i read the datasheet. power save wakes up with timer0,Ext int,...
Now the problem is why timer0 does not work correctly at the first time? i think timer works but the overflow does not..
I put a delay_ms (130) after MCUCR in while (1) and the problem solved.
thank you...
can you explain why its running with delay
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?