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!
    While all are better than what I was playing with, I like the array scheme. I just don't do enough arrays to keep them front and center in my head.
    Unfortunately, I didn't have the presence of mind to neatly stack the inputs into a nibble on a port..... using A0, A1, A4, and A5 on a 16F616
    I do understand the philosophy, but there is one wrinkle; there are 2 cases in which I need to a pin high, time out for 2 sec and then go low. If the condition on the inputs pins stays the same, the timed pin just stays high.
    I even used DT's instant interrupts (so cool) to time the pin but that didn't seem to work.
    This should be so easy, but I am missing something and its probably so visible that I can't see it!
    What I get when I test my primitive code is the LEDs flash (I use them for debugging) and the timed pin never times out UNTIL the input condition changes. Snippit below:
    Code:
              if command=1 and dpi=0 and bolt=1 and deadlck=1 then                 
                    t1=0 : t2=0 : t3=1     'leds
                    if tflag=1 then Main1X    'been here before so step around
                    unlock=0
                    unsecure=0
                    lock=1     'Turn ON sol
                    t1=0 : t2=1 : t3=0
                    pause 2000     'wait 2 sec
                    t1=0 : t2=1 : t1=1
                    lock=0     'Turn OFF sol                
                    tflag=1     'We did it so set flag
                    t1=1 : t2=0 : t3=0
    Main1X:         t1=1 : t2=0 : t3=1
                    unlock=0
                    unsecure=0
              endif
    "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

    t2 is the timed pin?

    is tflag being reset to 0 elsewhere in your code?

    Like you I see no problem with this snippet.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    Could be RMW issue if those T# are on same port, better in that case to change them all at once like PortB=%00000100 PortB = %00000011
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    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
    Thanks Guys!
    While all are better than what I was playing with, I like the array scheme. I just don't do enough arrays to keep them front and center in my head.
    Unfortunately, I didn't have the presence of mind to neatly stack the inputs into a nibble on a port..... using A0, A1, A4, and A5 on a 16F616
    There are ways around this.

    One is to use maths

    myvar=PORTA.0+PORTA.1*2+PORTA.4*4+PORTA.5*8

    Another way is bit manipulation

    myvar=PORTA & %00110011 ' select the input pins
    myvar=(myvar & %00000011) + (myvar & %00110000)>>2 'selects A0,A1 then selects A4 and A5 moves then to A2 and A3 and adds to A0,A1

    Another way is to set Aliases for the pins which relate to myvar. I will let you look into that one and I am sure there must be other workarounds.

    Then myvar can be used in LOOKUP to set an output pattern or used in SELECT CASE or IF THEN, the choice is yours.

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

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

  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

    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

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

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    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

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