A/D Converters and a Simple IDE Question
Can someone post an example of code for using an A/D converter? I have a Quickstart Rev.A, and I'm trying to learn how to use C to program it. (It would be a bonus if you would also explain how the code works)
Also, I was wondering if you could reference another program with C in Simple IDE, and if that other program had to be in C or if it could be in Spin?
Thanks in advance!
Also, I was wondering if you could reference another program with C in Simple IDE, and if that other program had to be in C or if it could be in Spin?
Thanks in advance!
Comments
Do you have a particular A/D converter in mind?
If you use an ADC with an I2C bus, you can save some I/O pins and put the ADC on the I2C pins used for the EEPROM. An SPI bus is usually faster. If the ADC is slow, SPI won't make much difference.
Remember that you can use a pair of Propeller I/O pins as an ADC. Look at the application note on the cog counters for more information and a Spin object that provides the ADC functionality.
You might use the Board of Education or the Activity Board as models. Both have ADCs and the schematics are downloadable. Both are supported for tutorials and code examples.
forums.parallax.com/discussion/comment/1315065/#Comment_1315065
The full thread is my adventures in learning how to make a C library that uses some PASM from a SPIN object.
There is also a simple SPI function in the libraries that come with SimpleIDE (in the simpletools library). It's just not that fast, which for your application may not be an issue. There is an example (but different type) that uses that library here:
learn.parallax.com/propeller-c-simple-protocols/spi-example
There are also a couple of examples in the OBEX. One of the simplest that does not use PASM is at:
obex.parallax.com/object/78
It prints the result to an LCD (which I don't have, but you could examine the Spin file for the ADC to see how to send commands and read data.
I hope this gives you a starting point.
Tom
If you need high precision and are OK with a few tens of sps, get the NAU7802; it's an I2C 24-bit sigma-delta in a DIP for about $2.50 the last time I checked. I've written a driver for it, but it's untested since I found that I could get what I need by using 1024-4096x oversampling with the MCP3304 and save board space, pins, & $$, since I needed it anyway. In any case, the NAU7802 uses standard I2C, so you can use the Simple Library functions to access it; the dedicated driver I wrote for it to maximize communication speed is superfluous when you're only getting a maximum of 80 sps (for 18 bits; 10 sps for 22 bits).
I've written an object for the MCP3xxx series ADCs in PropWare. You can find the example project here, which uses channel 1 of an MCP3000. To work with the MCP32xx series ADCs, simply change line 31 from
to
and you'll be good to go. If you'd like help gathering all of the files necessary to make this work in SimpleIDE, let me know and I can upload a SimpleIDE archive.
twm47099 already gave the link for SPI with C so here is the link for I2C.
http://learn.parallax.com/propeller-c-simple-protocols/diy-i2c
Unfortunately neither example involves an ADC but a very easy to use one is the ADC0831.
You can find numerous examples of BS2 code for the ADC0831 and Propeller C has both the shiftin and shiftout functions that work just like the BS2 commands.
Sometimes you don't even need an ADC.
Mike Green mentioned using only 2 Propeller pins in what's called Sigma-Delta but I myself am not familiar with how it works.
I myself was thinking I need an ADC because I was converting code written for another Microcontroller, but I realized I can just use rc_time to get a pot value just like on the BS2.
I started with a QuickStart but the Activity Board is so much more useful and it comes with an ADC.
Either save up for it or wait for it to go on sale.
Propeller C also has functions for the Activity Board's ADC.
You can see some of them under CO
if you have an ADC0831here's the code and the schematics below I'll be making a vid explaining the code in a few... : ]