instruction speed, AtoD conversion
I have a BS2, revision G. I'm trying to interface my BS2 with an A/D converter, specifically an ADC0832, and I can't make it work perfectly. The sequence of instructions are:
HIGH A2dChipSel ' Disable A/D ChiP SELEct
LOW A2dDataIn ' Initial state of data in
LOW A2dClk ' Initial state of clock
a2dResult = 0 ' Clear the 8-bit result
A2D_Start_Conversion: ' Start the conversion process
LOW A2dChipSel ' Enable A/D chip select
A2D_Shift_Out_Channel_ID: ' Shift out the Channel ID value
SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId\4]
A2D_Shift_In_Result: ' Shift in the result
PULSOUT A2dClk,10
SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult\8]
HIGH A2dChipSel ' Disable A/D chip select
I am just wondering how long does it take before the basic stamp goes from one instruction to the other? For instance in the code above, after executing 'LOW A2dChipSel', how long before the next SHIFTOUT instruction is carried out?
Secondly, the A2dDataIn has to come out first for a setup time of 250ns before A2dClk is pulsed out. Can I assume that is followed?
HIGH A2dChipSel ' Disable A/D ChiP SELEct
LOW A2dDataIn ' Initial state of data in
LOW A2dClk ' Initial state of clock
a2dResult = 0 ' Clear the 8-bit result
A2D_Start_Conversion: ' Start the conversion process
LOW A2dChipSel ' Enable A/D chip select
A2D_Shift_Out_Channel_ID: ' Shift out the Channel ID value
SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId\4]
A2D_Shift_In_Result: ' Shift in the result
PULSOUT A2dClk,10
SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult\8]
HIGH A2dChipSel ' Disable A/D chip select
I am just wondering how long does it take before the basic stamp goes from one instruction to the other? For instance in the code above, after executing 'LOW A2dChipSel', how long before the next SHIFTOUT instruction is carried out?
Secondly, the A2dDataIn has to come out first for a setup time of 250ns before A2dClk is pulsed out. Can I assume that is followed?
Comments
Thanks, Mike, for your reply. From the information in the website you provided, it seems that the SHIFTIN and SHIFTOUT timing is acceptable. The ADC0832 requires at least a 10KHz clock with 40-60% duty cycle. The SHIFTIN and SHIFTOUT give a 16KHz data tranmission rate so it's ok. It's the PULSOUT command that seems to be causing the problem. The instruction fetch requires about 220us and then the output stays high for only 20us. Is there a way around this so that the duty cycle or high point duration is 50% of the total period?
Will appreciate your reply.
Thanks, Mike for your reply. But this will solve only half of the problem. The ADC0832 has two requirements:
1) 40-60% duty cycle
2) 10-400Khz CLK input frequency for the conversion
If we add more delays, item#1 above will be solved. But at the current execution time Tp where
Tp = 220us + 20us = 240us
the CLK frequency amounts to 4.2Khz, which is below the minimum of 10Khz.
By the way, what ADC do you recommend will work well with the Basic STAMP based on users' input? This ADC0832 was the recommended IC in the renewable energy track that was up before in the Parallax website.
Parallax has switched to using the MCP3204 and MCP3208 ADCs, mostly because they have 12-bit accuracy rather than 8-bit and they can run at 3.3V as well as 5V for direct compatibility with the Propeller as well as the Stamps. The ADC083x ADCs are perfectly fine for 5V systems where 8-bit accuracy is enough.
You never did say what's wrong.
I used the code just posted. Than attached a resistor divider with potentiometer to CH0 or CH1 of the ADC0832. The output I get using Stamplot is just a 5V line even though I move the potentiometer's dial so the voltage varies from 0.5 to about 4.5V. At any rate, thanks for your input. I'll doublecheck my connections.