PDA

View Full Version : HPWM Problem



Mark Scotford
- 7th September 2004, 12:59
Finished learning how to use an ADC now I'm onto the Hardware PWM of my 17C756A running at 4 Mhz. My set-up is as follows, I have a Pot wired between 0 and 5V wiper going into ADC of PIC, and the result being stored as a variable (B21). I have a LCD displaying the value of the variable correctly ie 0-255. To test the HPWM, I have (in essence) an analogue volt meter connected to the output. I turn my pot up from 0 slowly up to 255 and the output ramps up from 0 to FSD fairly smoothly, but 16 times, 1 after the other, despite the fact that the LCD shows the value of the variable correctly. It does not say in the PBP book that you can use a variable for the Dutycycle, but I tried it and it seems to work, except for the above error. Any help would be much appreciated.

TEST:
HPWM 1, B21, 250 'Output B21 as a voltage
GOSUB LCD
GoTo TEST

LCD:
ADCON0 = %00100001
ADCON1 = %11001010
ADCIN 2, B21 'Read Value of Control Pot.
LCDOUT $FE, 1, "POT"
LCDOut $FE, $14, #B21 'Display Control Pot. value
ADCON1 = %11001110
RETURN

Melanie
- 7th September 2004, 14:07
Are you measuring the HPWM pin directly with your Analogue Voltmeter? It's not going to give sensible readings. unless it's spec'd at 250Hz and able to respond to tiny pulses.

Connect your PWM pin to a Resistor (eg 10K). The other end of the Resistor goes to the +ve side of a Capacitor (eg 1uF), -ve end of which connects to 0v. Take your DC meter measurement from across the Capacitor.

Now as long as your meter is not something silly like a moving-iron type, and has a reasonably high impedance (eg 20kR/v) so as not to load the Capacitor too much, you should see a stable voltage proportional to your POT setting. If you bought your meter from the cheap side of town, and it's impedance is nearer 2kR/v (or less), then reduce the value of the Resistor (eg 4K7). The bigger the load you put across the Capacitor, the greater the 'ripple' on the DC level. Increase the frequency of the HPWM (eg to around 1kHz) to provide some compensation.

Usual practice is to buffer the PWM with an op-amp to give you a stable voltage to play with unaffecetd by varying loads.

Mark Scotford
- 7th September 2004, 14:38
Thanks Melanie, the actual output of the HPWM goes to the gate of a 35A Mosfet (via a buffer) which is a known working arrangement. We were using the same output configuration with a different PIC which did not have Hardware PWM (using the PWM command). Our output from the Mosfet is loaded with a quantity of fairly high wattage light bulbs used as a dummy load, and we are measuring the average output with an AVO 8 analogue meter which evens out any PWM due to the weight of the needle. On re-reading my post I perhaps did not explain myself very well. When I turn my Pot. slowly from 1 end to the other, the average output from the HPWM goes from 0, ramping up to full output, then suddenly back to 0 and ramping up again, repeating this process 16 times in total, till the end of the pot is reached, with the output ending on full on. I appears to be a mathmatical problem rather than an electronic one. Just to add some more detail, here are the defines at the top of my program.

DEFINE LCD_DREG PORTF
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 7
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

GoTo MAIN

Dwayne
- 7th September 2004, 16:17
Hello Mark,

Mark>> repeating this process 16 times in total, till the end of the pot is reached, with the output ending on full on. <<

Ok... What is happening, ( I am guessing here), that your range of your value that you are feeding your HPWM is from 0 to 1024 from your ADC? Is this correct? If so, your HPWM range is from 0 to 64 right now... thus 16 times 64 is 1024. (that is where I got your HPWM range...

Just for curiousity, feed your HPWM values from 0 to 64, and see if that is the full range of your HPWM. If so, you are missing some bit ranges on your configuration of your PWM.

Dwayne

Melanie
- 7th September 2004, 16:49
See what happens if you change ADCON1 from 11001010 to 00001010.

with bit 7 you're right-justifying in the ADCON1 statement (used for 10-bit word), but your DEFINE is for 8 bits (which by default you'll left-justify)... there might be a clash there... and what does bit 6 do? I've not got the Datasheet for your PIC, but in the 16 series bit 6 is unused (usually left at zero).

What throws a wobbly is that you say the LCD is displaying correctly. I assume the variable B21 is a BYTE otherwise HPWM might get confused.

Mark Scotford
- 8th September 2004, 10:40
Just found what my problem was, I did not set the correct Frequency, just changed it from 250 to 3907 and this corrected the problem, I was hoping to use a lower frequency, but after re-reading the PBP book, it says this is the lowest frequency I can use for a 17 series chip. Thanks for all those who tried to help.