C3 ADC PropGCC driver code
Rsadeika
Posts: 3,837
in Propeller 1
I started messing around with the C3 again. I would like to use the ADC component on the board, but I have no idea as to where to start with C code for the driver. Anybody have a C driver already written, or could give me a good starting point for doing the driver?
I would like to stay away from doing a conversion, would like to do a scratch build, I guess a lot of hand holding on this one.
Thanks
Ray
I would like to stay away from doing a conversion, would like to do a scratch build, I guess a lot of hand holding on this one.
Thanks
Ray
Comments
Not C, but Spin (maybe a starting point?)
Not sure if you have this link, but here's the link to the FTP site for both the C3 and the Programming and Customizing the Propeller Book.
"ftp://ftp.propeller-chip.com/"]ftp://ftp.propeller-chip.com/
Follow the link; then go to the C3 directory and the Sources directory. There are a few analog to digital demos. In the docs folder there is a data sheet for an MCP3202, so I assume that is the ADC chip on the C3??
I did write a C program that loads the PASM from the SPI object in the Prop Tool Library and C code that uses the MCP 3208. The library is in this post:
https://forums.parallax.com/discussion/comment/1315065/#Comment_1315065
I haven't tried on a C3 so I'm not sure using an SPI interface with the C3 is as direct as it is with the Activity Board or PPDB.
Tom
Since there is a driver, written in C++, for the ADC being used on the C3, I am considering redoing my existing code, mainly in C format so I can incorporate the C++ ADC driver. Not sure what this would entail.
As an experiment, for my existing C program, I changed the compiler type to C++, and tried too compile the program. It came up with an error for the cogrun() function and a numerous amount of warnings. My first guess would be that simpletools.h is lacking something that would allow it to be run with the C++ compiler, without warnings.
I will be investigating what I can use, that PropWare offers, within a SimpleIDE environment. It would be nice if the libraries were interchangeable between the compiler types, maybe they are and I am just doing something incorrectly. Not sure if I want to go 100% C++, at this time.
Ray
Below the program listing is the build status for the program, the error has me scratching my head, not sure what that means.
Ray
I tested this using a QuickStart Board+HIB, it has the built in IR stuff. So far it looks like intermixing the simpletools.h within a .cpp program has not caused any difficulties yet. I am at a complete loss as to how I should add the C++ ADC driver code, and then be able to use the function calls.
I guess maybe at this point I should go ahead and try to see if I can install the latest PropGCC version, so I can maybe try and see how this stuff will run in XMMC mode.
Ray
Not sure what the easiest way would be to correct this. I am thinking that I would need to find the library source, and then have it compiled in XMM mode? I tried to find the simpletools library source code, but I had no luck. You would think that there would be some compiled libraries for all the memory models residing somewhere, but I am probably wrong again.
Now I am thinking that the available C3 C++ ADC code will not work with the XMM setting. This all seems to be very complicated if you have to compile the libraries, for the specific memory model first, before you can use it, and then deal with the multiple copies of the same library in different memory forms. This could be a very large nightmare.
Ray
ftp://ftp.propeller-chip.com/PropC3/ is the top level documentation and sample code store I've been using successfully for a while. Hope this helps!
-Mike
Glad you're interested in trying it. I just confirmed that PropWare's MCP3xxx object, and indeed the entire MCP3xxx_Demo file (which includes the serial routines), works in xmmc mode on a Quickstart. Pre-compiled versions of PropWare can be used from within SimpleIDE by following the instructions at the top of this page: http://david.zemon.name/PropWare/#/download
When you download PropWare, it also ships with all of the Simple libraries, including xmmc-compiled versions. However, so long as you're building from SimpleIDE, that should not be necessary. I don't have SimpleIDE installed on this machine at the moment, so I can't confirm, but I'm pretty sure SimpleIDE is supposed to automatically compile and link in any of the Simple libraries that are required by your application.
Now, that all being said, I was able to get your code to work on my Quickstart board after a one change. I increased your stack size significantly, to this:
"EXTRA_STACK_LONGS" is a macro defined on line 120 of propeller.h, and it resolves to a much larger value than what you have.
As for "compiler type" you want to leave that set to C, but make sure your files are named ".cpp". This will invoke gcc ("C++" compiler type invokes g++) and gcc will compile as C++ based on the file extension. Compiling with g++ just brings in automatic linkage of the C++ libraries, which you won't need. The link above, about downloading PropWare, explain all the right settings in SimpleIDE to get you going.
You can find that pdf by entering "C3" in the searchbox on the product page.
There is a lot of detail and examples in the book, but a short explanation from the book is:
"One signal would be used to clock a 4-bit counter (U11; 74LVC161A), the output of the counter would be fed into a 3-8 bit decoder (U7; 74LVC138A) then as the count increased the decoder would enable one of n outputs (active low). These outputs would then be directly connected to the active low chip select line of each and every SPI device on the bus. Finally, to reset the counter, the other remaining IO line feeds the active low reset of the counter (SPI_SEL_CLR) and this allows you to very quickly reset the SPI select to device channel 0."
Tom
I added a 400 ms delay between each set of readings to allow the printing to keep up with the data collection. Otherwise the printed values lagged far behind as I adjusted the voltage using the potentiometers.
Here's the SimpleIDE C version. --
EDIT 12/23 9:50 EST: sorry I had edited it in a text editor & and introduced some errors. I am reediting it in the IDE and will repost when fixed.
Tom
Tom
Ray