HPWM Problem


Closed Thread
Results 1 to 6 of 6

Thread: HPWM Problem

  1. #1
    Mark Scotford's Avatar
    Mark Scotford Guest

    Default HPWM Problem

    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

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


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

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


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. HPWM problem .. pls help!
    By Samuel in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 1st February 2006, 15:30
  4. problem ont hpwm on the pic16f767!!
    By oscar in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th May 2005, 10:41
  5. Problem with INTB0 and HPWM
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd March 2005, 16:15

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