cannot find the reason for such a strange behavior


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: cannot find the reason for such a strange behavior

    if you can find the troublesome code i'd like to have a look at it with the view to seeing why it fails
    Door_Lock var PortB.4
    DmyFlg var bit
    Report var byte[8]


    Report[2] = !Door_Lock + 48 ' (didn't work! can't remember if it fails with True or false)

    The work around was

    DmyFlg = Door_Lock
    DmyFlg = !DmyFlg
    Report[2] = DmyFlg + 48

    Sorry, not exactly as I mentioned in my previous post! I should say "bit into byte"

    Alberto

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,695


    Did you find this post helpful? Yes | No

    Default Re: cannot find the reason for such a strange behavior

    The work around was

    DmyFlg = Door_Lock
    DmyFlg = !DmyFlg
    Report[2] = DmyFlg + 48
    I'M not sure you solution is correct

    I did a few experiments as follows and conclude that,

    if you invert a bit var (or bit alias) wether logical or bitwise only bit 0 in the result is valid , I you go on to use the result mathematically then all the other bits need to be masked off

    for a correct calculation



    D_Lck !D_Lck ~D_Lck D_Flg !D_Flg ~D_Flg R+!L R+~L R+!F R+~F
    WRONG
    0 65535 65535 0 65535 65535 47 47 47 47
    CORRECT
    0 255 65535 0 65535 65535 49 49 49 49
    WRONG
    1 65280 65534 1 65280 65534 48 46 48 46
    CORRECT
    1 0 65534 1 65280 65534 48 48 48 48
    WRONG
    0 65535 65535 0 65535 65535 47 47 47 47
    CORRECT
    0 255 65535 0 65535 65535 49 49 49 49





    Code:
       TRISC = %11101111        ' set PORTC I/O
     
    
     D_Lck var Portc.4
     D_Flg var bit
     Report var byte[4]
     
     
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10      
     
     Debug 13 ,10 ,"D_Lck",9 ,"!D_Lck",9, "~D_Lck",9, "D_Flg",9, "!D_Flg",9, "~D_Flg" ,9, "R+!L" ,9, "R+~L" ,9, "R+!F" ,9, "R+~F"
    main:
     PORTC.4=!PORTC.4
     D_Flg=D_Lck 
     Debug 13 ,10 ,"WRONG"
     Report[0] = !D_Lck + 48 
     Report[1] = ~D_Lck + 48 
     Report[2] = !D_Flg + 48 
     Report[3] = ~D_Flg + 48 
     Debug 13 ,10 ,#D_Lck,9 , #!D_Lck,9, #~D_Lck ,9, #  D_Flg ,9,  #!D_Flg, 9,# ~ D_Flg ,9,# Report[0] ,9,# Report[1] ,9,# Report[2] ,9,# Report[3]
     Debug 13 ,10 ,"CORRECT"
     Report[0] = (!D_Lck&1) + 48 
     Report[1] = (~D_Lck&1) + 48 
     Report[2] = (!D_Flg&1) + 48 
     Report[3] = (~D_Flg&1) + 48 
     Debug 13 ,10 ,#D_Lck,9 , #!D_Lck,9, #~D_Lck ,9, #  D_Flg ,9,  #!D_Flg, 9,# ~ D_Flg ,9,# Report[0] ,9,# Report[1] ,9,# Report[2] ,9,# Report[3]
      
     
     
     
      pause 1000
     
      goto main
    Last edited by richard; - 5th November 2016 at 02:47.
    Warning I'm not a teacher

  3. #3
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: cannot find the reason for such a strange behavior

    Today I have finaly found the time to implement the corrections to my code!

    I have corrected the number of bytes int the array Pulse from 75 to 80. Next I have changed the following two lines of code:

    Code:
    DMY = W0//256
    Pulse[75] = (255 - DMY)
    with the simple form suggested by Richard

    Code:
    Pulse[75] = ~W0

    Compiled (22Kb of code) and updated the mcu. Power up and checked the packet transmitted via esp NOOOO! CRC is still txed as 253 all the time!

    I did change the code again setting Pulse[75] = 123 (costant value) and re-checked. Well this time CRC was txed as 123! This proved that there is no byte corruption in the code, but the problem should be in setting the byte variable Pulse[75].

    So I did change the setting of Pulse[75] = 123 to Pulse[75] = W0.lowbyte. Re-checked and it worked! CRC was txed correctly!

    Hence I added : Pulse[75] = ~ Pulse[75] (inverting bits) and CRC was still txed as 253!!!!

    I have removed Pulse[75] = ~ Pulse[75] and kept the CRC as the low byte of the packet sum that works!

    But as I stated in this thread title: "I cannot find the reason for such a strange behavior"

    Alberto
    Last edited by Alberto; - 8th November 2016 at 15:49.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,695


    Did you find this post helpful? Yes | No

    Default Re: cannot find the reason for such a strange behavior

    try as I might I cannot produce any code where
    Pulse[75] = ~W0
    gives an incorrect result , the problem is elsewhere
    I believe you are just masking the real problem/s
    my challenge to you is :-
    provide some fully compliable code that demonstrates the problem , I would bet you cannot


    Pulse[75] = ~W0 converts to a 1 line macro when compiled

    Code:
    NOT?WB  _w0, _Pulse + 00075h
    where can that go wrong ?
    Warning I'm not a teacher

Similar Threads

  1. Strange behavior on PORTB on a PIC18F26K20
    By Dosbomber in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th September 2016, 00:31
  2. Strange Behavior 12F1822
    By nobner in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd February 2012, 09:11
  3. Strange LCD Behavior
    By chips123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st November 2009, 01:48
  4. Strange behavior - PORTG.2, 18F8720
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th January 2009, 00:30
  5. Strange electrical behavior with PIC16F684
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 28th March 2008, 07:58

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