Title: Problem in AVR Programming Post by: wellnerson1 on October 22, 2008, 03:41:32 15:41 Let me know any one of this ever glittering forum that "how to set and clear the timer overflow flags in AVR mega16 processor during run time?" ??? please.
Title: Re: Problem in AVR Programming Post by: cluoiset on October 22, 2008, 09:43:58 21:43 TIMSK = (1<<OCIE1A)
I think Title: Re: Problem in AVR Programming Post by: Belgitaes on October 24, 2008, 08:30:38 08:30 set and clear the timer overflow flags in AVR mega16
with AVRSTUDIO Code: ;------------------------------------------------------ http://rapidshare.com/files/157022595/set_and_clear_the_timer_overflow.zip.html Title: Re: Problem in AVR Programming Post by: wellnerson1 on October 25, 2008, 04:41:23 04:41 That’s greatly appreciated cluoiset and Belgitaes. But I’m interested in manipulating the bits in TIFR register in ATMEL mega16 which is meant for clearing and setting the corresponding flags, during run time. In my attempts I tried to manipulate using logical operation with the register TIFR, but during execution the flag bits failed to update and the same results I got in my experiment also. Help sought for in this context. ??? Thanks in advance ;).
Title: Re: Problem in AVR Programming Post by: Belgitaes on October 27, 2008, 09:09:51 09:09 TIMSK = (1<<OCIE1A)
COMPA Timer/Counter1 Compare Match A Code: ;------------------------------------------------------ OCIE1A Timer/Counter1, Output Compare A Match Interrupt Enable When the bit is 1 the interruption is validated for Timer/Counter1 and OCF1A bit is changed in the registry TIFR TOIE0 Timer/Counter0 Overflow Interrupt Enable When the bit is 1 interruption is validated and the Timer/Counter0 bit TOV0 is amended in the register TIFR. Title: Re: Problem in AVR Programming Post by: sam_des on October 29, 2008, 10:40:06 10:40 Hi,
You can't manipulate the interrupt flags as you can do with other processors. Remember that the interrtupt flag is SET when interrupt occurrs & you have to write ONE to it WIHTOUT use of logical operators to clear it. e.g. If TIMER1 has interrupted with Compare Match 1 then OCF1A flag will be SET. To clear it you must write 1 to it - TIFR = (1<<OCF1A) and not TIFR |= (1<<OCF1A) nor TIFR &= ~(1<<OCF1A). This way it is ensured that no other bits in same registers are modified incorrectly. If you have defined ISR for your interrupt then AVR will automatically clear flag once ISR is executed(There are few exceptions such as TWI). As AVR has load-store architecture any logic operation will require 3 instructions atleast - load, modify, store. This may affect other bits in same register if they are modified in between these instrucitons. BTW, I don't get your point of manipulating interrupt flags. Why do you need it ? If you provide more details may be we can find out other ways.. regards, sam_des Title: Re: Problem in AVR Programming Post by: wellnerson1 on March 09, 2009, 12:12:15 12:12 As i forget the problem for which i thought the bit manipulation TIFR sorry dear sam_des? If it comes in my mind i will let you know.
More over right now i have a problem please let me clarify is it true?? The Problem is:- I made PORTB as output port in my program and while the AVR startes executing the program all the pins of PORTB becomes HIGH state for approximately 5 to 25 micro seconds and then works as i wish. sometimes even i coudnt capture the duration of HIGH state with my TEK OSC, iam totally confused. Anybody suggest whether it will cause any problem in firing high power inverters? Title: Re: Problem in AVR Programming Post by: sam_des on March 09, 2009, 06:39:49 18:39 Hi,
Quote As i forget the problem for which i thought the bit manipulation TIFR sorry dear sam_des? If it comes in my mind i will let you know. Don't worry. It happens all the time to all of us :PQuote The Problem is:- I made PORTB as output port in my program and while the AVR startes executing the program all the pins of PORTB becomes HIGH state for approximately 5 to 25 micro seconds and then works as i wish. sometimes even i coudnt capture the duration of HIGH state with my TEK OSC, iam totally confused. Anybody suggest whether it will cause any problem in firing high power inverters? Check the datasheet :-\ But if you don't want to -- 1) All the ports are tri-stated(high z) during the RESET. That's why when you try to check them, they can in any state. Even your DMM or oscilloscope probe may change it's state. 2) There is in-built power-on delay after reset to allow power & clock to stabilize. You select how much this delay is when you program the fuses. 3) If you are writing your software in C, then after reset, c0 module gets control, which intializes the data/return stacks, zeros entire ram, intializes static vars from rom and many other things. That just indicates that your code initializing PORTB as output executes much later than you imagin. Well there might be problems with power inverters, if this causes simultaneous turn-on of full/half bridge leg or push pull >:( Solution is simple one- 1) Use pull-down resistors on these pins or 2) Use a driving logic/driver that is active-low to drive mosfet. regards, sam_des Title: Re: Problem in AVR Programming Post by: wellnerson1 on March 10, 2009, 11:40:33 11:40 I thank you profusely dear friend SAM_DES, for your solutions. I have followed your solution but with little modification as 1) i've used the internal pull up instead of external (thanks for remembering me the pull up/down concepts) 2) i've followed your second solution as such now its perfectely OK.
By the way sam_des the foot note of your posting is absolutely motivating and giving a new dimension to hardwork. With regards, :D ;) |