![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| hello all... I am just starting out with PIC....i'm beginner..... i just built jdm programmer and excited to buit a simple project... i did simple led flasher...and its working..very happy my question is... i'm going to build the circuit that have 6 inputs and 4 outputs.... and i have my truth table to implement my circuit.... by using and gate and or gate ...i need 3 ics to implement my design... so..i'm looking to replace these ics with pic16f84a... how do i implement the truth table in PIC?...and how to use the lookup table in PIC?... pls guide me.... thanks | |
| |
| | (permalink) |
| If possible, derive the equation for your logic. Well, then, write a program to get the input, and use the equation, get the answer, and output it to your pins. | |
| |
| | (permalink) |
| the thing you are talking about is usually implemented using programmable logic devices PLD (PALs, GALs, SPLDs or CPLDs). although it could be implemented using PIC. using a PIC to work like 5 or 6 gates isnt that cost effective. u should use some type of PLD for this. u can program this very easily in Abel or similar programming languages. | |
| |
| | (permalink) |
| This reminds me of an ancient application note of Microchip which does exactly what you intend to do. It's for the PIC16C5X which is an earlier version of the PIC16F84. You can easily port this to the '84 which still has the obsolete TRIS instruction. http://www.microchip.com/stellent/id...pnote=en010976
__________________ "Having to do with Motion Control" | |
| |
| | (permalink) |
| If you just want to play around you can use this as a lookup table. Just make sure you don't run over the 8-bit boundry, lookup up the microchip appnote that deals with implementing a table read for more info on that. call the lookup with your data in Wreg Code: lookup movwf pcl,f retlw 0x01 retlw 0x02 retlw 0x03 retlw 0x04 retlw 0x05 . . . Ron | |
| |
| | (permalink) |
| It should be ADDWF PCL, F at the top | |
| |
| | (permalink) |
| Opps sorry yes you're right, typo. Should be addwf,pcl,f. Also it doesn't have to be Retlw instructions either you could just as well place goto's in there. (as long as the subs you go to have returns at the end) Ron | |
| |
| | (permalink) | |
| Quote:
I think the first action here is to study what actually needs to be done, it's all right saying a truth table was used originally - that isn't to say that's the best way to solve the problem - it may well just be a consequence of the logic chips used. | ||
| |
| | (permalink) | |
| Quote:
regarding the RETLW instruction... can i just simply.. ask pic to check the input then..look up to the table (retlw..) then ask pic to write to the output...? thanks.. | ||
| |
| | (permalink) | |
| Quote:
Something like this: Code: movf PortA, w ; read PortA into W andlw b'00000111' ; make sure value not larger than 7 call Table ; get entry from table movwf PortB ; and output to PortB | ||
| |
| | (permalink) | |
| Quote:
Code: main movf PortA, w ; read PortA into W
andlw b'00111111' ; table limits?...6 inputs...64 entries
call Table ; get entry from table
movwf PortB ; and output to PortB
Table addwf pcl,f
retlw 0x0
.
.
.
return my equation is y0 = x5&x2 + x5&x1&x0 + x4&/x3&x2 y1 = x5 + x4&x3&x2 y2 = x2 + x5&x3 + x5&x4 y3 = x5 + x4&x3&/x2 ... pls guide me thanks | ||
| |
| | (permalink) | |
| Quote:
However, it will be considerably slower than the table method!. | ||
| |
| | (permalink) |
| hi... i'm sorry....i try to write the code to implement my 'lookup table'...actually this is my first time writting the code.... after click "build all" i got this message Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F84A "digital.asm" /l"digital.lst" /e"digital.err" Message[302] C:\PROGRAM FILES\MPLAB IDE\MYPROJ\DIGITAL.ASM 79 : Register in operand not in bank 0. Ensure that bank bits are correct. Message[302] C:\PROGRAM FILES\MPLAB IDE\MYPROJ\DIGITAL.ASM 81 : Register in operand not in bank 0. Ensure that bank bits are correct. Error[113] C:\PROGRAM FILES\MPLAB IDE\MYPROJ\DIGITAL.ASM 87 : Symbol not previously defined (pcl) Halting build on first failure as requested. BUILD FAILED: Wed Jun 16 12:03:59 2004 and my code is like this: Code: ;********************************************************************** list p=16F84A ; list directive to define processor #include <p16F84A.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS STATUS EQU 03h ; variable used for context saving TRISA EQU 85h ; variable used for context saving PORTA EQU 05H TRISB EQU 86h PORTB EQU 06h ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location main bsf STATUS,5 ; bank 0 -----> bank 1 movlw b'00111111' ; set the port a as inputs movwf TRISA ; movlw b'11110000' ; set the port b as ouputs movwf TRISB bcf STATUS,5 ; bank 1 -----> bank 0 movf PORTA,w andlw b'00111111' call table movwf PORTB table addwf pcl,f ; inputs outputs retlw b'0000' ; 0 retlw b'0000' ; 1 retlw b'0000' ; 2 retlw b'0100' ; 3 retlw b'0100' ; 4 retlw b'0100' ; 5 retlw b'0100' ; 6 retlw b'0100' ; 7 retlw b'0000' ; 8 retlw b'0000' ; 9 retlw b'0000' ; 10 retlw b'0100' ; 11 retlw b'0100' ; 12 retlw b'0100' ; 13 retlw b'0100' ; 14 retlw b'0100' ; 15 retlw b'0000' ; 16 retlw b'0000' ; 17 retlw b'0000' ; 18 retlw b'0100' ; 19 retlw b'0101' ; 20 retlw b'0101' ; 21 retlw b'0101' ; 22 retlw b'0101' ; 23 retlw b'1000' ; 24 retlw b'1000' ; 25 retlw b'1000' ; 26 retlw b'1000' ; 27 retlw b'0110' ; 28 retlw b'0110' ; 26 retlw b'0110' ; 30 retlw b'0110' ; 31 retlw b'1010' ; 32 retlw b'1010' ; 33 retlw b'1010' ; 34 retlw b'1011' ; 35 retlw b'1111' ; 36 retlw b'1111' ; 37 retlw b'1111' ; 38 retlw b'1111' ; 39 retlw b'1110' ; 40 retlw b'1110' ; 41 retlw b'1110' ; 42 retlw b'1111' ; 43 retlw b'1111' ; 44 retlw b'1111' ; 45 retlw b'1111' ; 46 retlw b'1111' ; 47 retlw b'1110' ; 48 retlw b'1110' ; 49 retlw b'1110' ; 50 retlw b'1111' ; 51 retlw b'1111' ; 52 retlw b'1111' ; 53 retlw b'1111' ; 54 retlw b'1111' ; 55 retlw b'1110' ; 56 retlw b'1110' ; 57 retlw b'1110' ; 58 retlw b'1111' ; 59 retlw b'1111' ; 60 retlw b'1111' ; 61 retlw b'1111' ; 62 retlw b'1111' ; 63 goto main END ; directive 'end of program' actually what is the problem..? pls help me find the problem... thanks | |
| |
| | (permalink) |
| Try changing 'pcl' to 'PCL', the other messages are just warnings, not errors. | |
| |
| | (permalink) |
| Just a comment on the topic of lookup tables vs. performing calculations in real time. It doesn't have to be all of one or the other. In general, if there are more than a few inputs, there's a noticable tradeoff between speed and storage space (lookup tables -> highest speed, large storage requirements, calculations -> lowest speed, minimal storage). For many non real time cases, it doesn't matter which method you choose, since the resources used (time, storage space) are minimal and the differences aren't visible to the end user. In some applications, making a tradeoff between tables and equations can result in a better use of resources. Here's an example. Cubic interpolation often provides a better approximation to real world data than simple linear interpolation. The author claims that one quadrant of a sine wave can be approximated to better than 16-bits of precision using only 19 table entries. There is some simple math involved for the micro, IMO it's a great example of making good tradeoffs. - Claude http://www.reed-electronics.com/ednm...1695/04di2.htm here's the original, in forth :wink: http://www.tinyboot.com/cubic.txt | |
| |