Erratic behavior on a HPWM on a 16F88


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Erratic behavior on a HPWM on a 16F88

    Could it be your defines for your ADC being in mixed case? I was reschooled in that recently.

    On your OSCCON statement, are the last 4 bits what you want? Assuming you're using an internal oscillator, Bit 3 should be 1 for internal clock, Bit 2 should be 1 for stable clock, Bits 0-1 as 00 uses Fosc to set oscillator.

    ADCON1 bits 0-3 are undefined. I'm assuming you want your Vref to be right justified with Vref and AVss so the ADCON1 should look like this 10110000. It says in the data sheet you need to set ANSEL AN2 and AN3 to inputs to use Vref. So make sure to change your ANSEL settings to 00001111 for AN0 to AN3 as inputs.

    I'm also wondering if your ADCON0 bit 2 should be a 1 to start the conversion process. If it's a 0 I wonder if the conversion process will even begin.

    I'm also assuming TRISB is for a part of the program not shown.

    All that said I'm not a true "programmer" and I must just be creating more fodder. Best wishes.

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Erratic behavior on a HPWM on a 16F88

    Hi,
    thanks for answering, changed the OSCON but that did not help,
    this is my program:
    Mainloop:
    hPWM 1,127,150 'channel, dutycycle, frequency
    pause 20

    goto Mainloop
    END
    Therefore no ADCON to worry about, and I'm getting in the Kilohertz output...
    something wrong with the clocking output of the frequency

    K

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Erratic behavior on a HPWM on a 16F88

    Your code is very similar to something I did a long time ago. I haven't tried it but try this:


    OSCCON = $70 '8mhz
    adcon1 = 7 ' set inputs to digital - the adcin command automatically converts them to analog
    @ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON

    DEFINE OSC 8

    CMCON = 7

    TRISB = %01000010
    TRISA = %00000111

    DutyCycle var byte
    Frequency var byte

    Mainloop:
    ADCIN 0, DutyCycle 'Read channel PORTA.0 Duty Cycle
    ADCIN 1, Frequency 'Read channel PORTA.1 Frequency
    HPWM 1,DutyCycle,Frequency 'channel, dutycycle, frequency
    goto Mainloop
    END

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Erratic behavior on a HPWM on a 16F88

    Hi,
    Alain already wrote this in the very first reply but it seems to have gone unnoticed. When using the CCP-module in the PIC to generate a PWM output (which is what the HPWM command does) there's lower limit on the frequency depending on the frequency of the PICs oscillator. For a 14-bit PIC (which the 16F88 is) running at 8MHz that lower limit is 489Hz. All according to the manual. You're trying to set the frequency to 150Hz when it can't go lower than 489Hz, it's probably overflowing.

    And, which Alain also wrote, in the original code you had the Frequency variable declared as a BYTE. That won't work since the lowest possible value you can assign to that variable when the PIC is running at 8MHz is again 489 so you must declare Frequency as a WORD.

    Finally, I seem to remember something about HPWM not being suitable for continous update like this, probably because it sets up the CCP module for PWM each and every time but I'm not sure. I know that Darrel (of course...) wrote a routine better suited for that - and that was able to use the full 10bit resolution when available. Search for HPWM10 or something like that.

    /Henrik.

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Erratic behavior on a HPWM on a 16F88

    Hi,
    thanks, I must of read it quickly, I thought that was the maximum frequency!!
    thank you
    .. working now with higher frequency

Similar Threads

  1. PIC16F887 erratic behavior with DT interrupts
    By GordonCook in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th October 2012, 02:58
  2. Erratic Behavior on a 18F452
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th October 2010, 17:20
  3. erratic behavior when using MPASM vs. PM
    By cool_justin in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th June 2006, 01:08
  4. Erratic LCD behavior
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2006, 19:48
  5. Erratic PIC12F675 behavior
    By russman613 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th February 2006, 14:46

Members who have read this thread : 0

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