SOLVED - IOC works on B0 but not B5


+ Reply to Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    I don't understand how you seem to have disabled the PPS for pins B0 and B5 without allocating something to them. Don't they need something allocated to them whether it's a port access or peripheral whatever if you plan to use the pins?

    Apologies, I'm still learning this stuff,

    Troy

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by rocket_troy View Post
    I don't understand how you seem to have disabled the PPS for pins B0 and B5 without allocating something to them. Don't they need something allocated to them whether it's a port access or peripheral whatever if you plan to use the pins?

    Apologies, I'm still learning this stuff,

    Troy

    Yeah, so am I.

    I looked for a way to move "treat this like a GP pin" via PPS settings, but I don't see anything like that.

    Unless you just can't recycle CCP pins, unless you move another peripheral to it (which is very possible).
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by Demon View Post
    Yeah, so am I.

    I looked for a way to move "treat this like a GP pin" via PPS settings, but I don't see anything like that.

    Unless you just can't recycle CCP pins, unless you move another peripheral to it (which is very possible).
    I was thinking outputs not inputs - [slapping forehead] my bad

    Troy

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by rocket_troy View Post
    I was thinking outputs not inputs - [slapping forehead] my bad

    Troy
    I'm no better; look at the previous post when I was blindly setting inputs when I was using outputs only.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    If MCC can produce all the config code, why not use this tool?

    For some reason I have not found why I am not able to use it on my PC. But I guess Richard can as we discussed that some time ago.

    Ioannis

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by Ioannis View Post
    If MCC can produce all the config code, why not use this tool? ...
    What is MCC, and what tool are you talking about?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    MCC is the tool. MPLAB Code Configurator.
    Select a device, select peripheral(s), select configuration for those peripheral(s) and it outputs configuration code for you (in C syntax).

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    you seem to have disabled the PPS for pins B0 and B5 without allocating something to them
    the power on default state for RxyPPS regs is 0 ie pin is assigned to be gpio
    so
    RB0PPS = 0 assigned to pin RB0 TO be a gpio pin [which it already was ]


    none of this serves any worthwhile purpose if you do the pbp3 HPWM defines correctly


    Code:
    PinD2   CON %011010                     ' Datasheet table 13-2
    PinD3   CON %011011
    CCP3PPS = PinD2                         ' CCP3 Peripheral input selectiowm  in hpm mode the ccp modules have no input function 
    CCP4PPS = PinD3                         ' CCP4 Peripheral input selection
    
    
    PeripheralCCP3  CON %001011             ' Datasheet table 13-3         
    PeripheralCCP4  CON %001100
    RD2PPS = PeripheralCCP3                 ' Pin D2 output source selection  all done with pbp define
    RD3PPS = PeripheralCCP4                 ' Pin D3 output source selection
    
    
    RB0PPS = 0                              ' Disable CCP4 on pin B0 (moved to D3) all done with pbp define
    RB5PPS = 0                              ' Disable CCP3 on pin B5 (moved to D2)
    Warning I'm not a teacher

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    did i say ioc pin change is a bad way to do keys

    try this and compare results

    Code:
    #CONFIG    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_ON
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32
    define  CCP4_REG     PORTD              ' PWM Pulse out to LCD contrast
    DEFINE  CCP4_BIT     2                  '   2N2907 PNP with 1K on base
    define  CCP3_REG     PORTD              ' PWM Pulse out to LCD backlight
    DEFINE  CCP3_BIT     3                  '   2N2222A NPN with 1K on base
    define  CCP5_REG     0                
    DEFINE  CCP5_BIT     0                  
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    WPUC   = % 00100000                          
    WPUB   = % 00110000 
    TRISA  = % 00001111
    TRISB  = % 11111111
    TRISC  = % 11111111
    TRISD  = % 11110011
    
    
    IOCBN  = % 00100000  
    
    
    PushSwitchA      VAR PortC.5      ;sw2
    PushSwitchB      VAR Portb.4       ;sw1
    PushSwitchC      VAR Portb.5
    InterruptLED     VAR Lata.4
    anotherLED       VAR Lata.5
    polLED           VAR Lata.6
    notherLED        VAR Lata.7
    
    
    
    
    ButtonWasPressed VAR WORD[2]
    lc var byte
        Pause 500                                       ' Let PIC stabilize
        InterruptLED = 0
        anotherLED   = 0
        HPWM 3,250,1953                 ' Pulse Contrast
        HPWM 4,150,1953                 ' Pulse Backlight    
    
    
    Mainloop:
        lc=lc+1
        if lc==50 then
             polLED = !polLED 
             lc=0
        endif
        ButtonWasPressed[0] =  (ButtonWasPressed[0]<<1) +  PushSwitcha  
        ButtonWasPressed[1] =  (ButtonWasPressed[1]<<1) +  PushSwitchb 
        if ButtonWasPressed[0] = $f then                    ' Check flag
             anotherLED = !anotherLED
        endif
        if ButtonWasPressed[1] = $f then                    ' Check flag
            notherLED = !notherLED
        endif 
        if IOCBF then
             InterruptLED = !InterruptLED
            IOCBF = 0
        endif
        pause 10
    goto mainloop

    pps , my way works fine even with no capacitor on the switches
    Last edited by richard; - 13th September 2024 at 03:32. Reason: led shuffle
    Warning I'm not a teacher

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by richard View Post
    did i say ioc pin change is a bad way to do keys

    try this and compare results...


    pps , my way works fine even with no capacitor on the switches

    Richard, I have no doubt your way is leaner, faster and more efficient. I might even figure out what's going on after staring at it for a few hours with my PBP manual beside me.

    But I have to adapt whatever code I come up with for 88 switches and 24 rotary encoders. So far, this way has worked reasonably well, and I understand what's going on.

    I do appreciate the help and suggestions; I might even try it later, or someone else will.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Just to confirm, there definitely is something else required than my PPS settings.

    I commented out the 4 DEFINES and used only my PPS settings and it didn't work.

    I activated the 4 DEFINES and commented out all my PPS settings and it worked.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    for what its worth
    porta.4 also fails to operate as a normal gpio i/p when hpm is used
    DEFINE CCP5_REG 0
    DEFINE CCP5_BIT 0

    is needed to restore operation


    edit, i had mixed up cause and effect i had sw on c5 and led on a4 i assumed led failure to operate as intended was due to sw not working
    but sw was fine led pin not so


    moral to story
    if you use hpm it will mangle all the default pins for normal use unless you take action
    Last edited by richard; - 13th September 2024 at 05:22.
    Warning I'm not a teacher

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    FOUND IT!

    I had set my CCP defines to CCP4 and CCP5 by mistake, I meant it to be to CCP3 and cCP4.

    Code:
    define  CCP3_REG     PORTD              ' PWM Pulse out to LCD contrast
    DEFINE  CCP3_BIT     2                  '   2N2907 PNP with 1K on base
    define  CCP4_REG     PORTD              ' PWM Pulse out to LCD backlight
    DEFINE  CCP4_BIT     3                  '   2N2222A NPN with 1K on base

    The IOC on B0 and B5 now get detected.


    Here's my complete code:

    Code:
    @ ERRORLEVEL -306   ; turn off crossing page boundary message
    
    '***********************************************************************
    ' Default in file: PBP3_1\DEVICES\PIC16F18877.PBPINC                   *
    ' List in file:    PBP3_1\DEVICE_REFERENCE\PIC16F18877.INFO            *
    ' Note:            PIC18 devices, the __CONFIG directive has           *
    '                    been superceded by the CONFIG directive           *
    '***********************************************************************
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    ;--- Defines -------------------------------------------------------------------
    
    DEFINE OSC 32
        
    DEFINE  LCD_DREG      PORTD             ' Set LCD data port
    DEFINE  LCD_DBIT      4                 ' Set starting data bit
    DEFINE  LCD_RSREG     PORTD             ' Set LCD register select port
    DEFINE  LCD_RSBIT     1                 ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTD             ' Set LCD enable port
    DEFINE  LCD_EBIT      0                 ' Set LCD enable bit
    DEFINE  LCD_BITS      4                 ' Set LCD bus size
    DEFINE  LCD_LINES     4                 ' Set number of lines on LCD
    DEFINE  LCD_COM1MANDUS 1000              ' Set COM1mand delay time in microseconds
    DEFINE  LCD_DATAUS    50                ' Set data delay time in microseconds
    
    define  CCP3_REG     PORTD              ' PWM Pulse out to LCD contrast
    DEFINE  CCP3_BIT     2                  '   2N2907 PNP with 1K on base
    define  CCP4_REG     PORTD              ' PWM Pulse out to LCD backlight
    DEFINE  CCP4_BIT     3                  '   2N2222A NPN with 1K on base
    
    ;--- Setup registers -----------------------------------------------------------
    
    'INTCON = %10000000                 ' Controlled by DT-INTS                     
    'PIE0 = %00010000
    IOCBP = %00000000                    ;IOC Interrupt, Positive Edge, low-to-high
    IOCBN = %00100001                    ;IOC Interrupt, Negative Edge, from high-to-low
    'IOCDP = %00000000                    ;...not available
    'IOCDN = %00000000                    ;...not available
    'IOCEP = %00000000                    ;...not available
    'IOCEN = %00000000                    ;...not available
    
    WPUB   = %00100001
    
    '=======================================================================================
    '                       CCP3 moved from B5 to D2                                       !
    '                       CCP4 moved from B0 to D3                                       !
    '=======================================================================================
    PinD2   CON %011010                     ' Datasheet table 13-2
    PinD3   CON %011011
    CCP3PPS = PinD2                         ' CCP3 Peripheral input selection
    CCP4PPS = PinD3                         ' CCP4 Peripheral input selection
    
    PeripheralCCP3  CON %001011             ' Datasheet table 13-3
    PeripheralCCP4  CON %001100
    RD2PPS = PeripheralCCP3                 ' Pin D2 output source selection
    RD3PPS = PeripheralCCP4                 ' Pin D3 output source selection
    
    RB0PPS = 0                              ' Disable CCP4 on pin B0 (moved to D3)
    RB5PPS = 0                              ' Disable CCP3 on pin B5 (moved to D2)
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    TRISA = %00000000
    TRISB = %00100001
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    
        Pause 500
            
        HPWM 3,250,1953                 ' Pulse Contrast
        HPWM 4,150,1953                 ' Pulse Backlight
    
        IOCBF = %00000000
    
        LCDOUT $FE, 1 : Pauseus 1
        LCDOUT $FE, $80, "COM/NAV ENCODER TEST" : Pauseus 1
    
        PAUSE 500
    
    Mainloop:
    
        if IOCBF.0 = 1 then
            LCDOUT $FE, $94, "... Swap B0 ..." : Pauseus 1
            IOCBF.0 = 0
        endif
    
        if IOCBF.5 = 1 then
            LCDOUT $FE, $D4, "... Swap B5 ..." : Pauseus 1
            IOCBF.5 = 0
        endif
     
        goto mainloop
    end
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by richard View Post
    ...none of this serves any worthwhile purpose if you do the pbp3 HPWM defines correctly...
    I'm a very fast learner, as long as you explain very slowly a bunch of times and let me fumble around for a few hours/days.


    I commented out all my PPS settings and those Defines were indeed all I needed for it to work.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  15. #15
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by richard View Post
    ...

    Code:
    PinD2   CON %011010                     ' Datasheet table 13-2
    PinD3   CON %011011
    CCP3PPS = PinD2                         ' CCP3 Peripheral input selectiowm  in hpm mode the ccp modules have no input function 
    CCP4PPS = PinD3                         ' CCP4 Peripheral input selection
    
    
    PeripheralCCP3  CON %001011             ' Datasheet table 13-3         
    PeripheralCCP4  CON %001100
    RD2PPS = PeripheralCCP3                 ' Pin D2 output source selection  all done with pbp define
    RD3PPS = PeripheralCCP4                 ' Pin D3 output source selection
    
    
    RB0PPS = 0                              ' Disable CCP4 on pin B0 (moved to D3) all done with pbp define
    RB5PPS = 0                              ' Disable CCP3 on pin B5 (moved to D2)
    in hpm mode the ccp modules have no input function
    I realize that now. I had just gone through the datasheet and picked up all the registers I thought related with PPS, then tried setting them up in my I thought would swap the CCP function from pins Bx to Dx.


    EDIT: Apparently I was doing something wrong, or forgetting something altogether.

    The HPWM command may be used without these DEFINEs if you manually configure the PPS and TRIS SFRs.
    from PBP3_PPS_notes.txt in PBP3_1 folder
    Last edited by Demon; - 13th September 2024 at 16:44.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: IOC works on B0 but not B5

    Quote Originally Posted by rocket_troy View Post
    I don't understand how you seem to have disabled the PPS for pins B0 and B5 without allocating something to them. Don't they need something allocated to them whether it's a port access or peripheral whatever if you plan to use the pins?

    Apologies, I'm still learning this stuff,

    Troy
    (bottom of p. 239 of datasheet 16F18877)

    Note: When RxyPPS = 0x00, port pin Rxy output value is controlled by the respective LATxy bit.
    Took me a while to notice this line.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Replies: 12
    Last Post: - 7th September 2024, 15:10
  2. Replies: 8
    Last Post: - 30th August 2024, 19:45
  3. Replies: 4
    Last Post: - 22nd March 2023, 11:32
  4. DS3231 works in one config, but does not works with other IC.
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd December 2019, 19:52

Members who have read this thread : 11

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