Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/07/04 23:12
Read: times


 
#68125 - MCP3221 A/D converter
I've been having problems getting my a/d converter (microchip mcp3221) working with my at89s8252. I've tested the hardware over & over again, it is set up perfectly... The voltage & ground pins test out exactly 5v + & ground, the analog input varies between 2 & 4.5 volts as the input dictates, and I set up a little program to display when the inputs were high or low, then manually stimulated (grounded or released) them and they displayed perfectly. However, when I run it, it ALWAYS reads all bit high. The display routine is working because it shows the value that corresponds to all bits high normally, then when I ground the data pin, it dislays the value that corresponds to all bits low. So, as far as I can tell, it *HAS* to be software. so if anyone can look over my routine & see what kind of silly mistake I'm doing, it would be sooo nice! Anyway, relevant code follows:

VCPORT.VCBIT - this is the clock output bit
VDPORT.VDBIT - This is the data i/o bit


DISVOLT: ; clear clock
clr VCPORT.VCBIT ; To prevent sending a "stop" when data comes up
setb VDPORT.VDBIT ; set data high
SETB VCPORT.VCBIT ; set clock high
DISVOLT2: ;
JnB VDPORT.VDBIT,DISVOLT2 ; wait until all otuputs are high (this will catch 'busy')
JnB VCPORT.VCBIT,DISVOLT2 ;
CLR VDPORT.VDBIT ; clr data while clock high for a 'start' signal
NOP ;
CLR VCPORT.VCBIT ;
mov A,#10101011b ; 4-bit device code, 3-bit ID, and 'read' bit.
ACALL BYTESEND ; send that byte
ACALL ACKSTART ; Acknowledge the byte
ACALL BYTEREAD ; read next byte (routine has ack built in)
ANL a,#0fh ; ignore top half of byte (unused)
mov VOLTH,A ; save in VOLTH variable
ACALL BYTEREAD ; read next byte (built in ack)
mov VOLTL,A ; save in VOLTL variable
ACALL ACKSTOP ; send stop condition
acall displayout ; output to LCD
ret ;
;
BYTESEND: ;
mov B,#8d ; set to run through bit routine 8-times
BITSEND: ;
rlc A ; mov c into msb of A, all other bits left
mov VDPORT.VDBIT,c ; set data to this bit's value
nop ; give 1 cycle for value assurance on output
setb VCPORT.VCBIT ; set clock high
acall Wait5us ; wait 5 microseconds
clr VCPORT.VCBIT ; clear clock
acall Wait5us ; wait 5 microseconds
djnz b,BITSEND ; repeat until count is 0
RET ;
;
BYTEREAD: ;
SETB VDPORT.VDBIT ; set data high (input)
mov B,#8d ; set to run bit 8x
BITREAD: ;
setb VCPORT.VCBIT ; set clock cycled high
acall Wait5us ; wait 5 microseconds
mov c,VDPORT.VDBIT ; put value from databit in c
rlc A ; move into lsb of A, rotate a left
clr VCPORT.VCBIT ; clear clcok
acall Wait5us ; wait 5 microseconds
djnz b,BITREAD ; repeat 8x
CLR VDPORT.VDBIT ; clear datapin for input ack
nop ; wait 1 clock cycle for output assurance
SETB VCPORT.VCBIT ; set clock pulse
acall Wait5us ; wait 5 microseconds
CLR VCPORT.VCBIT ; clear clock pulse
acall Wait5us ; wait 5 microseconds
RET ;
;
ACKSTART: ;
CLR VDPORT.VDBIT ;
nop ;
setb VCPORT.VCBIT ;
acall Wait5us ;
clr VCPORT.VCBIT ;
acall Wait5us ;
ret ;
ACKSTOP: ;
clr VDPORT.VDBIT ;
acall Wait5us ;
setb VCPORT.VCBIT ;
NOP ;
SETB VDPORT.VDBIT ;
NOP ;
RET ;
;
Wait5us: ;
nop ;
nop ;
nop ;
ret ;


List of 7 messages in thread
TopicAuthorDate
MCP3221 A/D converter            01/01/70 00:00      
   RE: MCP3221 A/D converter            01/01/70 00:00      
   RE: MCP3221 A/D converter            01/01/70 00:00      
      RE: MCP3221 A/D converter            01/01/70 00:00      
   RE: MCP3221 A/D converter            01/01/70 00:00      
      RE: MCP3221 A/D converter            01/01/70 00:00      
         RE: MCP3221 A/D converter            01/01/70 00:00      

Back to Subject List