PWM - pic18f4550 - led + potentiometer (simple project)

Discussion in 'Embedded Systems and Microcontrollers' started by Bellon, Jun 19, 2016.

  1. Bellon

    Thread Starter New Member

    Sep 19, 2015
    Hello. I'm doing my first program with pwm and am encountering some difficulties to do a small project. I want to vary the voltage of an LED as the turning of a potentiometer. However, the examples I found are with PWM own libraries, which I have not. I'm using a PIC18F4550 in MPLAB X.

    If anyone can help me, I will be very grateful.
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1. can you do adc on your chip?
    2. can you do pwm on your chip?

    If you can do both, it is simple to integrate them;

    if you cannot do either, start learning now.
  3. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    If this is your first project, I suggest dividing it into two parts: 1) Setting up PWM to give, say, 40% duty cycle; and 2) Setting up the ADC to digitize your potentiometer output voltage (voltage divider) to control PR2, with which you can set the duty cycle. Do the first part, test it. Then proceed to the second.