ATmega32/16 PWM tutorial
http://aquaticus.info/pwm
P.S.
Not sure links allowed here
ATmega32/16 PWM tutorial
http://aquaticus.info/pwm
P.S.
Not sure links allowed here
Not sure links allowed here
Looks like a really nice guide, I'll have to bookmark it now and use it later when I have a project that uses PWM.
good post, reinforced info i nneded for my project! thanks!
thx dude,
thank you
Thankyou for a great guide. This is one of the best guides on PWM or any other AVR subject I have seen. I loved the layout so easy to follow and understand the maths, also the example figures where good too, and the code examples where good and covered a wide application for PWM useage.
Awesome 10/10
Rich
tuts for usin timer?
plz help me
tuts for usin timer?
plz help me
Nevermind. Just open your mouth, and you will be fed:
Quote:
tuts for usin timer?
plz help me
Oh dear. This has got to be one of the most clueless posts here this year. Did you even bother to go through the different threads here in the Tutorials forum?Nevermind. Just open your mouth, and you will be fed:
Smiley
is there a good guide/tutorial on soft pwm?
is there a good guide/tutorial on soft pwm?
https://www.avrfreaks.net/index.p...
That simply uses an overflow and a compare interrupt. The overflow sets the PWM frequency and the compare sets the duty cycle.
hi guys i need ur help in program timer0 atmega8 please can any one help me out in that :(
Please start your own thread for this kind of question (and in the correct forum). And we will need a heck of a lot more information if you want us to answer.
And we will start by pointing to the timer tutorial in the Tutorials forum. This is something that you can locate yourself with minimum effort, and read for a good start on timers.
ya i am just a beginner of avr i had enough pdf's on atmega8 and now even i had brought a new text book on avr but i am unluckey the author had explained the avr using ATmega16 i am loading the all timer registers with proper value here is my code for generating a square wave on portc pls check this out n help me if there is any fault in that
#includevoid main (void) { DDRC = 0x0ff;//setting portc as output port while(1) { PORTC=~PORTC; //turning on timer with no prescalar TCCR0=0x01; TCNT= 0;//initializing count while(TIFR==0);//checking for over flow TIFR=0x01;//making tovo to 0 TCCR0=00; } }
and this is the program which i had used in avr studio4
#includevoid main (void) { DDRC = 0x0ff;//setting portc as output port while(1) { PORTC=~PORTC; //turning on timer with no prescalar TCCR0=0x01; TCNT= 0;//initializing count while(TIFR==0);//checking for over flow TIFR=0x01;//making tovo to 0 TCCR0=00; } }
thanking u sir mr.JohanEkdahl &mr.Koshchi
But you haven't said what the problem is?
(I also edited [code] tags into your posts and fixed the indentation - please get into the habit of doing this yourself in future)
[But you haven't said what the problem is? ]
yes sir i got you and sorry for not mentioning the problem the code i have written is for generating 1 to 2 kHz square wave approximately but i am getting nearly 100 kHz wave here i am using the internal oscillator of 1 MHz for that it have to generate 1 to 2 kHz wave but it is not condition i don't know whats wrong in my code what do u suggest for this problem sir i hope you can solve my problem sir thanking u Mr.clawson
with best regards
Harish.G
@harish_spt: You need to fix your keyboard. It frequently drops characters (particularly punctuation characters). There are also serious problems with your shift key.
while(TIFR==0);//checking for over flow TIFR=0x01;//making tovo to 0
How exactly do you think that these two lines of cod work? Be very specific, talk me through what you think is going on in the mcu here. Be warned here: if you haven't fixed your keyboard problem, I'm not likely to bother reading your answer.
@Koshchi: sir, apologies:-)
I am actually trying to generate a square wave of freq = 1kHz on the AVR ATMEGA8 microcontroller. The code which I have sent you is for the same.
When I built the program it showed 0 errors and 0 warnings
However while simulating the Timer_Counter (TCNT0) is incrementing by 7 instead of 1 for every clock cycle.
I use the polling method to check if the flag 't0v0' flag is raised which is housed in the register 'TIFR'.
If it happens to be raised we break the while loop and
write the value 0x01 to the register TIFR(that way the 't0v0' bit is cleared).
Also is there any problem with the compiler I use(AVR studio4 v 4.13)?
However while simulating the Timer_Counter (TCNT0) is incrementing by 7 instead of 1 for every clock cycle.
@clawson: sir yes then according to you if it was taking 7 cycles for execution then it should generate the square wave correctly in mcu but it is not the case. i am getting nearly 100khz. and i don't know how to use c+ASM can you please help me out in this or else can please send me the code for other timers can you help me out in this please :(
When I correct the TCNT=0 in your post above then build/simulate the code for mega8 with a breakpoint on the PORTC=~PORTC line the breakpoint is hit at 148 cycles then 416 cycles, then 684, 952, 1220. So the output is switching every 268 CPU cycles. On 1MHz where one cycle is 1us this means the output toggles every 268us and a complete on/off cycle lasts 536us. So the output should be 1,865.67Hz. If the CPU is running faster than 1MHz then scale this accordingly. For example on 8MHz the output would be 14,925Hz (14.925kHz).
In this program, while it's blocking on the "while (TIFR=0);" line the TCNT0 is increasing by 4 for each step. When you look at the underlying code it is:
while(TIFR==0);//checking for over flow 58: 88 b7 in r24, 0x38 ; 56 5a: 88 23 and r24, r24 5c: e9 f3 breq .-6 ; 0x58
where IN is 1 cycle, AND is 1 cycle and BREQ is 2 cycles while the result is 0. So it's 1+1+2=4 cycles as was observed.
To step the opcodes rather than the C use "Disassembler" on the "View" menu. Now when you step it steps one opcode, rather than one whole C statement at a time.
Cliff
@clawson:
sir,please apologies me and don't mistake me i am just a beginner cani know how can i disassemble the c file in avr studio please and as per u it should increment 4 steps at a time but it is incrementing by 7
hi :) i got the output finally for which i was struggling and i got the out put through another software called code version avr there i used interrupt method to clear the flag and i don't know how to polling in this can any one help me in this by giving a sample code of c source and i am using internal clock of 1MHz and i want to shift it to 4 MHz can you please help me
Still haven't fixed your keyboard? I'm sure that there is a question in there somewhere, but without proper punctuation and capitalization, I'm not even going to try to decipher it.
The PWM link in the first post seems to be dead.
getting "Unable to connect to database" error.
Any chance of getting an updated link?
Ok i will fix my key board problem. now i am working on serial communication.can u please send me some example programs or links for that.
Ok i will fix my key board problem. now i am working on serial communication.can u please send me some example programs or links for that.
Eg should I locate the UART tutorial here for you? It only takes a few seconds, but if you've already read it I fear that you might be irritated for getting links that are of little value for you.
@JohanEkdahl:
No sir i am not irritated the work i had done on usart is i had configured the usart in asynchronous mode with 9600 baud rate. i don't what's the problem in the program. that i am not getting the output. Please i request you to send some example c code for both transmission and reception or send me the link where i can get the code
or send me the link where i can get the code
@JohanEkdahl
Ya sir i had checked those those programs support avr studio but i am working with code vision avr.But the code vision avr does not support this type of instruction. Which are mentioned below
[ UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); /]
}
while (x==0);
UCSRA = 0x40;
};
/* Put data into buffer, sends the data */
};
}]
But the code vision avr does not support this type of instruction. Which are mentioned below[ UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); /]
Funny. I was fairly convinced that CodeVision was compliant with C standards. What are the compilation errors you get?
It might that CodeVision does not have the defines for the bit numbers, but they can either be generated or you can supply them.
It might that CodeVision does not have the defines for the bit numbers, but they can either be generated or you can supply them.
ATmega32/16 PWM tutorial
http://aquaticus.info/pwmP.S.
Not sure links allowed here
nice tutorial! i'm late but thanks:) i was busy making stuff!
BTW, it would be nice if you added how to choose resolution! i found out at datasheet :)