Erratic behavior on a HPWM on a 16F88


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1


    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    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.

  3. #3
    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, 03:58
  2. Erratic Behavior on a 18F452
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th October 2010, 18: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, 02:08
  4. Erratic LCD behavior
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2006, 20:48
  5. Erratic PIC12F675 behavior
    By russman613 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th February 2006, 15: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