View Full Version : marad75

- 15th December 2005, 19:26
Hi, I'm fairly new at this. I am using a 16F84 with two a/dc's. I can do the math in PBC ok, but am having trouble getting the output type I need. I need a PWM output that can be set up for 0 to 100% duty cycle. Can anyone help with a routine that uses, maybe, PWM output or PULSOUT with pauses? Or maybe just HIGH, X, Pause, X, Low,X, or whatever. Really stumped.
Thanks in advance, Ron

- 16th December 2005, 04:25
You have three options...

1. Your PBC has a command called PWM... go check it out in the manual - it even comes with an example.

2. Do s SEARCH on this forum (use PWM* as the search phrase) for heaps of topics on PWM many with examples.

3. Swap your 16F84 (I really don't know why folks still use this chip) for a pin compatible 16F628 which has hardware PWM on-board... the Datasheet in the Capture/Compare/PWM (CCP) Section explains step-by-step how to initialise and get that running...

- 16th December 2005, 16:39
Hi Melanie,
Thanks for your reply to my PWM question! I have older versions of both PBC and PBP. Neither of them include the 16F628. I would upgrade to later versions, but am on Social Security and money is tight. Besides, the 16F84 is doing well for this project. All other functions work well on this. (Radio Control hobby project)
Now, could I use a PulsOut command and scale the length value until the resulting "PWM" function is approximately right? (relative to the off time to go through the program again) Am using a 4 meg XT and there are actually two outputs for this project, each doing a separate "PWM" thing. Where I run into a "senior moment" with this is USING THE PULSOUT COMMAND, I AM ONLY USING 1 CYCLE OF "PWM" for each of the two outputs, that occur each time the code loops through.
If I use real PWM on the 16F84 with a variable for the duty and, say, 10 cycles, will the pwm have to complete the full 10 cycles before upgrading? Or will the duty variable be upgraded each time the program loops through again?
I hope this makes sense and THANKS MUCH FOR YOUR HELP!!

PS this is all in PBC

- 16th December 2005, 18:57
If you specify your 10 cycles for PWM, then it will execute those tens cycles before exiting and continuing with your next instruction.

You may want to check out Darrel Taylors PWM routine that can sit and run in background whilst you're doing other things...


...and if that excites you try...