Inverting the o/p of hardware PWM


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104

    Default Inverting the o/p of hardware PWM

    I'm working up a project to use 3 hardware PWM modules. Probably on a 16F777. The PWM signal goes into the signal pin of a LUXEON Buckpuck. The trouble is that that pin thinks 5V is "OFF" and 0V is "ON" for the led. So a 100% duty cycle would have the led off all the time and vice versa for a 0% duty cycle.

    I could just put a line in to subtract my desired duty cycle count from 1024 (if in 10bit mode) and invert it that way, but is there an easier way to just invert the output of the PWM module ?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Short answer ... NO.

    There isn't really a 10-bit mode. Depending on the frequency being used, there may only be 6-7 bits of resolution. Then instead of subtracting from 1024, you'd have to subtract from the maximum resolution.

    If you have PBP2.50 which allows all 3 HPWM's. You could subtract from 255, because the HPWM command always scales it to the available resolution.

    It could be done by modifying the Library, but you probably don't want to go there.

    There's always the 74HC04.
    <br>
    DT

  3. #3
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel, it's only a couple of extra lines of code so not too difficult. 3 PWM modules - perhaps I wasn't being clear, I didn't mean three times HPWM, but using the three different embedded PWM modules in a PIC such as 16F777 and addressing them directly.

    Andrew

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by AndrewC
    perhaps I wasn't being clear, I didn't mean three times HPWM, but using the three different embedded PWM modules in a PIC such as 16F777 and addressing them directly
    Yikes,

    Then maybe my answer wasn't clear either, cause that's what I was talking about as well.

    I could be more specific, if you were too.

    What frequency are you running the PWM at?
    What OSC?
    Which version of PBP?
    PM or MPASM?
    <br>
    DT

  5. #5
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Basically following Bruce's example in this thread:

    http://www.picbasic.co.uk/forum/showthread.php?t=1770

    PBP: 2.46
    20MHz
    MPASM

    Hopefully I'm not missing something obvious - it has happened before and will doubtless happen again A 16F777 has 3 PWM modules and I'll control them directly.

    thanks, Andrew

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    AndrewC, Why not just use a transistor and a couple of resistors?

    Dave Purola,
    N8NTA

  7. #7
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dave View Post
    AndrewC, Why not just use a transistor and a couple of resistors?

    Dave Purola,
    N8NTA
    To invert the signal or drive the leds ? These are Luxeon leds running at high power. They work best on constant current sources and buckpuks are great for driving them.

    If I can do it with a simple line of code why add external parts ? Actually, my led drivers only go up to 1000mA and my leds can take 1500mA so I may just make my own constant current drivers (two transistors and a couple of resistors per channel) in which case 5V will be ON This particular project is for lighting a macrophotography stage - while focussing / adjusting I use the leds at constant low power but for actual exposures switch to a single high power pulse. Three channels for left, right and backlight.

  8. #8
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    AndrewC, I dont know what constant current has to do with inverting the control signal?

    Dave Purola,
    N8NTA

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Question (maybe more of a comment) concerning taking pictures and using PWM to drive LEDs for lighting...

    Won't your PWM frequency have to be REALLY high to keep the camera's shutter from seeing the flickering?
    LEDs, unlike incandescent light bulbs, can actually turn on and off at those high speeds, whereas an incandescent light bulb will glow during the off time.
    I'm thinking that even with a really fast shutter on a camera, the film (or CCD, or whatever) is going to see that 'flickering' caused by the PWM driven LEDs.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by AndrewC View Post
    Hi Darrel,
    Basically following Bruce's example in this thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=1770
    Oh,OK.
    According to that, it's running the PWM at the absolute minimum frequency, which gives exactly 10-bit resolution.

    From you're last post I see that it's not continuously changing the dutycycle. So I don't need to talk about "glitch-free" either.

    So it looks like your original idea from post #1 is the way to go, with 1 exception.
    Subtract from 1023 instead of 1024.
    <br>
    DT

  11. #11
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Question (maybe more of a comment) concerning taking pictures and using PWM to drive LEDs for lighting...

    Won't your PWM frequency have to be REALLY high to keep the camera's shutter from seeing the flickering?
    LEDs, unlike incandescent light bulbs, can actually turn on and off at those high speeds, whereas an incandescent light bulb will glow during the off time.
    I'm thinking that even with a really fast shutter on a camera, the film (or CCD, or whatever) is going to see that 'flickering' caused by the PWM driven LEDs.
    Well you know the bit where I say "but for actual exposures switch to a single high power pulse" ....... Actually if you have an exposure time longer than say 10 PWM cycles it wouldn't matter. The advantage of a single high power flash is to freeze motion.

    Dave: the point being that if I stick with the OEM drivers I have, I need to invert the signal. If I make my own constant current sources I don't need to invert the signal but need to add some extra components - so the choice is to add some components to invert the signal, or add some components so as not to have to invert the signal. Or I was hoping to find a magic instruction that inverted a PIC o/p pin.

    Darrel: 1023 - you know I keep missing zeroes Same happens with registers, I keep thinking Pin1 or Bit1 is the first one. Duh !

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. Hardware PWM Question?
    By jhorsburgh in forum General
    Replies: 1
    Last Post: - 18th August 2008, 03:07
  3. PWM: Vernacular/Function (Newbee)
    By TerryN in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd July 2008, 16:58
  4. 3 Hardware PWM.
    By sirvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th January 2008, 12:21
  5. pics with 3 hardware PWM ports
    By CBUK in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th August 2004, 00:14

Members who have read this thread : 1

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