PWM Module 18Fxx31


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    15

    Default PWM Module 18Fxx31

    Just a quick question here. Any one been dealing with the built in PWM modules in PICBasic?
    I am trying to do a 3 channel dimmer that uses the 14 bit PWM.
    The rundown of what I have so far is:

    PWMCON0 = 0101(takes care of the odd pins for output) bits 3-0 I’m not sure on how to set. I am assuming that I want independent mode for just having a simple dimmer setup. That would be 01011111.

    Next would be to setup “freerunning mode” – PTCON0 = 0000 (1:1 Postscale) 00 (1:1 Prescale) 00 (Free Running Mode) - all zeros.

    Next is the PWMCON1 = 00000000. This register deals with interrupts and special events. Neither are needed.

    I am not sure on the PWM Period stuff. Do I need to set PTPER? This I don’t really get. From what I can tell if I do need to set it, it would be PTPER = 0FFFH like in the datasheet.

    After that it’s all down to the Duty Cycle – PDCx (L & H)

    I won’t be using the dead time, override or fault registers. At least I don’t think so.

    I am new to the whole onboard PWM stuff so any help is greatly appreciated.

    Ian

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    It may not be what you are looking for, but DT has produced some excellent PWM utilities which are available from

    http://www.darreltaylor.com/DT_INTS-14/SPWM.html

    I'm sure there is an INTS_18 version too, but can't for the life of me find where it is.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Malcolm, but that probably won't help.

    I've seen those chips before, but haven't had a chance to try them out yet.

    All those 14-bit PWM's and capture channels look really interesting.
    But they sure don't work anything like the CCP modules.

    And nope, nothing special for DT-INTS either for those chips.

    I know... I'm a whole bunch of No Help aren't I.
    <br>
    DT

  4. #4
    Join Date
    Jan 2005
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply guys.
    Yah, I've used the CCP PWM stuff before and even done a simple Basic PWM but the resolution isn't good enough.
    I know that probably doesn't sound right but believe me, you can see the difference, and more importantly, the folks that will be using this device will point it out to me.

    Ok, I guess I just have to fight it out.
    I will let you know how I make out here.
    Thanks again.
    Ian

    Oh, and just so you know, this isn't a commercial(profit) application.
    Last edited by iphillipsca; - 17th April 2007 at 00:50. Reason: Forgot to mention.

  5. #5
    Join Date
    Jan 2005
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    The following works for setup:

    pwm setup declarations

    PTCON0 = %00000000 '1:1 postscale,1:1 prescale,Free running mode
    PWMCON0 = %01111110 'all odd PWM I/O enabled,PWM pairs in Independant Mode
    PWMCON1 = %00000001 '1:1 Postscale special event trigger,special event trigger occurs counting up, Updates from duty cycle and period buffer registers enabled, Output overrides via the OVDCON register are sycronized to the PWM time base.

    OVDCOND = %00101010 'Output on PWM I/O is controlled by the value in the Duty Cyle register and PWM time base - for POVD1,POVD3,POVD5

    PWMresolution VAR Word bankA
    PWMresolutionL VAR PWMresolution.byte0
    PWMresolutionH VAR PWMresolution.byte1

    PTCON1 = %10000000 'PWM Time base is on
    PWMresolution = 4064
    PTPERH = PWMresolutionH
    PTPERL = PWMresolutionL

    ' take your desired PWM value and put to PDCx L and H

    There does seem to be an issue when using the PWM in the low values.
    Just before the duty cycle is zero, it seems to flash to 100%.

    Anyone else experience this?

  6. #6
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Smile

    I'm working with the 18F2431...

    Forget the PICBASIC PWM-Modules, this device has to be coded "by hand" !
    I'm powering a brushless DC-Motor and I can't see your problem "around 0". Before programming new values to PDC* you have to set a bit and clear it afterwards in order to realy update the timings.

    Yes, there are 3 (or 4) independent PWM-Modules inside !
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  7. #7
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default details

    Hi!
    Can you give some details about your project.Also some code will be really helpfull explaining the timings,updation of PWM and use of motion feedback procedures.

Similar Threads

  1. 18F2331 Advanced PWM Questions
    By JDM160 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th July 2010, 23:04
  2. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Using PWM built in Module 16F628
    By earltyso in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th October 2007, 06:40
  5. pic 18Fxx31 PWM module
    By dirace in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th May 2005, 19:51

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