Anyone have examples of using the Prop Boe's ADC from PASM?
Martin_H
Posts: 4,051
I have a sensor that has an analog output and some Propeller code that uses sigma delta analog conversion to interface with it. I want to port the code to the Prop Boe and use its on-board ADC instead. If this was Spin code I could do it pretty easily, but the original code is in PASM, which I've been avoiding for a while now. I used to program in assembler back in the 80's, so I bit the bullet and read through the code. I found it relatively straight forward with a few bits I was clueless on.
I think if I had a PASM example showing how to use the Prop Boe's ADC, I could cut out the sigma delta section and replace it with the ADC example tweaked for this application. I imagine debugging PASM is a whole lot harder than debugging Spin as you don't have access to the serial terminal. But I'm willing to give this a shot since I think it will be easier than re-writing the whole thing in Spin.
I think if I had a PASM example showing how to use the Prop Boe's ADC, I could cut out the sigma delta section and replace it with the ADC example tweaked for this application. I imagine debugging PASM is a whole lot harder than debugging Spin as you don't have access to the serial terminal. But I'm willing to give this a shot since I think it will be easier than re-writing the whole thing in Spin.
Comments
Here's some working code I've excerpted from a program I'm working on. It reads two inputs. Perhaps you can modify it for your own needs.
I should add that, although the datasheet is complete and accurate, it's terse to a fault. It took me quite awhile to figure out how to read the results. Also, I discovered that the PropBOE has nowhere handy to probe the SCL and SDA pins, so I added an echo function to P12 & P13, so I could see what was going on with my scope. If you don't use this facility, just replace the echo lines with nops or some other equivalent delay.
BTW, the amount of delay seems large for the ADC chip's stated specs, but I suspect it's because the PropBOE uses 10K pull-ups. They should be 3.3K or less for reasonable clock speeds at 3.3V.
-Phil
* I can read the ADC using the Simple ADC test and I know it is working because I changed the voltage into the ADC and saw it reflected in the output.
* I removed all the sigma delta stuff from the TSL1401 driver and the adc code did nothing. But I could attach the TSL1401_monitor_simple.exe and produce a flat line. So the bones of the program is working.
The bad news:
* I added in the I2C ADC code and it terminates execution and it's clear I'm in over my head as I don't really understand it well enough to know if it looks right or wrong.
David, do you have some C I2C routines or are they included in an example with Prop GCC?
It's up to the slave device to pull SDA low, signalling an ACK condition after a write, which causes C to be cleared in i2c_rd_wr (called by i2c_wr). If it does not, it's up to the master to keep trying.The code I posted works. If it gets stuck in this loop, it means that something else has gone wrong.
-Phil
I used the Prop BOE Spin object with the ADC and it does work, but apparently not with this code. The OBEX has a pure Spin TSL1401 object which I tried and it works, but it uses pin thresholding for binary output. I could interface it with the Prop BOE ADC Spin code, but I'm thinking that the results will perform poorly as all that Spin code starts to add up.
What I will probably do tonight is go back to the Propeller Backpack and have the Prop BOE consume its output like I was doing with the BS2. I thought it would be neat to use the Prop BOE's built in facilities, but I know the Prop backpack will do the trick.
Propgcc has promise too, but there's a learning curve there which is more of a long term strategy than short term.
My crazy idea is to use spin2cpp to port this code to GCC and then obtain a speed up that way.
I seem to be one of the lucky people who has a BOE where the adc I2C address is %010_0001 instead of the expected %010_0011. Fortunately I found someone else who had the same problem on the forums and I've got the Spin version of the A/D code working but I can't figure out where I'd make changes in your Pasm code. I've entered the code and your debugging lines show what looks to be normal I2C clock and data on my Propscope except that there's no output returned by the program. Presumably your code was written under the assumption that the I2C address of the A/D was %010_0011.
I'm sure if I spent a few hours slogging through your code I'd be able to figure this out, but after losing 3 days on what was supposed to be a really easy part of my current project I just can't afford to.
Thanks,
Boris