Truth Tables in PBP


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    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.

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


    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

  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

    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

  4. #4
    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

  5. #5
    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
    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?
    Good thinking! Maybe I should try Rye.

    Obviously you could use all of the upper nibble as flags giving four sets of special cases if you set them as individual bits. By using the upper nibble as a value then fifteen special cases would be available.

    One complication, there is always at least one,

    TableIn=PORTA & %00110011

    TableIn is reset every time and the bits are manipulated. Obviously there is a workaround. More thinking is required, or Rye?

  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

    Ha! Clearly more of BOTH would be encouraged.......
    I'm re-making the truth table with the conditionals. I've always been better at diagramming and such - I'm sure a pattern may arise.
    Once I have the new 'map' I'll see what I can do.
    As far as TableIn=PORTA & %00110011, The dirty little secret DT showed me may come in handy for the INPUTS as well as it has for the OUTPUTS.
    The 'trick' is that the IO is sequential in the memory map, so, just set the base address:
    SYMBOL IN_PORT_PIN=PORTA ' starting address
    for x=0 to 4 'only 5 inputs for this chip
    IN_PORT_PIN.0=[x]
    next x

    OR just use alias - but that does 'bloat' the code......
    "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-
    I've worked on this for a bit (no pun) and now I am finding out what the 'conditionals' are are actually edge-triggered events.
    I have code which works using flags and if-then-endif style, but my real question is does DT's Instant Interrupts work not only on level conditions - but also for edge level??
    I have gone to his page and looked it over, but I do not see any reference to edge-level interrupts.
    Should I now start a new thread?
    "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, 22:47
  2. Help with two lookup tables?
    By awdgsx in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th February 2012, 09:13
  3. Help with look up tables please
    By opticaltrigger in forum mel PIC BASIC
    Replies: 3
    Last Post: - 19th June 2010, 01:54
  4. Re:The Truth about Chernobyl Via Melanie
    By emmett brown in forum Off Topic
    Replies: 1
    Last Post: - 15th August 2006, 08:25
  5. Truth Tables
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th April 2005, 17: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