A PIC can't do 10 bit PWM to 500Khz, since it would need a counter running at 500KHz * 1024 = 512MHz.
A PIC can't do 10 bit PWM to 500Khz, since it would need a counter running at 500KHz * 1024 = 512MHz.
Charles Linquist
Absolutely Correct!
As the frequency increases, the resolution decreases.
Follow that all the way to the highest frequency, and with OSC=16, you should have 2mhz PWM at 1-bit resolution (essentially on or off).
@ 500 khz, you should have 4-bits. And if all you ever want is 50% dutycycle, then it's a piece of cake.
<br>
DT
Hi Darrel & Charles.
I need 50% duty cycle at 32767 Hz on CCP2 to drive an Intersema pressure sensor - easy - even I can do that with 8 bit HPWM.
I also need a variable duty cycle to drive an AGC circuit. With 8 bit HPWM, my AGC is sudden death and one count goes from not quite enough to a little bit too much. 10 bit HPWM would be much less sensitive. The frequency must stay at 32767 Hz to suit the Intersema sensor.
Can I get 10 bit HPWM at 32767 Hz?
Cheers
Brian
Last edited by BrianT; - 8th January 2008 at 09:20.
As long as your OSC is 20 or more, then Yes.
@ 4mhz OSC you only get 8-bit resolution with that freq.
HPWM10 should work fine with it.
<br>
DT
Thanks everyone,
I have had to be away for a couple of days, I did have to manipulate and condition the frequency values several times to obtain suitable results from the DIV32 operation, to provide a usable value for PR2.
But it is very messy, maybe now not so bad after all.
will follow up when I am back
I should also try again to get PBL to compile, from memory I could not immediately find any solution to the error codes and did not wish to be sidetracked, considering LONGS was one of the features that prompted me to upgrade I should review.
Thanks again
Duncan
Hi Back again
I have changed from 16F648A to a 18F1320 to allow the use of PBPL, the pin allocations are different for the CCP and the USUART but that is now sorted.
I am looking now at Darrel Taylor’s macro HPWM10, there are two uses of DIV32 the first calculating the value of PR2. The DIV32 multiply is within the PR2 ASM routine
With Darrels' permission.. could the next lines be something like?
HP_Long = (resultant of Multiplication) / HP_Freq
HP_Temp = HP_Long.WORD0
in which R register does the resultant reside?
or remove the PR2 ASM altogether and just use PBPL.
and the second use of DIV32 for the CCP section
HP_Long = HP_Temp * HP_Duty
HP_Long = HP_Long / 1023
HP_Duty = HP_Long.WORD0
long winded and compiles into 1624
I would very much wish to contribute but I find it very difficult when there are so many people who know soooooo much more than I.
Thanks also for the help Charles, I do not have any PICs hooked up to a 108 type keyboard, I presume that it is easier on is the older type rather than the newer PS2 type. Actually I have a couple of old magnetic swipe card readers and some old keyboard inline barcode readers as well in the same box, trouble is I could not begin to remember where the box might be![]()
I am also reminded that I used to know all the barcode symbologies once.......... now I regret all gone................ come to think of it quite glad really. maybe it made space for something more exciting
Duncan
Actually,
My code does not connect directly to a keyboard. It receives data from the PICs serial port which is connected to a PC. The PC is running HyperTerm or TerraTerm. When you press the "UP" and "DOWN" arrow on a PC keyboard, HyperTerm actually sends out 3 ASCII characters (the first one being an <ESC>).
So, on a HyperTerm session, when the program starts, the PIC asks what frequency you want the PWM to be -
312Khz,156Khz,78Khz or 39Khz. It uses a table to set PR2 to the correct value, and then writes the desired PWM Value into CCPR1L and CCP1CON. You increment or decrement the
PWM value by pressing the UP and DOWN arrow keys.
Charles Linquist
Bookmarks