I am doing a project on pic16f877A to control dc motor speed control. I am working for the first time with pic microcontrollers . In my project i am generating pwm signals and to generate pwm pic uses timer2 . And i am also using serial communication and i read on google that timer2 is used for UART. so i wanted to know how pwm and uart will work together using single timer. I demonstrated the output on proteus and it works fine.
2 Answers
You shouldn't believe everything you read on Google.
Your first port of call should always be the datasheet. In there it describes exactly how each peripheral works, and even gives you some simple block diagrams to follow so you don't need to understand all the terminology.
For instance, the UART section gives this nice diagram:
You can instantly see that the baud rate, generated by the SPBRG (Serial Port Baud Rate Generator) gets its clock direct from \$F_{OSC}\$ (the OSCillator Frequency) and there is no connection anywhere to any timer peripheral.
So I don't know what you read, or where you read it, but it may have been referring to some completely different chip, or have been written by someone who doesn't actually possess a clue.
"i read on google that timer2 is used for UART". Seriously!!? Design by heresay is not a good technique.
The proper source of information about any electronic device is its datasheet, and this case is no exception. The UART is very well described in the datasheet. It has it's own chapter 10 Addressable Universal Synchronous Asynchronous Receiver Transmitter starting on page 111. Section 10.1 on page 113 goes into great detail on the baud rate generator. There is also a complete diagram of the USART in section 10.2.2 on page 117 that shows, among other things, how the baud rate generator fits into the whole device. There is no dependence on timer 2 described anywhere in that chapter.
Once again, Read the Manual!
-
\$\begingroup\$ Actually I read the data sheet and was sure that timer2 has nothing to do with uart but I got confused with that google stuff \$\endgroup\$– dcmotorMar 17, 2015 at 16:56
and i read on google that timer2 is used for UART
Where exactly did you read that? UART has nothing to do with timers \$\endgroup\$i wanted to know how pwm and uart will work together using single timer
Should work just fine provided you don't use the same pin for the UART rx/tx and the PWM output. \$\endgroup\$