Connect with us

PWM - pic18f4550 - led + potentiometer

Discussion in 'Microcontrollers, Programming and IoT' started by Bellon, Jun 19, 2016.

  1. Bellon

    Bellon

    10
    0
    Sep 20, 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. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Hello, what do you mean with PWM own libraries?
    Adam
     
  3. Bellon

    Bellon

    10
    0
    Sep 20, 2015
    A library file (header):
    #include <pwm.h>
     
  4. Bellon

    Bellon

    10
    0
    Sep 20, 2015
    The "Library Routines" are these (available in MikroC):
    PWM1_Init
    PWM1_Set_Duty
    PWM1_Start
    PWM1_Stop

    I can use these in MikroC but do not know what to use to program the MPLAB.
     
  5. hevans1944

    hevans1944 Hop - AC8NS

    4,203
    1,990
    Jun 21, 2012
    @Bellon do you want to program the PIC using C or assembler?
     
  6. Bellon

    Bellon

    10
    0
    Sep 20, 2015
    Using C
     
  7. hevans1944

    hevans1944 Hop - AC8NS

    4,203
    1,990
    Jun 21, 2012
    I don't do C much, but there should be a way to import those libraries into MPLAB. Try asking on the Microchip MPLAB XC8 forum. Might want to look at some of the links here too.
     
    Arouse1973 likes this.
  8. smitthhyy

    smitthhyy

    11
    0
    Apr 16, 2013
    I'd suggest having a look at this response to a similar question http://www.microchip.com/forums/m295647.aspx#328482 on the Microchip forum. It includes some C code for using PWM to contol the intensity of LED's.

    Source: Google search. Affiliation: None, found using google.
     
  9. Amar Dhore

    Amar Dhore

    129
    12
    Dec 2, 2015
    Assuming you are using 8 bit micro,

    For MPLAB, you can go through this Microchip's wiki: http://microchip.wikidot.com/8bit:10bitpwm
    or if you have MPLAB with Harmony, you can generate code using Harmony configurator or use the Harmony example code.
     
  10. pgib8

    pgib8

    99
    22
    Jul 26, 2015
    Forget the library, just write your own code. You will learn so much more, or do you want to be one of these people that do such exciting projects they talk about but in reality they just used a bunch of libraries and copy and pasted some code from the internet?

    setting up the PWM should take you maybe an hour or two.
    setting up the ADC to read the potentiomenter, probably 30 minutes.
    tweaking some numbers, maybe another hour.
    that's a very conservative estimate, in other words you can do it.
    i myself could do the whole thing in probably 15 minutes or less. finding the right libraries and learning how to use them would actually take me longer... just some thoughts.
     
    hevans1944 likes this.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-