![]() | ![]() | ![]() |
| | |||||||
| Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi All, I posted a while back on the use of the PC parallel port to drive a DAC and ADC as an interface to a variety of sensors/PWM's. I breadboarded a circuit and have written the software in VB6. The DAC chip performed perfectly first time out ( not what I was expecting! ), I can specify a voltage by moving a slider in the software and instantly get a corresponding voltage output. Thanks! | |
| |
| | (permalink) |
| Perhaps you should try to make some simple software to start with. You know; "Barebones". When i make software (highend), i like to make simple little bits of code just to get things to work, and then reprogram it to work in the "big picture". If you are sure that your code is right, then i would also try some different circuits. Maybe some LEDs on the output lines of the ADC? That way you can see what is happening? I have never used an ADC or DAC before, so maybe this is dumb advice, but someone somewhere could use it. Good luck. If you get a chance, maybe you could post some source?
__________________ There is no "I" in "team", unless Apple makes it... Then it would be iTeam. | |
| |
| | (permalink) |
| Hi! Thanks for the reply! Thanks! | |
| |
| | (permalink) |
| Hi, I've written the 'bare-bones' code to drive the ADC. I've attached the code and also the datasheet for the TLC2543. Still no joy, I'm stumped..! Cheers, Salvatore. | |
| |
| | (permalink) |
| hi salvatore, Looked thru your VB code fragment, unable to run it as its not complete. Perhaps a simple question, are using Windows XP, if so you will require a *.dll in your Windows/System directory. I use 'inpout32.dll'. I have written a parallel port test program using VB5, if it would help let me know and I will post it.
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | |
| |
| | (permalink) |
| Hi, I'm using XP Pro and the same inpout32.dll. I've amended the code ( attached ) to include the declarations for the input/output functions so it should now work as is. Incidentally, I had changed the DB25 pin assignments slightly to accomodate the test code and as such I attach the resulting revised schematic. I can drive the TLC5628 DAC in a similar fashion and it works sweet, it's the TLC2543 ADC that's giving me headaches.! Thanks, Salvatore. | |
| |
| | (permalink) |
| hi salvatore, The *.zip includes the source code in VB5, also a *.exe file. The purpose of the program is just to exercise the parallel port I/O. I will re-try your code, I will have to simulate, in some way, the ADC ic. If I get a result I will get back to you.
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ Last edited by ericgibbs; 7th July 2008 at 12:20 PM. | |
| |
| | (permalink) |
| Hi Eric, Thanks for the code! I sent an instruction sequence to the ADC by toggling bit 1 ( DATA 1, Pin 3 ) for the CLK and monitored the output bit 6 ( STATUS 6, Pin 10 ). After running through a number of 12-bit instruction sequences and writing down the output results, I found I was still getting random results. I'm going to have another hard look at the datasheet to see if I've missed something. Thanks again, Salvatore. | |
| |
| | (permalink) |
| hi Salvatore, Look at this, in your coding. ADCResult(0) = Inp(STATUS) ' Read STATUS port and store MSB 'D9 ADCResult(2) = Inp(STATUS) Out DATA, StringToBits("00000100") Out DATA, StringToBits("00000110") Out DATA, StringToBits("00000100") ADCResult(0) = Inp(STATUS);**** Is this statement supposed to be here??, you are changing the state of the MSB to the state of B9 I have inserted some dummy values into your ReadSubr and it gives the correct results. A problem occurs in D9 read block. To test I changed ADCResult(0) to 64' Inp(STATUS) and ADCResult(1 thru 11) to 32' Inp(STATUS), and deleted the *** line. Thus gives a final result value of 2048, which is correct. I expect you know that your code is not optimised and could be reduced in size and also faster. Regards
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | |
| |
| | (permalink) |
| hi, Looking at the ADC setup routine in 'ReadVoltage', if I am reading page #14 of the datasheet correctly, the setup is addressing AIN3. You appear to be using AIN0 as a 2.5Vref test value?. Page #14 also states its an 8 bit function select byte, you are adding, 4 padout bits? On page #12 of the datasheet, 'Principles of Operation' it again states its an 8 bit control data stream. On page #9 it states that the data I/O is simultaneous, you are addressing and reading sequentially? You appreciate that unless I have a device to test with your program, I have to take all my information from the datasheet. The way I read the datasheet, you are not controlling it in the way it describes. Regards.
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | |
| |
| | (permalink) |
| Hi Eric, Thank you for your patience! You are right in pointing out the mistake in the code I posted. In actual fact the code itself does not contain this error, it was introduced after cutting and pasting the code into Notepad and making a few adjustments to pretty it up..! Sorry! In answer to your query about the 8-bit function select byte, the ADC allows 3 choices in terms of length of the instruction sent to it depending on the type of serial communications mechanism you are using, 8-bit, 12-bit( recommended as the ADC has a 12-bit resolution), and 16-bit ( see page #15 - Principles of Operation - data output length). The function select byte is 8 bits which in my case has to be padded to 12 bits. There is a timing diagram on page #9, figure 9 which is the control scenario I am trying to implement. In answer to your other query about the ADC being simultaneous, yes it has been designed this way for fast operation. As you are sending an instruction, the result of the previous conversion is shifted out, so the desired result lags behind by one instruction sequence. In my code, I send the instruction twice, the first is the 'real' instruction, the second as a 'dummy' to get access to the result. Although not in the datasheet, the method I'm using is actually recommended in the manufacturers application notes if all you are interested in is 'one-shot' conversions. If you are trying to convert a fast continuously varying signal then the simultaneous method is obviously recommended for speed. I've tested the attached code and am still getting spurious results as before. Thanks, Salvatore. Last edited by saiello; 22nd June 2007 at 03:52 PM. | |
| |
| | (permalink) |
| When I was working with ATMega16's ADCs I faced a similar kind of problem. The output was very unstable. Later I found out that in the breadboard the voltage of the ground rail was 150mV. May be yours is the same problem. | |
| |
| | (permalink) |
| hi salvatore, Try this code, add to the Form, 1 sec Timer and a Text1 box. This works using the parallel port and a project board. The ADC is simulated. Code: Option Explicit
Dim DATA
Dim STATUS
Dim ADCValue As Single
Dim Ary(12) ' for precalculated power values
Private Sub Form_Load()
DATA = &H378 ' LPT1 port address
STATUS = &H379 'STATUS port address
MakeAry
End Sub
Private Sub MyRead()
Dim Rd, iADCValue, V As Integer
Dim t As Long
'this routine,selects ADC0, 12 bit data, msb 1st, binary, NOT using /CS as Page #9
'remember to allow for EOC time out
For Rd = 0 To 11
V = Inp(STATUS) And 64
If V = 0 Then GoTo skip1
iADCValue = iADCValue + Ary(Rd)
skip1:
Out DATA, 0 'ck=lo, cs=lo, dta=lo
Out DATA, 2 'ck=hi, cs=lo, dta=lo
Out DATA, 0 'ck=lo, cs=lo, dta=lo
Next Rd
ADCValue = iADCValue
End Sub
Private Sub MakeAry()
Dim z As Integer
For z = 11 To 0 Step -1
Ary(z) = 2 ^ z
Next z
End Sub
Private Sub Timer1_Timer()
MyRead
Text1.SelText = "Decimal= " & ADCValue & " Vadc= " & (ADCValue / 4095) * 5 & vbCrLf
End Sub I'll look thru your latest *.zip Regards
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | |
| |
| | (permalink) |
| Hi Eric, Neat bit of code! For Rd = 0 To 11 ' Add any code here.. e.g. Wait 0.001 V = Inp(STATUS) And 64 If V = 0 Then GoTo skip1 iADCValue = iADCValue + Ary(Rd) skip1: ' ..or here.. e.g. DoEvents Out DATA, 0 'ck=lo, cs=lo, dta=lo Out DATA, 2 'ck=hi, cs=lo, dta=lo Out DATA, 0 'ck=lo, cs=lo, dta=lo ' .. or here with this bit of code.. For n=0 to 100 Next Next Rd What's even more interesting is that if I reduce the extra loop to n=0 to 10 for example, I get back the more stable results as mentioned above...! "..The conversion cycle is transparent to the user, and it is controlled by an internal clock synchronized to I/O CLOCK..". How any internal clock can synchronise with an externally applied clock of indeterminate frequency I don't know.. Maybe it has no bearing on the problem... Hmmm.. Thanks again, Salvatore. | |
| |
| | (permalink) |
| hi Salvatore, By inserting a DoEvents, which you should have in any long loop, Windows can 'insert' its other event any where in the loop. If you have an oscilloscope to monitor the port output pins, you will see the output pulses are not 'equally' spaced in time, which in some external circuits can cause timing problems. According the specsheet the ADC clk can be from 0 thru 4MHz, so I would not expect the timing problem you are getting. Making an array with the bit weightings precalculated makes the sums and program easier/faster. What you could do, is to load a picture box into the Form and place a preprepared 'graticule' image in the picbox and let the program draw the out and inp pulses to the picbox. This will give you an insight into what is happening. Of course its just for testing, like an oscilloscope. I have use this method a number of times when trying to sort out port timing relationships. Regards
__________________ Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Parallel port control port: is it Write Only or Read/Write | elexhobby | Electronic Projects Design/Ideas/Reviews | 6 | 23rd December 2008 11:18 AM |
| Need help badly on Inchworm and MPLAB | thushy | Micro Controllers | 14 | 11th March 2007 07:05 PM |
| I need: Parallel Port.. examples and applications.. | sonaiko | General Electronics Chat | 8 | 28th October 2006 02:44 PM |
| PIC 2 PC: Parallel (Port) Read | Electrix | Micro Controllers | 8 | 31st July 2005 05:24 PM |
| Multiple devices controlled at once on one parallel port | Kerri Ann | Electronic Projects Design/Ideas/Reviews | 0 | 18th February 2005 11:52 AM |