Truth Tables in PBP


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Thanks Guys!
    I thought there had to be another way....
    BTW, it WAS a bug in my code that kept me from the timing sequence. I just tripped out all the code but the one conditional area - code worked like I thought it should.
    Then with the entire code back, I systematically remarked all the other places in the code where I zeroed the TFLAG bit var which was in all the other conditionals until it passed the var the way it should.
    Turns out you actually can not type using all thumbs! I had mistyped and it was staring me in the face.......

    Now that it actually works, its now going to be a learning experience and a life lesson to try these other ways so I may help someone down the road.
    Starting with arrays and trying the bit manipulation schemes.......

    Thanks and Regards.
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Quote Originally Posted by ecoli-557 View Post
    Now that it actually works, its now going to be a learning experience and a life lesson to try these other ways so I may help someone down the road.
    Starting with arrays and trying the bit manipulation schemes.......
    You are welcome and if you need more help, as always, just ask.

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Thanks Steve.
    I have the array working now, thanks to Pedja089 (Thanks!) and thanks to Steve (EarlyBird2) I have the bit manipulation going.
    I have a solution using bit manipulation and Select Case statements which work completely and is more readable than my early attempts at multiple if the statements.
    The array idea works well except I can't seem to figure out the timing; on 2 inputs (9 and 11) I have a timing function where an output stays high for 2 seconds then goes low.
    For the array, I use
    Code:
               Table            var byte[16] BANKA              'Array input is the value of the 4 inputs; 0-15 from the binary weight
               tflag            var table.3                     'timer flag
               TableIn          var byte                        'Entry into array from inputs
               temp             var byte                        'Temp var to use as a debounce
    and to get the table data is use
    Code:
              Table[0]=6
              Table[1]=2
              Table[2]=6
              Table[3]=2
              Table[4]=6
              Table[5]=6
              Table[6]=6
              Table[7]=6
              Table[8]=5
    '          Table[9]=0
              Table[10]=5
    '          Table[11]=0
              Table[12]=4
              Table[13]=6
              Table[14]=6
              Table[15]=6
    And for the main part I tried to use
    Code:
    '#########################################################################################################################
    '#	Subroutines
    '#########################################################################################################################   
    
    Wait2sec: pause 2000
              return
    
    get_input:
              TableIn=PORTA & %00110011                         'Selects the correct input pins
              TableIn=(TableIn & %00000011) + (TableIn & %00110000)>>2
                                                                'Selects A0,A1 then selects A4,A5 moves to A2, A3 and adds to A0,A1
                                                                'Therefore, the array entry is (Command - DPI - Bolt - Deadlck)
              return
    '#########################################################################################################################
    '#	Startmain - where the MAGIC starts!
    '#########################################################################################################################
    Startmain:                                                  'Main wait loop
              gosub get_input                                   'Get inputs
              temp=TableIn
              pause 100
              gosub get_input
              if TableIn <> temp then goto startmain                'Var and temp var did not match so must have been noise, go back
              if TableIn = 9 then
                 if tflag=1 then Main1X
                 unlock=0
                 unsecure=0
                 lock=1
                 pause 2000
                 lock=0                
                 tflag=1
    Main1X:      lock=0
                 unlock=0
                 unsecure=0
                 goto startmain
              endif   
              PORTC=Table[TableIn]                                  'Sets the port output to the table byte
              
              goto startmain                                    'Start all over
    I use the timing function which seems to work for 1 condition but when I type
    if TableIn = 9 or 11 then
    as a substitute for just 1 function, it bombs.
    The time flag beinig reset for all of the other conditions works for 1 condition but not for an OR condition?
    What am I missing now?
    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    If I was doing same thing I'll set outputs as needed on start of event 9 or 11...
    To detect start of event "9" and "11" you can use this code:
    Code:
    IF TableIn=9 AND TableInLast<>9 THEN
    'Here you can do what ever needed
    ELSEIF TableIn=11 AND TableInLast<>11 THEN
     'Sttuf for event 11
    ENDIF
    TableInLast=TableIn
    This way if you have continuous 9 or 11 on input, PIC won't be bricked doing pause...
    PAUSE 2000 will block pic to respond to other input states for 2 seconds. I don't know if that can cause problem... But there is way to make timings without using pauses.
    First set outputs, and then start timer. And on timer interrupt you turn off timer, and set outputs to default state...
    That is pretty easy using DTINT.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Hi,
    but when I type if TableIn = 9 or 11 then as a substitute for just 1 function, it bombs.
    That won't work because what does If 11 then evaluate to? For that to work it needs to be
    Code:
    IF (TableIn = 9) OR (TableIn = 11) THEN
    /Henrik

  6. #6
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Hey There-
    I do have it working - came up late last night and my solution looks pretty much like Enrik's suggestion. Code follows for others to use or learn:
    Code:
    '------------------------------------------------------------------------------------------
    'Variable List
               i                var byte                        'Loop counter var
               Table            var byte[16] BANKA              'Array input is the value of the 4 inputs; 0-15 from the binary weight
               tflag            var table.3                     'timer flag
               TableIn          var byte                        'Entry into array from inputs
               temp             var byte                        'Temp var to use as a debounce
    '---------------------------------------------------------------------------------------------
    '#########################################################################################################################
    '#	We are going to setup this Pig!
    '#########################################################################################################################
    Initialize:                                                   
              unsecure=0                                        'Esures the relay is not active
              lock=0                                            'Ensures lock valve is not active
              unlock=0                                          'Ensures unlock valve is not active
              i=0
              Table[0]=6
              Table[1]=2
              Table[2]=6
              Table[3]=2
              Table[4]=6
              Table[5]=6
              Table[6]=6
              Table[7]=6
              Table[8]=5
    '          Table[9]=0
              Table[10]=5
    '          Table[11]=0
              Table[12]=4
              Table[13]=6
              Table[14]=6
              Table[15]=6
              
              goto Startmain                                    'Steps around the subroutines
    '#########################################################################################################################
    '#	Subroutines
    '#########################################################################################################################   
    
    Wait2sec: pause 2000
              return
    
    get_input:
              TableIn=PORTA & %00110011                         'Selects the correct input pins
              TableIn=(TableIn & %00000011) + (TableIn & %00110000)>>2
                                                                'Selects A0,A1 then selects A4,A5 moves to A2, A3 and adds to A0,A1
                                                                'Therefore, the array entry is (Command - DPI - Bolt - Deadlck)
                                                                'Remembering that Command and DPI are ACTIVE LOW
                                                                'When we get a command to open it is LOW, when door is closed=LOW
                                                                'Bolt and Deadlck posotion sensors are ACTIVE HIGH
              return
    '#########################################################################################################################
    '#	Startmain - where the MAGIC starts!
    '#########################################################################################################################
    Startmain:                                                  'Main wait loop
              gosub get_input                                   'Get inputs
              temp=TableIn
              pause 100
              gosub get_input
              if TableIn <> temp then goto startmain                'Var and temp var did not match so must have been noise, go back
              if TableIn = 9 then
                 if tflag=1 then Main1X
                 unlock=0
                 unsecure=0
                 lock=1
                 pause 2000
                 lock=0                
                 tflag=1
    Main1X:      lock=0
                 unlock=0
                 unsecure=0
                 goto startmain
              endif   
              PORTC=Table[TableIn]                                  'Sets the port output to the table byte
              
              goto startmain                                    'Start all over
    I really like the bit manipulation and the use of the tables - a lot.
    That's the good news, the not so good news is I have discovered 2 conditions which I hadn't counted;
    1. Coming out of the timed function, IF DPI goes from 0 to a 1, I just need to change state of the relay.
    IF after staying at 1, DPI goes back to a 0, then start the timing sequence again....... Dang.
    2. If after the timed section, if DPI=0 AND deadlock goes from a 1 to a 0 just change the relay state.

    Now that I have the truth table, understand the bit manipulation, got the array to work - now I find a 'transitional' state.
    Mickey Mouse logic in its day was pretty involved - almost as interesting as the relay-logic trees!

    Summation, thanks for the assist, I learned quite a number of 'finer' parts of PBP and registers.
    Now I am setting sites on how to know where I am, and watch for certain transitions......

    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  7. #7
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    OK, Ive been thinking (with the aid of a glass of Rye.....) and I was wondering with my re-newed knowledge of arrays if the following would work:
    1. Have built the truth table - works.
    2. Found that there are 'conditionals' within the truth table.
    3. What if (new thought here) that a bit or flag is set in the timing section which turns on or activates another section of table!?
    4. In my example (I will flesh out the table in the AM) that input 9 or 11 are the timed events. If I set a flag which I can add to the base address of 4 bits (a 5th) and use the newly addressed table for the 2 conditionals!!??
    OK, I don't know yet how to do this but tomorrow I will try several trys at this......
    Thoughts?
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

Similar Threads

  1. tables using PBP and asm command retlw
    By queenidog in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th June 2012, 23:47
  2. Help with two lookup tables?
    By awdgsx in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th February 2012, 10:13
  3. Help with look up tables please
    By opticaltrigger in forum mel PIC BASIC
    Replies: 3
    Last Post: - 19th June 2010, 02:54
  4. Re:The Truth about Chernobyl Via Melanie
    By emmett brown in forum Off Topic
    Replies: 1
    Last Post: - 15th August 2006, 09:25
  5. Truth Tables
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th April 2005, 18:35

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