PDA

View Full Version : HPWM question



Squibcakes
- 24th June 2004, 00:44
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>

Melanie
- 24th June 2004, 01:33
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

Squibcakes
- 24th June 2004, 10:59
Thanks Mel. Great explanation.

Cheers

Squibcakes
- 24th June 2004, 23:27
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!