Need help with MCP3208 ADC and multiple cogs
One Who Waits
Posts: 7
Hello, guys!
I'm an absolute newbie, but it just happens that I really have to construct not so simple (for me) device.)
Briefly, I need to have three simultaneous processes, started in different cogs: first one will act as 30us width /10 Hz square pulse generator and the rest two connected to 2 MCP3208 (or 04, 01, doesnt really matter) chips. The idea is to measure very short signal (~100 ns) that's triggered (with a small delay) with the rising edge of the 30 us pulse using two synchronous detectors connected to MCP3208's. By far, I've been experimenting with the MCP3208 object from ObEx. The problem is that it uses assembly language (which I don't understand at all). According to the datasheet, conversion time depends on the sampling rate. I assume that in our case it's it's quiet high (~100 ksps), which makes it quiet difficult to synchronize. Could you please help me to figure out, how one could make the sampling time ~ 20-60 us and sampling rate 10 ksps. Just adding a 100 ms delay wouldn't change sampling time. I also had problems with starting the main procedure from MCP3208_test object in a new cog. Could this be because of the assembly part of it or shared variables? I'm really looking forward to your replies. If any one of you possibly have an assembler-free object for this chip, could you please share it with me. I know that SPI is a·really simple interface, but right now I just have no time to go throu it.
Thanks very much.
···
I'm an absolute newbie, but it just happens that I really have to construct not so simple (for me) device.)
Briefly, I need to have three simultaneous processes, started in different cogs: first one will act as 30us width /10 Hz square pulse generator and the rest two connected to 2 MCP3208 (or 04, 01, doesnt really matter) chips. The idea is to measure very short signal (~100 ns) that's triggered (with a small delay) with the rising edge of the 30 us pulse using two synchronous detectors connected to MCP3208's. By far, I've been experimenting with the MCP3208 object from ObEx. The problem is that it uses assembly language (which I don't understand at all). According to the datasheet, conversion time depends on the sampling rate. I assume that in our case it's it's quiet high (~100 ksps), which makes it quiet difficult to synchronize. Could you please help me to figure out, how one could make the sampling time ~ 20-60 us and sampling rate 10 ksps. Just adding a 100 ms delay wouldn't change sampling time. I also had problems with starting the main procedure from MCP3208_test object in a new cog. Could this be because of the assembly part of it or shared variables? I'm really looking forward to your replies. If any one of you possibly have an assembler-free object for this chip, could you please share it with me. I know that SPI is a·really simple interface, but right now I just have no time to go throu it.
Thanks very much.
···
Comments
I have a modified version of MCP3208.spin that does all of the work in assembly language.
At 80 MHz it always takes exactly 6624 clock cycles to retrieve a single adc sample, using the MCP3208 chip specs for clock frequency. The original code varies between 2500 and 16000 clock cycles because of the way it's written.
For an average of 10 samples, the new code takes 21,776 clock cycles. The original code takes about 135,000 clock cycles. That's more than 6 times as fast.
Notice that it can take a 10 sample average in a little over 3 times what it takes to get a single sample.
I've used it for a while and it seems to be very reliable. See the attached pics.
Let me know if you'd like the code.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim Fouch
FOUCH SOFTWARE
It has exactly the same calling sequence as the original.
There are a few operational changes, listed below:
For a 10 sample average it is 6 times faster than the original.
The output is deterministic, in that it takes the same number of cycles each time it is called.
It there is enough interest, I'll post it in the object exchange.
Jim
The spec sheet lists a maximum sample rate of 100,000 samples per second, which is one sample every 10uS.
10uS is 10,000ns, so what you need isn't even close to what this chip can supply.
I assume you're trying to "see what the signal looks like", so you'd need at least several samples within your sample period of 10-100ns.
Am I missing something?
Jim
To get the power density or integral energy I think you need the area under the curve. I don't see how you can get this without getting several samples during its cycle. The chip does not take an instantaneous sample, it takes a certain amount of time for it to derive the sample and this time may be longer than your entire sample.
Sorry to seem dense.
Jim
I have a couple of questions:
1. You didn't say what frequency you are clocking the MCP3208 at. If your drawing is to scale, then it looks like the 20us pulse is the same as the clock frequency, which would be 50KHz.
2. You didn't say what voltage you're using to power the MCP3208. If you're using 3.3V, then the clock frequency is limited to 1.0MHz. If you're using 5.0V then the clock frequency can be set to 2MHz.
Suggestions:
1. Use a scope to determine the timing. You should be able to trigger on CS going negative. This will let you easily adjust the timing parameters.
2. I think your goal should be to maximize the ratio of t-signal to t-sample. Since the ADC is charging a capacitor, maximizing this ratio will allow it to charge higher during t-sample and give you a better sample.
You said your t-signal is 20-100ns, let's say it's 50ns as an example.
If your clock frequency is 50KHz, then t-sample is 30us and the ratio is 0.05us/30us = 0.0017.
If you can use 5.0V and 2MHz clock frequency, then t-sample is 0.75us and the ratio is 0.05us/0.75us = 0.067, which should give you a better sample.
I hope this helps.
Jim
1) The picture isn't really to scale. In fact, it's rather difficult to speak about clocking with this object for according to scope, it provides different clock periods at different stages of conversion).
2) I'm using 3,3 V supply. Didn't want to bother with output levels of MCP3208. By the way, do I have to do anything to connect it to Prop in case of 5 V supply, for the output logic 1 level would be also almost 5 V? Like voltage dividers or something?
Anyway, I measured the last Din clock cycles and it seems that tsample with this object exceeds 50 us! So I had to quit using it. Now I'm using the standard object for MCP3208. I believe you understand it perfectly. Is it possible to estimate time interval from calling "in" method to the "start" of tsample? So I could add a required delay.
From what you say, you want to meassure the energy of a very small pulse of undefined shape, but aproximable by a square pulse of around dT = 60 ns +/-40 ns . What you want to learn is dT*Umean.
An A/D converter is a very unapt mean for this... As mynet remarked you need a sample rate of at least 5 ns = 200MHz for it... These exist but don't look at the price tag...
The standard procedure for this is to let electronics do their fast working in the disguise of a tiny cap.
Cut away all the lower MHzs by a suitable high pass and catch the pulse (=charge) with a low pass, buffer between both filters with a high impedance output (common gate) circuit.
Note that this is basically an "integrator" so you have to compute the difference between two (slow) samples from yor ADC. There is the noise, steadily ramping up, and the signal, noticable by a jump and its value
Post Edited (deSilva) : 10/28/2007 8:14:52 PM GMT
You asked what to do if you use a 5V supply on the MCP3208. If you do this, make both the supply and the reference pins 5V. Then simply use a 1K resistor on your Din/Dout line between the Prop and the MCP3208. This will limit the current and should work great.
This would allow you to use the 2MHz clock and get a usable reading for your signal.
Let me know if you need help with the 2MHz clock to the SPI interface. I just posted a fast MCP3208 routing to the object exchange. It operates at a 1MHz clock to accommodate the 3V3 voltage restriction. I can probably supply you a 2MHz version if you want it. I've tested the chip at even higher clock frequencies and it works great.
Jim