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

    Default Truth Tables in PBP

    Hey Everyone-
    I have queried this forum and have not found much in this area.
    I am attempting to 'clone' a logic board which cannot be purchased any longer and is no longer supported for a client. I have all the inputs and results for outputs but my main question is has anyone used a micro in place of logic gates?
    I have tried a couple of ways to provide inputs using IF/THEN type statements but it seems clunky and verbose.
    Almost think there may be a way to map inputs to EEPROM locations and read data straight out........
    Its pretty small; only 4 inputs and 3 outputs and a timing function of 2 seconds.
    Curious if anyone has tried to do this?
    Thanks in advance for any insight!
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    four inputs
    could be
    a var portb.0
    b var portb.2
    c var porta.3
    d var portc.3

    outputs could be
    e var portc.0
    f var portc.1
    g var portc.2

    formula e = a or b and c ,f= d and c or b, g = b and c and d

    code
    e = (a or b)and c
    f= (d and c) or b
    g=(b and c)and d

  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

    Select case cleans up on multiple if/then applications, on goto and on gosub work too.
    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
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Truth Tables in PBP

    If you need fast response you can create tables using arrays.
    For 4 bit system you have 16 different states, so you create array which hold data for output for every 16 states. And use 4 bits of ports for inputs, and outpust, eg portb0 to Portb3 is inputs, portA0 to 3 are outputs.
    TruthTable var byte[16] BANKA'So pbp doesn't need to put banksel after each command
    TruthTable[0]=%00001111
    TruthTable[1]=%00001100
    etc...
    TruthTable[15]=%00001111
    TRIS...
    ANSEL
    ETC..
    Tmp Var byte BANKA
    Main:
    Tmp=portb & %00001111
    porta=TruthTable[Tmp]
    goto Main
    This will give almost fastest response for given clock speed.
    If you grounded upper nibble, this give you fastest possible responese
    Main:
    porta=TruthTable[portb]
    goto Main
    If speed isn't critical you can assign bits to Tmp variable from any pin...
    Last edited by pedja089; - 30th August 2014 at 09:41.

  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!
    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

  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

    t2 is the timed pin?

    is tflag being reset to 0 elsewhere in your code?

    Like you I see no problem with this snippet.

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

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

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

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 : 1

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