Shop OBEX P1 Docs P2 Docs Learn Events
instruction speed, AtoD conversion — Parallax Forums

instruction speed, AtoD conversion

PhilippineEaglePhilippineEagle Posts: 8
edited 2010-12-06 07:22 in BASIC Stamp
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-27 22:47
    Look at Emesystems' website (here) for information on a variety of Basic Stamp issues. Use the "app-notes" link at the bottom of the page. There's a section on the execution time of various statements for several of the Stamp models including the statements you're interested in.
  • PhilippineEaglePhilippineEagle Posts: 8
    edited 2010-11-29 15:16
    Mike Green wrote: »
    Look at Emesystems' website (here) for information on a variety of Basic Stamp issues. Use the "app-notes" link at the bottom of the page. There's a section on the execution time of various statements for several of the Stamp models including the statements you're interested in.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-29 16:02
    The PULSOUT statement is specifically designed to produce pulses of a specified width based on one of the parameters supplied to the statement. The unit (for the BS2) is 2us, so you can specify a pulse width up to about 128ms (a count of 65535). The 20us may be overhead so you may have to adjust the pulse width downwards by a small count. I don't have the EmeSystems document in front of me, so I'm not sure, but I'd go with their measurements. The 220us fetch/initialization time is also about right. If you need some way to stretch this out, you'd have to add some kind of delay while the pulse remains low. For millisecond resolution, use PAUSE. For other delays, use dummy statements like making an I/O pin an output or input when it's already in that mode. That'll give you about 140us.
  • PhilippineEaglePhilippineEagle Posts: 8
    edited 2010-12-04 22:42
    Mike Green wrote: »
    The PULSOUT statement is specifically designed to produce pulses of a specified width based on one of the parameters supplied to the statement. The unit (for the BS2) is 2us, so you can specify a pulse width up to about 128ms (a count of 65535). The 20us may be overhead so you may have to adjust the pulse width downwards by a small count. I don't have the EmeSystems document in front of me, so I'm not sure, but I'd go with their measurements. The 220us fetch/initialization time is also about right. If you need some way to stretch this out, you'd have to add some kind of delay while the pulse remains low. For millisecond resolution, use PAUSE. For other delays, use dummy statements like making an I/O pin an output or input when it's already in that mode. That'll give you about 140us.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-05 14:25
    Download and read Chapter #3 in the "Basic Analog and Digital" tutorial (here). It's for the ADC0831 ADC, but the only difference is the 4 bits sent to the ADC initially to configure it. You could make your PULSOUT longer if you want by changing the 10 (20us) to something larger.

    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.
  • PhilippineEaglePhilippineEagle Posts: 8
    edited 2010-12-06 07:22
    Mike Green wrote: »
    Download and read Chapter #3 in the "Basic Analog and Digital" tutorial (here). It's for the ADC0831 ADC, but the only difference is the 4 bits sent to the ADC initially to configure it. You could make your PULSOUT longer if you want by changing the 10 (20us) to something larger.

    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.
Sign In or Register to comment.