pot controlled pwm -- help


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    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.

  2. #2
    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.

  3. #3
    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  

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


    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 " !!!
    *****************************************

  5. #5
    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

  6. #6
    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".

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


    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