HPWM on 16F88


Closed Thread
Results 1 to 8 of 8

Thread: HPWM on 16F88

  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Default HPWM on 16F88

    Hi folks, long time no see!

    Maybe someone is in the mood to help.
    Thanks in Advance.
    try to make an engine water pump driver and Iīm frustrated about my inability to get the HPWM working.
    the °C reading works and the speed change works too but I canīt
    get the RB0 to make it right....I know its in the config thingy..


    Heres my code:
    '************************************************* ***************
    '* Name : Thermometer-LCD1 + HPWM (only for range 70-90°C) *
    '* Test with 20-23 °C RB0 = HPWM out *
    '* Author : M.David *
    '* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 31.03.2011 *
    '* Version : 1.0 for NTC Probe AB 94 098 000.D1 M12 x 1.5 *
    '* Notes : 16F88 LCD 1X16 connected as usual *
    '* : Portb.7 analog IN 0-2V *
    '************************************************* ***************


    Include "modedefs.bas"


    Define OSC 4
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 100 ' Set sampling time in uSec

    define CCP1_REG PORTB
    DEFINE CCP1_bit 0



    CMCON = 7 ' Disable analog comparator
    ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital
    ADCON1.7 = 1 ' Right justified results... duh... really needed in 8 bits???

    Uhilf var word

    Uin VAR Word
    Fac var Word
    Multi Var Word
    Uresult var Word
    Temp Var word
    speed var word
    Speed = 0

    pause 100

    LCDOUT $FE,1

    PAUSE 1
    LCDOUT $FE,1,"Pumpensteuerung"
    pause 2000
    LCDOUT $FE,$C0,"Wassertemperatur"
    pause 3000


    main:
    HPWM 1,speed,1000

    ADCIN 6, Uin ' Read channel 6 (RB7)
    pause 10
    Uhilf = Uin * 7
    Uresult = Uhilf / 48
    Temp = Uresult / 100

    pause 10
    if Uresult = 21 then
    speed = 0
    endif

    if Uresult = 22 then
    speed = 127
    endif

    if Uresult = 23 then
    speed = 255
    endif

    LCDOUT $FE,1,"Temp=",DEC2 Uresult
    pause 2000
    LCDOUT $FE,1,"Speed",DEC3 speed
    pause 2000


    goto main



    END ' End of program

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


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    Hi,
    I think that CCP1 defaults to RB3 and that you, as you say, has to reconfig it to have it on RB0 instead.

    Open 16F88.inc file located in the PBP folder and change the CONFIG line to:

    __config _CONFIG1, _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _CCP1_RB0

    Note that there are two lines, one (the one I showed above) if you use MPASM and another if you use PM and they differ slightly in the format used but you'll get the idea.

    Just remember that once you've edited the file it stays that way and if you forget about it you'll scratch your head the next time you're using the F88 and the CCP module doesn't work on RB3.... ;-)

    /Henrik.

  3. #3
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    Hi Henrik,

    tried your suggestion, didnīt work.
    thought it was already in the defines, but tried that too.

    Any more ideas?

    thanks

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


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    Hi,
    Now I'm a bit confused, it seems like it IS defaulting to PortB.0 and not PortB.3 as I said earlier, so you shouldn't have to change anything. Either way I've tried it here and it works.... I can switch the PWM output between RB0 and RB3 by changing the CONFIG like shown in the previous message.

    However, I don't see you setting the TRIS register anywhere and I don't know if HPWM does that for you, always best to do that your self.

    /Henrik.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    If you are using MPASM for the assembler, defines need to be all uppercase.

    Code:
        define CCP1_REG PORTB
        DEFINE CCP1_bit 0
    DT

  6. #6
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    Hello Darrel,

    nice you took a look at my childish problem.

    The config files you mentioned were in the upper part of the program
    do I have to put them in the .inc file? Iīm confused.

    And i was so frustrated I wrote code that used Portb.0 as switch
    inside my simple program because I feared the chip was blown but it works.

    it is just: I canīt get portb.0 as HPWM output AND the normal LCDout application at once. The LCD is the reason I canīt switch the port. got the boards already.

    sream, howl, and so on

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: HPWM on 16F88

    Try to set your fuse like this:
    Code:
    @ DEVICE PIC16F88, CCPMX_OFF
    where:
    0 = "ON" CCP1 on RB3
    1 = "OFF" CCP1 on RB0



    You also need to set a register:
    Code:
    CCP1CON = %00001100 'Select PWM Mode
    HTH
    Roger

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Use PWM instead

    Instead of using HPWM, try this:
    Code:
    PWM PORTB.0,speed,1000
    You won't need to declare/define T2CON, CCP1CON, PR2 and CCPR1L.

    PS: I'm using MCS
    Roger

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