pot controlled pwm -- help


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jan 2006
    Posts
    76

    Thumbs down pot controlled pwm -- help

    greetings, I am a novice at the whole pic thing. I hope to change that with many experiments and networking with people like you guys.

    anyway, I am trying to control a PWM with a 10k pot. It is for controlling the dimming of an LED driver. I have the pot hooked up correctly and am getting proper readings. I am using the pot command to read. Given that this gives me a number from 0-255, it seemed perfect to set a variable and plug it right into the hpwm command. I then let it loop, looking for changes in the pot. The drivers frequency is 10khz and outputs current to the led when the pin goes low.
    Unfortunately what I get is a very erratic blink that really has no continuity with the pot being adjusted. Any ideas?

    here is the code, remember, Im an extreme beginner.

    ----------------------------------
    define OSC 8
    v1 var byte 'Variable v1 holds pot information

    high portc.2
    pause 100
    High portd.2 'power indicator

    main:
    pot portd.1,23,v1 'Read resistance of pot
    Hpwm 1, v1, 10000 'hardware pwm on RC2
    pause 100
    goto main


    End
    -------------------------------

    as for hardware, I am using a buckpuck made by luxdrive. It is a 1 amp LED driver that gives a regulated 5v reference for microcontroller power, it also has a control return which I hooked the pwm out pin (RC2/CCP1) to. I have an led indicating the chip is on & running. I also have a 10k pot with capacitor for the dimming adjustment. MCLR is pulled up with a 4.7k. I am also running an 8mhz crystal with two caps.

    thanks in advance for your feedback.

  2. #2
    Join Date
    Oct 2005
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    what pic do you use ?

    sample for 16f876:

    TRISA = 255 ' Set PORTA als input
    ADCON1 = 0
    define OSC 8
    DEFINE ADC_BITS 8 ' adc = 8 bits

    v1 var byte 'Variable v1 holds pot information

    high portc.2
    pause 100
    High portd.2 'power indicator

    main:

    adcin 0,v1 'Read resistance of pot
    pause 10
    Hpwm 1, v1, 10000 'hardware pwm on RC2

    goto main


    End

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Angry Pot command

    Hi,DOC

    Forget the POT command ... it gives more headaches than anything Else. @ 4 Mhz only, you can hope for something

    the RC Time command ... ( see manual ) works perfectly for such input readings.
    you'll just have do divide the result by 256.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Cool

    Also, don't forget that your V1 variable as "byte" holds values upto 255 just as "pot" command does.

    However, when you use a scale less then 255, which is 23 in your code, after 23 you still get V1 as a value bigger then 23.

    Use an LCD just to see how the values in your scale do not match with the variable you are using to hold the pulse value.

    To avoid this problem, you should use a check module like an IF statement.
    Ex: IF V1 > 23 then V1=23

    You should have already realized that after you get the value of your scale (23), your 10K pot does not respond accurately since the reading value now is much bigger then 23.

  5. #5
    Join Date
    Jan 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    thank you all for your help so far. to answer the first question, I am using the 16F877A. It wont be the chip that I will actually use for this item when I finally have a finished board, but it is feature rich and good for prototyping.

    maus: I will give your code changes a shot. my main reason for using pot was I get a value from 0-255, the same as the input for hpwm, so no conversion necessary. what kind of values do you get from the adcin? I havent found any documentation that has answered this question thus far.


    Acetronics: thanks for the input as well, it looks like the pot command is going out the window. Ill read up on the RC command

    sayzer: I thought the scale was an adjustment for setting the pot's upper limit? I used a counter program that read the pot with an if then statement and blinked an LED equal to the scale amount, this is where 23 came from.

    thanks again for all your help. I will probably be able to test some of these things tonight after work.


    included is a schematic, it also may be crude, its my first time using the schematic software.
    Attached Images Attached Images  
    Last edited by docwisdom; - 25th January 2006 at 17:44.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As you use a 16F877, why spending time and extra capacitor when life can be sooo much easier by using internal ADC on PORTA?

    Look for ADCIN in the PBP manual and Section 11 of the datasheet.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jan 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by maus
    what pic do you use ?

    sample for 16f876:

    TRISA = 255 ' Set PORTA als input
    ADCON1 = 0
    define OSC 8
    DEFINE ADC_BITS 8 ' adc = 8 bits

    v1 var byte 'Variable v1 holds pot information

    high portc.2
    pause 100
    High portd.2 'power indicator

    main:

    adcin 0,v1 'Read resistance of pot
    pause 10
    Hpwm 1, v1, 10000 'hardware pwm on RC2

    goto main


    End

    thanks for this code, but doesnt this base itself on the ADCIN producing a number from 0-255 to feed to the hpwm? I have made these changes and the LED's just stay on, even with adjustment of the pot. I dont think the variable output from the adcin is properly formatted for the hpwm

    does anyone know how this is formatted? I cant find any documentation on it.

  8. #8
    Join Date
    Jan 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default update

    So I gave up on the pot for now and just set a pwm to go to the driver.

    hpwm 1, 127, 5000

    I get 50% duty with a regular LED, but it doesnt work properly with the LED driver
    Last edited by docwisdom; - 26th January 2006 at 06:09.

  9. #9
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Cool

    Try the attached PWM filter.
    Play with the driver resistor and the load resistor to catch a nice signal out.

    If you already have a signal amplifier, the NPN transistor may not be necessary.
    Attached Images Attached Images  

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Thumbs down ON/OFF vs PWM

    Hi, Sayzer

    PWM is intended to know what you apply to your load, your design is very very very very far from giving a known output ... it's more an ON/OFF output than anything else.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    I don't really care for the HPWM command. I think it's easier to manually set the registers. This is a conversion from part of my code that may work for you to at least get the PWM working.

    This is for an 8MHz oscillator (on a 18F2525, so double check register names):

    T2CON = 4 'Timer2 = ON; Prescale = 1:1
    PR2 = 200 '(period) this should give you should give you about 10KHz
    CCPR1L = 100 '(duty cycle) 100 should be close to 50%, 20 is about 10%, etc

    To turn PWM ON:
    CCP1CON = 12

    To turn PWM OFF:
    CCP1CON = 0
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  12. #12
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Cool

    Hi Acetronics,

    PWM filter is not something I created through my output port; it is what picbasic pro recommends.
    If you check the manual or help files, you will find this filter as a solution to scarry pwm out. Still, it is optional.

    If you know something else, pls share it with us so that we can learn. Also, PWM is already an on/off state with different intervals on ON mode, on OFF mode etc. and this is called "modulation".

  13. #13
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking The Missing resistor ...

    Hi, sayzer

    As you're asking, it's a pleasure ...

    Just insert a resistor between your Emitter and ground, and the transistor collector current will simply follow linearly ( w. a little offset due to Vbe ...) the PWM value ...
    An U/I converter w/ OpAmp could wipe off this offset, if needed ...

    No, no, don't send flowers ....

    Alain
    Last edited by Acetronics2; - 29th January 2006 at 12:33.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. Serial controlled PWM
    By The Master in forum Off Topic
    Replies: 1
    Last Post: - 26th November 2007, 06:47
  4. Replies: 4
    Last Post: - 24th January 2007, 22:20
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts