![]() Let’s say we want a 1kHz frequency from the formula the value for the TOP(which is OCR1A) is 8000, but with that value on oscilloscope appear only 500Hz, so for 1kHz signal we use a value for TOP quals with 4000. In this mode because of the dual slope particularity the frequency is half the frequency obtain from the formula f OCnx=f clk/2*N*TOP, where the TOP is the OCR1A value The result for this program is in the image below: put your main code here, to run repeatedly TCCR1B=0b00010001 //WGM13 is 1 and WGM12 is 0 with no prescaler CS10 is 1 The program is(for example OCR1A=128 and no prescaler): So OCR1A0,OCR1B0 are 1, OCR1A1,OCR1B1 are 0 and WGM13,WGM11, WGM10 are 1 and WGM12 are 0(mode 11 in image) with no prescaler: With examples we start with this final combination of COM1A0 and COM1B0, both 1, because in the waveform generation mode bit description image has only two situation for phase correct pwm: In this case the TOP value take the OCR1A value(it can be between 5).īefore examples we must say that the modes which TOP is equal with ICR1 will not be studied in this post because are particular cases(can work with external signals). If the COM1A0 and COM1B0 are 1 that means OC1B is diconnected(pin 10), and pin 9(OC1A) will generate a pwm signal wich frequency is dependent by OCR1A. ![]() If all four bits are 1 we have the situation from previos case with the difference that he signal is inverted(the pin is set high on upcounting and low when downcounting) If COM1A1 and COM1B1 are 1 that means we generate a signal which frequency is given by the formula f OCnx=f clk/2*N*TOP, where f clk=16000000Hz, N is the prescaler(given by the CS12,CS11 and CS10 from the TCCR1B register-explain later) and TOP takes the value from the waveform generation mode bit description image(multiple situations). ![]() In the picture below we see the modes of this bits(picture from atmega datasheet):įrom these picture if we have all four bits 0 the pins are disconected-not work If in the fast pwm mode we have a counter which is only upcounting and the duty cycle can be adjust only on a half of the triangle signal in this mode the value of the duty cycle is copied also on the other half of the triangle and the signal is preserved more than in the fast pwm mode, so you can adjust much better the signal, higher resolution, but at a low frequency.įor Timer 1 the fast pwm mode is like for timer 0 but with other posibile frequencies because we have the modes with 9 and 10 bits.Īs you can see the pin is put in high state when the counter is downcounting and in the low state when it is upcounting in non-inverted mode.įirst let’s see the TCCR1A and the TCCR1B registers and the bit description for phase correct mode in the images below(from atmega datasheet):īefore to choose one of these modes in TCCR1A register are four bits COM1A1,COM1A0,COM1B1 and COM1B0 which controls the pins 9(COM1A) and 10(COM1B). This mode has half of fast pwm mode frequency.It is preferred in motors control(pictures from atmega datasheet). In this mode Timer 1 count from a BOTTOM value to a TOP(which can be max in top of the triangle signal or set by OCRnx) value after that it not overflow it countdown from TOP value to BOTTOM value and repeat(triangle wave). Next we will take Timer 1 and put it in the phase correct pwm mode. – OCR1A and OCR1B registers with bits for the duty cycle of the PWM signals for pin 9(OCR1A) and pin 10(OCR1B) – TCCR1B it has the bits needed to choose the prescaler and the other two bits neded to choose the mode of PWM – TCCR1A it has two of four bits needed to choose the mode of the PWM(fast pwm ,phase correct pwm etc) and the bits who manage the mode to set pins high or low Let’s talk about Timer 1 a little! As we mentioned in the previos post Timer 1 manage pins 9 and 10 and for that we must work with some specific registers like: This thing means that Timer 1 has a higher resolution or it can count longer. The main difference between Timer 1 and Timer 0 or Timer 2 is that it is a 16 bits timer(instead 8 bits the others) so Timer 1 can count up to 65355 insteat to 255. ![]() If you like the article click the follow button from social media to stay in touch with us! Please let us in the comment zone any suggestions that you think will improve the article!
0 Comments
Leave a Reply. |