Software PWM Problems


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2005
    Posts
    6

    Default Software PWM Problems

    Hi! want to read the 8 Bit AD of the 12F675 an put it out as PWM with duty cyle between 0-100%.
    My Programm is working well, but when AD gets 5V, I get Pulses out with 400ĩS Pause. But at AD 5 V it should be permanently on, without Pulses
    I donīt know whats the problem.
    Here Is my Programm, I attached the Scope Picture.

    Define OSCCAL_1K 1 ' Calibrate internal oscillator

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS


    LED Var GPIO.0 ' LED is bit 0, PIN 7

    adval var word ' Create adval to store result
    i var word

    ANSEL = %00111000 ' Set AN3 analog, rest digital
    CMCON = 7 ' Analog comparators off

    loop:
    ADCIN 3, adval ' Read channel 3 to adval
    i = 256 - adval
    I = i * 10
    Pulsout LED,adval ' Puls is 2,56 ms
    Pauseus i 'cycle = 5,12ms = 195 Hz

    Goto loop ' Do it forever

    End

    Hope, Someone could help me!
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    With an A/D input > 0V you will always have a pulseout "period" > 0. Grounding the A/D input should stop the output pulse.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Nov 2005
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    I think you missunderstood something, the 12f675 hasnīt got a Hardware PWM, so I want to emulate it in Software! And my Problem is that I could not put the output permanently on, between 0 an 100% der must be pulses, but on 0% the output should have ground signal (thats working) and on 100% the output should have high signal, and thats the problem, it isnīt a countinously line it should be!

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    loop: 
    ADCIN 3, adval ' Read channel 3 to adval
    if adval<250 then
       i = 256 - adval
       I = i * 10
       Pulsout LED,adval ' Puls is 2,56 ms
       Pauseus i 'cycle = 5,12ms = 195 Hz
       else
           high led
       endif
    
    Goto loop ' Do it forever
    If you can change your PIC, use the 12F683. It have an internal PWM module.
    Last edited by mister_e; - 27th November 2005 at 20:58.
    Steve

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

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    If you *REALLY* need smooth PWM out of your chip, it is possible.

    One approach would be to set up a hardware timer to give you a constant period (say 100uSec), and then use an interleave-type A/D routine. You could do the conversions (and the math) on consecutive timer rollovers.

    Using this technique you could get 8 bits of resolution and 0 to 100% duty cycle at 40Hz. Not great, but possibly usable.
    Charles Linquist

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default

    Hi,
    (OK, just an idea here - worth a try)
    With the AD result set to 8 bits your result will vary from 0 to 255. Try changing the line:
    Code:
    i = 256 - adval
    to
    Code:
    i = 255 - adval
    and see what happends. Even at full scale (adval=255) your i variable will be 10 if you subtract adval from 256. You will probably still get short glitches but hopefully you will end up closer to what you want.

    /Henrik Olsson.

Similar Threads

  1. Software PWM
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 15:21
  2. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 12:49
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  4. 2 PWM in 16F690 problems
    By ciendavila in forum mel PIC BASIC
    Replies: 9
    Last Post: - 27th April 2008, 10:03
  5. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 02:34

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