help hpwm in pic 16F88


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2007
    Posts
    9

    Default help hpwm in pic 16F88

    I c'ant switching hpwm between RB.0 AND RB.3 please can any one help me

    pic is 16f88:


    INCLUDE "modedefs.bas" ' Include serial modes


    @ DEVICE MCLR_ON, HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF ,CCPMX_ON

    define OSC 20


    OPTION_REG = $7f ' Enable PORTB pullups= %01111111
    ANSEL = %10000001 ' 'Set PORTA.0 analog rest digital
    ADCON1 = %10000000 'Right justify result
    ADvalue VAR WORD
    DutyCycle VAR WORD $22
    Frequency VAR WORD
    TRISA = %10000001
    TRISB = %10000000
    PORTB = 0


    'LOW PORTB.0
    'LOW PORTB.3 ; Set CCP1 pin to output low

    Frequency = 50
    DutyCycle = 50
    PAUSE 500
    loop:



    if portb.7 = 0 then
    goto left
    else
    goto right
    endif
    '=============================

    left:

    if portb.7 = 1 then right

    LOW PORTB.3

    @ DEVICE pic16F88, HS_OSC , CCPMX_ON
    PAUSE 100 ' start-up delay
    TRISB=0
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3


    HPWM 1, DutyCycle, Frequency
    GOTO left

    '=============================
    right:
    if portb.7 = 0 then left

    LOW PORTB.0
    @ DEVICE pic16F88, HS_OSC , CCPMX_OFF

    PAUSE 100 ' start-up delay
    TRISB=0
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 1

    HPWM 1, DutyCycle, Frequency

    GOTO right
    '============================

    goto loop


    END

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Bear in mind that the minimum PWM frequency you can achieve with an osc @ 20 MHz is 1221 Hz. (see page 74 of PBP manual)

    In your code the PWM frequency is set to 50 Hz.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Aug 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    I change to 4 mhz AND The Frequency TO 100 ,but the hpwm still on rb.0


    INCLUDE "modedefs.bas" ' Include serial modes


    @ DEVICE MCLR_ON, XT_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF ,CCPMX_ON

    define OSC 4

    OPTION_REG = $7f ' Enable PORTB pullups= %01111111
    ANSEL = %10000001 ' 'Set PORTA.0 analog rest digital
    ADCON1 = %10000000 'Right justify result
    ADvalue VAR WORD
    DutyCycle VAR WORD $22
    Frequency VAR WORD
    TRISA = %10000001
    TRISB = %10000000
    PORTB = 0


    'LOW PORTB.0
    'LOW PORTB.3 ; Set CCP1 pin to output low

    Frequency = 100
    DutyCycle = 50
    PAUSE 500
    loop:



    if portb.7 = 0 then
    goto left
    else
    goto right
    endif
    '=============================

    left:

    if portb.7 = 1 then right

    LOW PORTB.3

    @ DEVICE pic16F88, XT_OSC , CCPMX_ON
    PAUSE 100 ' start-up delay
    TRISB=0
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3


    HPWM 1, DutyCycle, Frequency
    GOTO left

    '=============================
    right:
    if portb.7 = 0 then left

    LOW PORTB.0
    @ DEVICE pic16F88, XT_OSC , CCPMX_OFF

    PAUSE 100 ' start-up delay
    TRISB=0
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 1

    HPWM 1, DutyCycle, Frequency

    GOTO right
    '============================

    goto loop


    END

  4. #4


    Did you find this post helpful? Yes | No

    Default Really need to read datasheets...really...

    You just can't not read the datasheets. You will get nowhere.

    In the data sheet: http://ww1.microchip.com/downloads/e...Doc/30487c.pdf

    It says:"The CCP module’s input/output pin (CCP1) can beconfigured as RB0 or RB3. This selection is set in bit 12 (CCPMX) of the Configuration Word".

    So we read the whole document so that we have a small idea where to find this register, or, we do a search in the document for this register.

    On page 130 we find register 15-1. Here we find bit 12 - the CCPMX bit.

    No escaping it - for real - truths - RTFDS.

    You were also told by Aratti about minimum frequencies: You still set it for what you wanted; not what it can do. In the table regarding 14-bit core it says @4MHz the minimum frequency is 245Hz. 245 is more than 100.

    RTFM...
    Last edited by mtripoli; - 25th March 2010 at 14:11. Reason: more

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


    Did you find this post helpful? Yes | No

    Default

    You can't change config settings with @ DEVICE at runtime.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by selim View Post
    I change to 4 mhz AND The Frequency TO 100 ,but the hpwm still on rb.0
    4 mhz doesn't do 100 hertz either, but Arrati's page reference shows you that. You will need to run the chip at 0.5mhz for 50 hertz, or you can run at 1 mhz for 100 hertz.
    Last edited by ScaleRobotics; - 25th March 2010 at 14:21.

  7. #7


    Did you find this post helpful? Yes | No

    Default Huh... I didn't RTFDS

    Quote Originally Posted by Bruce View Post
    You can't change config settings with @ DEVICE at runtime.
    I've never had to do it so it didn't occur to me that you couldn't change this during runtime; I could think of situations when you might want to switch between running PWM to different devices at run time. I had to go back and look:

    "15.1 Configuration Bits
    The configuration bits can be programmed (read as ‘0’), or left unprogrammed (read as ‘1’), to select various device configurations. These bits are mapped
    in program memory locations 2007h and 2008h. The user will note that address 2007h is beyond the user program memory space which can be accessed only during programming."

    I don't have an application for this, but I would have thought you could(switch between RB.0 and RB.3) at run-time. Hmmm... learn something new...

  8. #8
    Join Date
    Aug 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    The Frequency it not my probl ok for this point ,but my probl is the switching betwen rb.0 and rb.3

    thank you for help

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Being you want to change pins why not use the software PWM.
    Dave
    Always wear safety glasses while programming.

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