How can I use analog port with card

Hi
I need to use this card to obtain analog signal, mainly pressure, is there any peripheral I can use?

thx in advance.

What card?

I guess the question is can you use ChipworkX to read analog pressure sensor?

There is no built in analog inputs but you can add an ADC chip over SPI bus.

Hi,
thanks to all of you.
Yes, I have chipworkX card.

To Gus:
would you pls make a recommendation of some ADC chip, as I really know little of that. Thx .

There are hundreds or maybe thousands of analog chips. It depends on what you need in your application.

I recently started with a Pcf8591P http://www.farnell.com/datasheets/71768.pdf

It only has 8bit resolution but it’s usable via I2C which I think is a bit easier than SPI.

Another solution, if you don’t want to work with single chips) would be to use one of the cheap GHI boards (Panda2 or Mini) as an extension board, read the Analog data with it and make it available via one of the serial ports. I know it’s overkill if you just need an ADC.

To Gus:
We used this chipworkx board to control an small machine, it’s consist of digital IO and analog IO. All analog just need to read in, like air pressure.

To Xykon:
Thx for your information, I will study this board. I think 8 bit resolution is enough for us.

Maybe start with www.digikey.com and search for ADC.

GHI does offer consulting if you need us to find one and even write the drivers for it.

Hi Gus:

Thx. I will search.
But that’s a limitation of this board. If we successfully extend this card’s application, it also means you can have more customers. :slight_smile:

I also ordered today this one: http://www.sparkfun.com/products/8636

It’s a single 10bit ADC with SPI interface. If you just need one port this one might be easier for you than the 4xADC + 1xDAC chip I mentioned earlier.

I’m planning to work on the I2C chip this weekend and the new one next week as soon as it arrives. Once I have any usable code for either chip I’ll let you know.

I haven’t checked the Code section yet, maybe someone has already provided something? It’s also helpful to look for some Arduino based code. I did that for the digital pot I worked on a while ago and porting the code to C# was extremely easy.

Xykon:

I really appreciate that.
But I may not make it clear. I need analog input to read pressure of some closure, but there are more than one analog lines needed. In all there are about 8 lines. So I need to create a PCB board with 8 chips, right?

It depends on your requirements. Do you need to read all 8 values continuously or can you cycle through the sensors?

You could use a MUX like this one: http://www.sparkfun.com/products/9056 where you can connect up to 16 analog sensors with only one ADC port. You just can’t read all the sensors at the same time, you have to toggle through them.

Otherwise if you use the Pcf8591P it has 4 input lines so you would need two chips. But even there I think you can’t read all 4 values at the same time but you need to read one after the other (need to check the datasheet I posted earlier) though I assume it’s a lot faster than using the MUX.

You are lucky as I already have the MUX breakout I linked so I can give you some pointers on how to use it (although it’s actually extremely simple to use).

You should check through the datasheet of the mux to check how fast it switches between inputs and then check if this delay is acceptable for your application.

Xykon:

That’s good. What I need to is monitor whether the pressure is within a range, if I can read all data in 1s is enough. so a Mux is work for me.

As for multiplexers there are a lot of them available. Beside the one I linked earlier from Sparkfun, there are also some older chips like the Philips HEF4067BP datasheet pdf as a 16 port (De)Mux or the CD4097BE Datasheet(PDF) - Texas Instruments as a differential 8 port version. All these are “old school” DIP versions (standard throughhole) so if you plan on using a PCB that will be easier for you unless you consider professional production.

As for the Pcf8591P I haven’t gotten it to work properly yet, so I’ll wait for the MCP3002 (The 1 port SPI based chip) to arrive and work on that one first, as that is more likely the chip you are going to use anyways.

I just read through the Module description again and found this:

[quote]Touch Screen Controller with ADC:TSC2046 touch controller chip with 2 analog inputs is used to access
touch screen. It is controlled though SPI1. User can utilize the two analog inputs of TSC2046 (VBAT and
AUX) as Analog to Digital converters which are exposed on SV2 header. More analog inputs are also
available when adding XBee module.
[/quote]

So the way I understand it there are two ADC ports available on the CWX dev board.

Are there any Code example on using these two ports?

P.S. I would guess I’d have to access the TSC2046 directly using SPI1 with TC_CS (PB22) as enable pin. Or is there any code in the SDK that would allow us to use this ports without having to do the SPI stuff manually?

Well as for the SPI based DAC from Sparkfun (MCP3002) I believe I got it to work somewhat with the code below.

If you look at the picture, which was made with CH0=VDD, you have the first byte completely zero (which is strange because I didn’t see that in the data sheet), then you have the null bit (this one I expected from the datasheet) and then the 10bit result followed by more zeros.

Now I guess it’s just a matter of properly formating the byte results…

I’ll check on the CWX’ “internal” ADC (touch controller) in the next few days… the data sheet can be found here: http://www.ti.com/lit/ds/symlink/tsc2046.pdf


using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;

namespace SPIDAC
{
    public class Program
    {
        public static void Main()
        {
            SPI.Configuration MyConfig = new SPI.Configuration((Cpu.Pin)ChipworkX.Pin.PB7,false, 0, 0, false, true, 1000, SPI.SPI_module.SPI2);
            SPI MySPI = new SPI(MyConfig);
            byte[] tx_data = new byte[1] {12}; 
            byte[] rx_data = new byte[5];
            
            while (true)
            {
                MySPI.WriteRead(tx_data, rx_data);

                Debug.Print("Output: " + (rx_data[0]).ToString() + " : " + rx_data[1].ToString() + " : " + rx_data[2].ToString() + " : " + rx_data[3].ToString() + " : " + rx_data[4].ToString());
                Thread.Sleep(1000);
            }
        }
    }
}

For adc it is normal that they don’t send the result directly. The first spi clocks after the command are used for acquisition.

Hi, Xykon:

That’s really helpful for your response.
I’d seen the document of ChipworkX about that two analog input’s depiction. But as we also need use touch screen for some UI development. so if we use these two analog ports for processing analog input, the touch screen can still available?

ps: sorry for late response, as I took a holiday.

if you wish to use the touchscreen, then you can not access the 2 ADC on the TSC2046 as the internal drivers for touch prevent you from using the CS pin and thus connecting to the chip.

if you do not wish to use the touch screen, the following code will read the VBat pin. to read the AUX pin, change (0x2 << 4) to (0x6 << 4). (AUX untested)

SPI.Configuration Batconfig = new SPI.Configuration((Cpu.Pin)ChipworkX.Pin.PB22, false, 100, 10, false, false, 1000, SPI.SPI_module.SPI1);
            SPI s = new SPI(Batconfig);
            byte[] buffer = new byte[3];
            buffer[0] = (1 << 7) | (0x2 << 4) | (0 << 3) | (1 << 2) | (3);
            Debug.Print(buffer[0].ToString());
            s.WriteRead(buffer, buffer, 1);
            ushort result = (ushort)((buffer[0] << 4) + (buffer[1] >> 4));
            Debug.Print(result.ToString());