HPWM question


Closed Thread
Results 1 to 4 of 4

Thread: HPWM question

  1. #1
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257

    Default HPWM question

    Howdy,

    I have a project in mind that could use the hpwm on my pic 16F628.

    Unfortuantley I ma getting pretty confused by the data sheet and would like some help getting started.

    For example, what code is required to generate a 1KHz / 50% duty cycle pulse train? This is what I have so far:

    <table border=1><tr><td><b>CMCON</b> = 7
    <b>DEFINE</b> OSC 4
    PAUSE 1000
    <b>HPWM</b> 1,127,1000
    END
    </td></tr></table>

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


    Did you find this post helpful? Yes | No

    Default

    Step by Step...

    Firstly Defines come first... by default PBP assumes 4MHz clock, so you don't need to have a DEFINE OSC statement unless your clock is other than 4MHz.

    Secondly, let's set the PIC up for internal oscillator and no MCLR (MCLR pin can be used as an Input)...

    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628, BOD_ON
    ' Brown-Out Detect

    Now we have our PIC configured, we need to configure the pins... let's say we want a Blinky LED on PortB.0 and of course our HPWM will fall out of PortB.3...

    LED var PortB.0
    ' Put a LED on this Port Pin
    CMCON=7
    ' This assigns all pins Digital but it only affects PortA, so if
    ' you're not bothered with PortA this is irrelevant
    TRISB=%00000000
    ' I've assigned ALL of PortB as Output,
    ' I only need to have done that for B.0 and B.3
    Pause 200
    ' A large Pause at startup is only needed to wake-up sluggish
    ' external devices like LCD's...
    HPWM 1,127,1000
    ' Yup, this will give 1kHz at 50% Duty
    Loop:
    Toggle LED
    Pause 500
    Goto Loop

    End

    This blinks an LED (somebody else wanted to know how to set up a 16F628 to do that so it answers that query as well), while at the same time it will permanently output your PWM train in background.

    Melanie

  3. #3
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Thanks Mel. Great explanation.

    Cheers

  4. #4
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Mel,

    I have found that those defines work a treat when programming the pic.... I have been setting those rotten fuses manually for so long.


    I use Microcode studio, and in it's PBP manual
    (help topics) there is no mention of the below @DEVICE commands.

    Silly question, but where can I find a list of these @DEVICE commands?

    Cheers
    .....
    I just read the 16F629 Post!.... Ouch!
    Last edited by Squibcakes; - 24th June 2004 at 23:31.

Similar Threads

  1. HPWM question
    By sjmusic2 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th May 2009, 19:50
  2. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 13:00
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

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