Today was a busy day, yet productive one for me. I, together with my groupmate Tino, was able to finalize our project which is an ADC converter interfaced using a Parallel Port.
In lieu to this, I decided to share the enhanced C++ source code along with the compiled program for the benefit of everyone (Remember that the rationale for this blog is sharing!).
Link: http://rapidshare.com/files/370753131/ADC_interface.zip
Enjoy!...
Since everything is a consequence of purpose, the purpose of this blog is to contain as much information that is available to be shared.
Showing posts with label parallel port interfacing. Show all posts
Showing posts with label parallel port interfacing. Show all posts
Thursday, April 1, 2010
Sunday, March 28, 2010
Entry 1: Interfacing ADC using Parallel port with Python
This Python code will suffice the need of interfacing an ADC (analog-to-digital converter) using a Parallel Port. Tested with ADC0804 (8-bit ADC ).
'''This module facilitates ADC interfacing in Python using a Parallel port'''
__author__ = 'Aivin V. Solatorio'
import parallel
import ctypes
_ppt = ctypes.windll.simpleio
_ppt.init()
class ParallelADC(object):
'''Definition of ADC interfacing class'''
def __init__(self):
self.dataAdr = 0x0378
self.statAdr = self.dataAdr + 1
self.ctrlAdr = self.dataAdr + 2
def getData(self):
'''Acquires signal from data register'''
return _ppt.inp(self.dataAdr)
def setCtrl(self, val):
'''Dictates the value of control register'''
_ppt.outp(self.ctrlAdr, val)
def getStat(self):
'''Acquires value of status register'''
return _ppt.inp(statAdr)
'''Start of data gathering'''
gather_time = 100 #100 number of sample points
ADC = ParallelADC()
for i in xrange(gather_time):
lc = 0
ADC.setCtrl(0x32) #initializes ADC to start
ADC.setCtrl(0x36) #converting signal
while ((ADC.getStat() & 8) == 0) and (lc != 256):
lc += 1 #wait for ADC to finish converting
if (lc == 256):
print "Timed Out, check device or connection!"
else:
ADC.setCtrl(0x37)
value = ADC.getData() & 0xFF
ADC.setCtrl(0x36)
print "The ADC reading is: ", value #prints out ADC value
Subscribe to:
Posts (Atom)