Pwm


Closed Thread
Results 1 to 7 of 7

Thread: Pwm

  1. #1
    Join Date
    Jul 2007
    Posts
    48

    Default Pwm

    How do I PWM two pins at the same time with this code?

    Code:
    For duty = 0 to 255
    PWM PORTB.0,Duty,Cycle
    HIGH PORTB.0
    Next

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    With the PWM command, you can not.

  3. #3
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Is there anyway you can PWM to pins at the same time?

  4. #4
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    You can, if you use a PIC with two hardware PWM modules.

    Or, you you use interrupts. Search for Darryl Taylor's "instant interrupt", and you'll find everything you need. (I think a post from just today has it.)

  5. #5
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Multiple Slow Speed PWM

    Hi XOXB,

    Yes I agree that Darrel's Multiple Slow Speed PWM example is great. I use 16 channels of PWM to control the brightness of LEDs on an 18F2410. I believe you could do 8 or more on a 16F. It all depends on the freq and the resolution you run at. You must use this with DT_INTS-14 or DT_INTS-18 depending on the pic.

    Thanks again Darrel!!!


    DT_INTS-14 (SPWM_INT - Multiple Software PWM)
    http://darreltaylor.com/DT_INTS-14/SPWM.html
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xobx View Post
    Is there anyway you can PWM to pins at the same time?
    Do they need to be at the same frequency?

    Are the duty cycles related (e.g., 1/2 or double of the other)?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Aug 2006
    Posts
    6


    Did you find this post helpful? Yes | No

    Default This is my code for testing PWM

    ; adjust duty 50%
    ; period of on state ,Tduty
    ; (CCPR2L with T2CON.5.4) = Tduty / (Tosc x T2prescale)
    freq1 con $41 ; adjust for duty cycle
    freq0 con $00 ; very low duty cycle for no output
    ccpr2l = freq1 ; adjust Duty cycle



    ; adjust carrier frequency
    ; period of PWM ,Tpwm
    ; Tpwm = (PR2+1)x(4Tosc) x T2prescale
    pr2 = 130

    ccp2con = %00111111 ;MSB>> 2xNone..2xDuty2bitLSB..4xPWM mode >>LSB

    t2con =%00010000 ; MSB>>1x None..4x PostScale....1xEnable..2xPrescale >>LSB

    tmr2 =$00 ; clear timer2 register
    t2con.2 =1 ; enable timer2 module

    '------------ Variables ---------------
    index1 var byte ; for loop count


    goto test1


    '-----------------------------------
    test1:
    ;start freq
    if portb.7=0 then
    ccpr2l =freq1
    endif

    ;stop freq
    if portb.6=0 then
    ccpr2l =freq0
    endif
    goto test1

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. PWM: Vernacular/Function (Newbee)
    By TerryN in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd July 2008, 16:58
  4. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  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