Skip to main content

Posts

Showing posts from February, 2011

Generating a PWM Signal Based on an Analog Input - mikroC

If you like to experiment with microcontrollers you've probably tried out analog-to-digital conversion and generating PWM signals. Using a popular PIC microcontroller like the 16F877A, which has both ADC and CCP (Capture/Compare/PWM) modules, you can test out both of these easily because mikroC provides easy to use library functions for both of them. (Most of you will be familiar with these libraries, so I won't be going in to much detail about them here. Leave a comment if you like to learn more.. :) ) Now, think of a scenario like this: You want to change the duty cycle of your PWM signal based on a analog signal. It can be from a variable resistor that you want to use to increase or decrease the duty cycle, or it can be a feedback from a sensor which is analog. So, how can we do it?... we simply use the ADC to convert the analog signal and use that value as the duty cycle value. All we need is a microcontroller that has both a CCP and a PWM module. As I said before, the