Announcement

Collapse
No announcement yet.

PIC16F18326 PWM with PPS problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PIC16F18326 PWM with PPS problem

    Hello everyone.

    I am trying PWM with PIC16F18326.
    I set CCP1 to RC3 with PPS and output PWM with HPWM instruction.
    The PWM output was able to be output normally, but there was a problem with other pins.
    In order to check the status of other pins, all pins of A port and C port are Hi / Lo in 200mS cycle.
    Before the HPWM instruction, all but RA3 were blinking normally, but when HPWM is executed, RA2 and RC1 are fixed at Lo, and RC5 has an AC output.
    I think it's a rudimentary problem, but I would appreciate your advice and the correct code.

    Thanks !

    Code:
    #CONFIG
    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
    __config _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _WDTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LOW & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
    __config _CONFIG3, _WRT_OFF & _LVP_OFF
    __config _CONFIG4, _CP_OFF & _CPD_OFF
    
    #ENDCONFIG
    
    OSCCON1 = %00000000
    OSCCON2 = %01100100
    OSCFRQ = %00000110
    define OSC 32
    
    ANSELA = %00000000
    ANSELC = %00000000
    
    TRISA = %00000000
    TRISC = %00000000
    
    CCP1PPS = %00010010    ' is this necessary ?
    RC3PPS = %00001100      'RC3=CP1=PWM
    
    pause 100
    
    hpwm 1,127,500
    
    MAIN:
    PORTA = %11111111
    PORTC = %11111111
    
    pause 200
    
    PORTA = %00000000
    PORTC = %00000000
    
    pause 200
    
    goto MAIN
    end

  • #2
    Hello everyone.

    After posting, I found a thread "Normal i / o required on portc, pin6, 7 18f27k40".
    With reference to this, I / O settings were also explicitly set for the pins affected by the PPS setting part.
    Maybe it's better to explicitly set all PINs after setting PPS ?

    Code:
    'CCP1PPS = %00010010 'NO NEED
    RC3PPS = %00001100
    RA2PPS = 0
    RC1PPS = 0
    RC5PPS = 0

    Comment


    • #3
      Hello everyone.

      After that, when the RC5 port was set as the input,
      when PWM was output,
      there was a problem that RC5 changed to the OUTPUT port without permission.
      What's wrong?
      Please give me a solution.

      Code:
      #CONFIG
      __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
      __config _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _WDTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LOW & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
      __config _CONFIG3, _WRT_OFF & _LVP_OFF
      __config _CONFIG4, _CP_OFF & _CPD_OFF
      
      #ENDCONFIG
      
      OSCCON1 = %00000000
      OSCCON2 = %01100100
      OSCFRQ = %00000110
      define OSC 32
      
      ANSELA = %00000000
      ANSELC = %00000110
      
      TRISA = %00111000
      TRISC = %00110110     'SET RC5 to INPUT
      
      '==== ポートの設定 ================
      RC3PPS = %00001100   'SET RC3 to CCP1
      RA2PPS = 0                    'SET I/O because bad effect from PPS
      RC1PPS = 0                    ' same
      RC5PPS = 0                    ' same
      
      HPWM 1,127,500
      
      MAIN:
      
      HIGH PORTA.2 : PAUSE 200
      LOW PORTA.2 : PAUSE 200
      
      goto Main
      
      end

      Comment


      • #4
        There is a PPS UNLOCK sequence that sometimes matters. Try:
        Code:
        PPSLOCK = $55
        PPSLOCK = $AA
        PPSLOCK.0 = 0
        RC3PPS = %00001100 'SET RC3 to CCP1
        RA2PPS = 0 'SET I/O because bad effect from PPS
        RC1PPS = 0 ' same RC5PPS = 0 ' same
        We can crack this cotton PIC'n thang!

        Comment


        • #5
          Dear Mr.mpgmike

          Thank you for your advice and I'm sorry to my late reply.

          I tried your code and also added "RC5PPS = 0 ", but no improvement was seen.

          When just write into your code, RC5 is always Hi.
          When added "RC5PPS = 0", RC5 is always Lo, both no accept "Hi/Lo" input.

          About PPS unlock, I already wrote at CONFIG as "_PPS1WAY_OFF".

          In spite of wrote config, still need to write PPS UNLOCK on the main code every time ?

          I think the PIC16F18326 is a very useful PIC if PPS can be used correctly, so I want to solve the problem.

          I'm waiting more advices.

          Thanks!

          Comment


          • #6
            You would only need to UNLOCK PPS once. If you don't lock it again, it will remain unlocked.

            Even though HPWM works with the PIC's hardware CCP peripheral, you need to configure the needed SFRs. If you look in the data sheet you'll see that CCP1 requires a clock; Timer2 for example. That would also need set up (and turned on). You will need to configure the following SFRs:

            - CCP1CON (Register 29-1, page 308)
            - CCPTMRS (Register 29-5, page 311)
            - T2CON (Register 28-1, page 298)

            To understand what the bits do, you'll probably need to read sections of the data sheet to better understand what they do. HPWM will set values for PR2, CCPR1H and CCPR1L for you.

            You also need to DEFINE CCP1_REG and CCP1_BIT (5.28 HPWM, page 148 of the PBP3 Reference Manual).
            We can crack this cotton PIC'n thang!

            Comment


            • #7
              There's a file with details about HPWM defines that set PPS for both active and inactive channels on the 16F18326 and similar chips. There should be a message shown that names this file whenever you compile for this chip.

              The file is PBP3_PPS_notes.txt and it's in your PBP3 documentation. Documents\PBP3\DOCUMENTATION

              If you don't have this file, check your PBP version.
              Charles Leo
              ME Labs, Inc.
              http://melabs.com

              Comment

              Working...
              X