PWM conflict


Closed Thread
Results 1 to 8 of 8

Thread: PWM conflict

  1. #1
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78

    Question PWM conflict

    I have read the PWM listing that was posted earlier this month and have considered that in my code. I am trying to imitate the fading and slowly turning on effect using pbp using SOFTWARE PWM because the PIC that I am using does not have a HARDWARE PWM. I am running my PIC at 20Mhz. please help.. any advise is greatly appreciated... here is what I am doing....

    ==== program starts here====
    include "modedefs.bas"
    Duty VAR WORD
    Cycle0 VAR BYTE
    Cycle1 VAR BYTE
    LED1 VAR PORTB.4
    LED2 VAR PORTB.5
    TRISB = %00000000

    'How long it will take for the PWM to occur
    Cycle0 = 10
    Cycle1 = 10

    'Turns Off the LEDS SLOWLY
    For Duty = 255 to 0 Step -1 'going from ON to OFF state.
    PWM LED1, Duty, Cycle4 'sends a string of pulses
    PWM LED2, Duty, Cycle5 'sends a string of pulses
    Next Duty
    'Turns On the LEDS SLOWLY
    For Duty = 0 to 255 'Going from OFF to ON STATE
    PWM LED1, Duty, Cycle0 'sends a string of pulses
    PWM LED2, Duty, Cycle1 'sends a string of pulses
    Next Duty
    GoTo start

    ==========program ends here=====

    I am seeing the flickering of the LEDs instead of a smooth fading effect that I am suppose to see. I have read the manual and it says that the duty needs to be from 0 (0%) to 255(100%) I am not seeing the gradual fluctuation in the intensity of the light, but instead I see the LEDs flicker on and off very fast, with the same intensity when they are on. Any help with what I am doing wrong is greatly appreciated. Thanks in Advance

    Srigopal

  2. #2
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    ohh I forgot to include the
    Cycle4 VAR Byte
    Cycle5 VAR Byte
    .
    .
    .

    cycle4 = 10
    cycle5 = 10

    in the code that I posted ...

  3. #3
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Srig,

    Srig>>I have read the PWM listing that was posted earlier this month and have considered that in my code. I am trying to imitate the fading and slowly turning on effect using pbp using SOFTWARE PWM because the PIC that I am using does not have a HARDWARE PWM. I am running my PIC at 20Mhz. please help.. any advise is greatly appreciated... here is what I am doing....<<

    Ok, I will up load my Homemade PWM to you as soon as I get home tonight... It is already tested and working. Can be used on any output pin you want.

    One other thing... A Software PWM is different than a Hardware PWM. A Hardware PWM is continous...your chip can be doing things while your PWM is outputting. On a Software PWM, this is not so... You have to complete your PWM before moving on to the next phase of your program.

    I notice you are switching between two diodes... in the *middle* of your homemade PWM.... that could be a problem, and could explain your "Flickering". I did not sort through your code, I just noticed this.

    Dwayne
    Last edited by Dwayne; - 31st August 2004 at 21:02.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  4. #4
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default PWM

    Hi Dwayne, Thanks for your reply. Here is the thing. when I only try to control one of the LED with PWM to turns it on and off smoothly and the program works fine.. but when I try to control two of them at the same time.. I am noticing flickering and not getting what I wanted. I dont know why this is the case. I konw I have the code fine with compliance with PBP. Can anyone help me with some answers.. thanksss in advance


    srigopal

  5. #5
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Srig,

    Srig>>Hi Dwayne, Thanks for your reply. Here is the thing. when I only try to control one of the LED with PWM to turns it on and off smoothly and the program works fine.. but when I try to control two of them at the same time.. I am noticing flickering and not getting what I wanted. I dont know why this is the case. I konw I have the code fine with compliance with PBP. Can anyone help me with some answers.. thanksss in <<

    Ok, this explains everything.... Remember when I said in a Software PWM, you must wait until the entire command is done? What you are doing, is switching between two LED's and because of the time it takes to switch, you are getting this "Flickering" effect. In other words the Software PWM can Probably only handle 1 LCD at a time on the "Fade" effect.

    If you had a hardware PWM, you would have no probems at all. Hardware PWMS operate continuosly, while your chip does other things. Thus, while your chip is switching loops, Jumping around in the program, your PWM is still outputting a continuous stream of Pulses. (Software PWM can't do this).

    You *may* be able to adjust your "Cycle" to make the "Flickering" less noticeable", but between your Duty Cycle and your Cycling, it may be difficult to remove this "Flicker" to the eye using two LCD's... and the problem compounds itself, the more Pins you use to simulate a Software PWM...

    Dwayne

    Dwayne
    Last edited by Dwayne; - 31st August 2004 at 21:52.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  6. #6
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Srig,

    here is the code:

    @ DEVICE PIC12F675,INTRC_OSC_NOCLKOUT,WDT_ON,PWRT_OFF,BOD_O N,PROTECT_OFF,CPD_OFF,MCLR_OFF
    ANSEL=%00000000
    CMCON=%00010111
    TRISIO=%00011000
    ADCON0=%00000000
    Counter var word
    Counter2 var byte
    Loop:
    For Counter=0 to 250
    For Counter2=0 to 150
    GPIO.1=1
    Pauseus Counter
    GPIO.1=0
    pauseus 250-Counter
    Next Counter2
    Next counter
    GPIO.0=1
    pause 1000
    GPIO.0=0
    Goto Loop
    end
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  7. #7
    RossW's Avatar
    RossW Guest


    Did you find this post helpful? Yes | No

    Default

    srigopal - I tried to do something similar to your code and ran into the same problem with flickering. If all you want to do is fade out (or in) 2 LEDs at the same rate, try using 1 output pin with 2 LEDs (each with a current limiting diode, of course). I have this working with red LEDs, but you may need a transistor for heavier current drawing ones like blue or white.

    Dwayne - is your code an example of a hardware pwm? Isn't there a PicBasic command for this? Also, do you know how to use a hardware pwm signal to fade out LEDs?

    Ross

  8. #8
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Ross,

    Ross>>Dwayne - is your code an example of a hardware pwm? Isn't there a PicBasic command for this? Also, do you know how to use a hardware pwm signal to fade out LEDs?<<

    No, my example is not a Hardware PWM. He emailed me with a private message, that he would like to have my code of my software PWM. I told him I would put it on the board when I got home.

    Yes, there is a PBP command for this kind of PWM...I just write my own <g>

    Yes, I know how to use hardware PWM to fade in/out LED's Since the Hardware PWM's are contiuous without intervention, the chip can be doing other things while it is streaming the pulses. That means a chip with 2 PWM's can operate two fading LED's

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 23:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  3. PWM 'channels ...what's that all about then!
    By HankMcSpank in forum General
    Replies: 5
    Last Post: - 23rd April 2009, 17:49
  4. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 08:24
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 01:26

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