--- This is a test - only visible to admins ---
--- advertisement may go here ---
Today 12:04
Forum: Projects discussion
Starter: yvesmazzon
Views: 0
Replies: 4
Today 11:36
Forum: Third Party Developments
Starter: leonj
Views: 0
Replies: 1
Today 09:03
Forum: The Lounge
Starter: basparky
Views: 0
Replies: 15
Today 08:59
Forum: The Lounge
Starter: Oldhack
Views: 0
Replies: 2
Today 05:31
Forum: The Lounge
Starter: RGV250
Views: 0
Replies: 2
Today 00:53
Forum: Projects discussion
Starter: towlerg
Views: 0
Replies: 0
Today 00:36
Forum: Projects discussion
Starter: steyn
Views: 0
Replies: 6
Yesterday 22:34
Forum: Proton Plus Compiler v3
Starter: charliecoultas
Views: 0
Replies: 1
Yesterday 19:18
Forum: Proton Plus Compiler v3
Starter: evoortman
Views: 0
Replies: 2
Yesterday 18:21
Forum: Proton Plus Compiler v3
Starter: xldaedalus
Views: 0
Replies: 36
Go to last post By: yvesmazzon
Yesterday 16:43
Forum: The Lounge
Starter: rverm
Views: 5528
Replies: 12
Yesterday 16:34
Forum: Proton Plus Compiler v3
Starter: gtv_pic
Views: 0
Replies: 10
Yesterday 15:31
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 13
Closed Thread
Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 37

Thread: Mysterious PORTB problem34 days old

  1. #11
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Quote Originally Posted by See_Mos View Post
    I looked at this again and the code has several problems and the timing is all wrong. I think you need to start again with just the switch code and get that working first..

    What is the code after
    Code:
    If PortBswCheck = 0 Then
    supposed to do ?
    PortBswCheck increments from 255 to 0. When it has tried to read the switch 256 times, I try to reset the internal PORTB latch with a bunch of different code. You see, the switch code works perfectly. See above for the original, very simple PORTB read I started with, and progress to the much more complicated version I posted. Both versions work exactly the same, and the PORTB latch up occurs with both. Basically, the problem is that PORTB stops returning the logic state of the real world electrical state of the pins. With the internal pulls ups turned on, and no switches pressed. PORTB should always return %11111111. In my case, when the latch occurs (for whatever reason I do not yet know) PORTB starts returning %11100000 sometimes, %11100011 sometimes, %11101011 sometimes WHEN the real world state on PORTB is %11111111.

    And it is NOT the code that is doing this, at least, not the code by itself. When the Port is "read" the MCU goes through a 4 stage process called Q1 Q2 Q3 Q4 During this time, the electrical state of PORTB is read, latched onto an internal register.

    This link explains the potential problem:

    https://download.mikroe.com/document...c/help/rmw.htm

  2. #12
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    The GIE = False (0) and GIE = True (1) are there to prevent the code from being interrupted. It doesn't see to work anyway, but it isn't the problem.

    As suggested, it is possible something unusual like entering LVP mode might have some value. While RB6 and RB7 are PGC and PGD of the programmer, the third pin involved in the problem is also MCLR. Now this is just a coincidence. And, as said before, I've create 5 other products using the same pins with buttons and never had this problem. And, as you can see by the CONFIG settings that MCLR is configured as a digital input, and NOT Master Clear, it is a bit too much of a coincidence that the 3 most important pins of the programmer are also the pins involved in this problem.

    I mean, is it possible that, given a certain amount of noise on the pins, of a certain kind, with the right combination of presses, that either the MCLR pin or the RB6, RB7 pins are making the MCU think its being programmed? Unfortunately, I can't change the pins now. I'm using all the pins available, and without a board redesign, need to consider a work around, if this turns out to be the case.

    Thanks for your suggestions.

  3. #13
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,199
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    603.66 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Just to get a clear picture of how you have configured the hardware delay on PORTB could you post a sketch of the circuit

    What do you have on the MCLR pin

    Are you using any of the analog inputs

    I do most of my developing with an 18F25K22 and the PICkit2 is permanently attached and never had a problem. Also as LVP is turned off in the config I don't see how it can enter LVP mode, but then I don't know everything that goes on inside these devices.
    My RAM is failing

  4. #14
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,199
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    603.66 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Read-Write-modify only affects the output latches not the input side so that's not the problem.

    Is there anywhere else in the program that writes to Port B ?

    I tried you first code with 10K pullup resistors as that is how my test hardware is set up. Everything works as expected. I next reduced the code to just basic, no assembler. Checking the GIE bit is probably not needed but I always included it since when I used to write just assembler. You don't even need to clear and set GIE for it to work, but then I am not using interrupt for the test.

    Code:
    Start:    
        PortBswCheck = 1
    GetSw_Read:
        GIE = False                      ' stop interrupts interfering
        While GIE = True : Wend
        OldPortBState = PORTB    
        GIE = True                       ' allow interrupts during delay
        DelayUS 10
        GIE = False                      ' stop interrupts interfering
        While GIE = True : Wend
        PortBState = PORTB
        GIE = True                       ' allow interrupts during processing
    
        If PortBState <> OldPortBState Then
            DelayUS 987
            Inc PortBswCheck
            
            If PortBswCheck = 0 Then
    '            GoSub DebugFlash_Red
                GoTo ExitGetSwEnd '255 read failed, so bail out and try again
            Else
                GoTo GetSw_Read 'try to clear port until two reads are stable
            EndIf
            
        EndIf
        
    ExitGetSwEnd:
        Print At 1,1,Bin8 PortBState
        SWState = 0                             'clear the register
        SWState = PortBState & % 00011110           'sw1 & sw2 pins swapped RB.1 & RB.2 in AasignPins
        SWState = SWState >> 1                  '001111
        ' SwState.4 = INT                        '011111
        SWState.4 = 1                           '011111 ' no used set as ON
        SWState.5 = LCDSw3pin                   'As PORTE.3 same as MCLR but set to digital in CONFIG MCLRE=INTMCLR ' RE3 input pin enabled; MCLR disabled
    '    Select SWState
        Print At 1,1,Bin8 PortBState           ' show PORTB state
        Print At 2,1, Bin8 SWState             ' and processed state
        DelayMS 100
        GoTo Start

    and I figured out that E.3 is the LCD light switch
    Last edited by See_Mos; 17th October 2018 at 14:18.
    My RAM is failing

  5. #15
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,199
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    603.66 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Just noticed something in that last post. There is an error in the code as posted but not in my code as used. There should be no space between % and the first 0.
    Although Proton does not process spaces this does cause incorrect output.
    My RAM is failing

  6. #16
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    I'm sorry. My circuit is using an 18F46k22. The 18F26k22 doesn't have a PORTE. I apologize for any confusion. I use the 18F26k22 in 4 or 5 other devices, so, its on my brain.

    The 3 main switches that trigger this condition are 3 tactile switches RB6, RB7 and RE3 which are also PGC, PGD and MCLR. As George suggested below, these are the programming pins. It is true that I have LVP=off and MCLRE set to input, the "freeze" has the characteristics of entering LVP program mode. I don't know how that is possible, but until I know what's happening, anything is possible. I don't know how, but perhaps some pattern of the button pressing, plus other MCU internal noise, is cause the PIC to enter LVP program mode.

    Also, in reviewing my hardware, I see that I don't have debounce caps on these pins. So, I have klugged some on. Programming via Pickit2 still works great. Changed the switch to to read every 128 loops of the state machine (@2.5mS) and every main timer interrupt (@12mS) It must have two matches or the same state in >5-6mS before the switch value is calculated. I tried the software again, and went crazy pressing the buttons. It took a while, but the freeze did happen once. With the cap on, I get a nice rise from 0 to 1, but still a 100nS fall from 1 to 0, so the button press could still look like a logic signal.

    Yes, RB.0 had its digital circuitry turned OFF, and set to an analog input. It's function is OverCurrent short circuit sense with an interrupt-on-change. However this feature is turned off for the moment, all interrupt settings for this pin are turned of, and the load is very small, there is no possibility of an overcurrent condition setting the flag. That said, its connected to an external XOR Schmitt trigger chip. It should be a standard logic input. Having the ANSELB.0 set is a mistake. Thanks for pointing that out.

    'ANSELB PORTB ANALOG SELECT REGISTER
    ' bit 7-6 Unimplemented: Read as 0
    ' bit 5-0 ANSB<5:0>: RB<5:0> Analog Select bit
    ' 1 = Digital input buffer disabled
    ' 0 = Digital input buffer enabled
    'Follow [RB5] needs digital input disabled for use as analog port
    ANSELB = %00000001 'all digital input enabled except RB0 is the Current Limit Flag

    It should be ANSELB = %00000000 'all digital input enabled



    Also, RE0 is used an an output for PWM, and I found I had it being configured as an Analog input in ANSELE.

    Thanks again for pointing out my stupid mistakes.


    'ANSELE PORTE ANALOG SELECT REGISTER
    'bit 7-3 Unimplemented: Read as 0
    'bit 2-0 ANSE<2:0>: RE<2:0> Analog Select bit(1)
    '1 = Digital input buffer disabled
    '0 = Digital input buffer enabled
    ANSELE = %00000111 '


    It should be ANSELE = %00000110 'RE.0 = PWM3 RE.1 RE2. are Current Sense analog inputs

    I'm not sure how these might be relevant, but they are mistakes that needed fixing. I will try these changes and see if they affect any change in the appearance of the "freeze" condition.

  7. #17
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Don't know how the space got between the % and 00011110

    Current code attempting:

    If PortBswCheck = 0 Then 'check switch every so often
    OldPortBstate = PORTB
    PortBswCheck = 1
    GoTo GetSwExit
    Else 'PortBswCheck = 1
    PortBstate = PORTB
    EndIf




    PortBswCheck = 0 'clear the switch check counter
    If PortBstate = OldPortBstate Then 'if they match in condition, use them, otherwise, start over
    Else
    GoTo GetSwExit
    EndIf


    SwState = 0 'clear the register
    SwState = PortBstate & %00011110 'sw1 & sw2 pins swapped RB.1 & RB.2 in AasignPins
    SwState = SwState >> 1 '%00001111
    ' SwState.4 = INT '%00011111
    SwState.4 = 1 '%00011111
    SwState.5 = LCDSw3pin '%00111111 '

  8. #18
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    I checked all PORTB interactions. There are none. No writes, not other checks. As I mentioned, RB0 is wired to be a overcurrent interrupt on change INT0, but that code is currently commented out. RB5 can be used as an analog input, but that too is currently disabled, and there are no external components except a 1k protection resistor

    The Switch read Sub is the only place after intializing the PORTB is used in anyway.

  9. #19
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Quote Originally Posted by See_Mos View Post
    Just to get a clear picture of how you have configured the hardware delay on PORTB could you post a sketch of the circuit.
    attached is a PDF of the relevant circuitry, its more or less standard switch circuitry. Active low, PORTB should return 1 is switch is not pressed. 0 if it is pressed.

    MysteriousProblem.PDF

  10. #20
    Member xldaedalus's Avatar
    Join Date
    Jan 2005
    Posts
    148
    Thumbs Up
    Received: 4
    Given: 6
    Total Downloaded
    355.40 MB

    0 Not allowed!

    Default Re: Mysterious PORTB problem

    Well, for what its worth, there does now seem to be a change, not sure whether related to adding the debouce caps to the switches or changes to ANSELB / ANSELE.

    The buttons seem to work, without freezing, however, now the OLED cliches (prints odd characters) then/or goes black, and stays that way until power cycle. The rest of the device seems to work properly. I see no relationship between the two, other than the SPI pins (CS?). Unfortunately, so far, its usually the switch connected to the MCLR pin that starts it. Although I did see once, the ON / OFF switch do that same. The ON / OFF switch is located on RB1 and RB2 its and ON-OFF-ON (3 way) rocker switch.

    Hmmm.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. 16f628A portb.4 problem
    By raf in forum Absolute Beginners Section
    Replies: 1
    Last Post: 14th March 2017, 09:09
  2. PORTB not behaving
    By shantanu@india in forum Proton Plus Compiler v3
    Replies: 17
    Last Post: 27th October 2009, 09:23
  3. [SOLVED !] Problem with portB on16F886
    By JohnP in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 14th October 2008, 13:14
  4. 18F452 PORTB.6 & 7 Problem
    By scott e. in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 1st January 2007, 03:08
  5. Confused about portb
    By David Blackburn in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 3rd June 2005, 20:50

Members who have read this thread since 9th November 2018, 01:20 : 43

Actions :  (Set Date)  (Clear Date)

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