![]() ![]() The base frequency of microcontroller in Arduino UNO is defined as So pin 5 and pin 6 can be set to one frequency, pin 9 and 10 can be set to another different frequency and pin 11 and pin 3 can be set to another different frequency. Arduino pin 5 and 6 are controlled by register TCCR0B, pin 9 and 10 are controlled by TCCR1B and pin 11 and 3 are controlled by TCCR2B. There are 3 counter/timer registers in which pre-scaler bits are set and these are named TCCR0B, TCCR1B, and TCCR2B. These 3 bits of pre-scaler are denoted by CS02, CS01, and CS00. The value of the pre-scaler consists of 3 bits and is stored in the three least significant bits of the timer/counter register. The speed of the counter clock is obtained by dividing system clock speed with pre-scaler value. The frequency of a PWM signal is controlled by the clock rate of the counter. Moreover, on-time of the output signal is almost 1.01ms which is 50% of the total width of the signal. The 2.02ms time period is approximately equal to 490Hz frequency. Program OuputĪs you can see in the output diagram below, the time period of the output waveform is almost 2.02ms. The PWM function width parameter read from value 0 to 255, Value 0 will represent completely OFF waveform and 255 represent completely ON Waveform. The mapping between the duty cycle and number 127 can be understood as follows. Here pin3 will generate a PWM with a 50% duty cycle and default frequency of 480Hz as described above. PinMode(PWM_Pin,OUTPUT) /*declare D3 pin as an output pin */ĪnalogWrite(PWM_Pin,127) /* Produce 50% duty cycle PWM on D3 */ int PWM_Pin = 3 /* give PWM_Pin name to D3 pin */ This code generates a 490Hz and 50% duty cycle signal on the D3 pin. The following code generates a fixed frequency and fixed duty cycle waveform on the D3 pin of Arduino Uno. In this section, let’s discuss to generate a fixed frequency PWM using the D3 pin of Arduino Uno.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |