@bko, Provided a fix for the extra zero in the converted data by:
1)Changing the DMA mode from “circular” to "normal"
2)Enabling ADC2 external trigger conversion for each analogRead
3)Reset the buffer and DMA counter before starting the ADC-DMA command
When do you think this will get pushed out to allow us to build using the WebIDE and not experience the cross-talking issues between analog channels? I know I can use the USB approach, but I’m curious what the timeline is for seeing it in the over-the-air version.
@satishgn I haven’t read the whole thing yet, but this jumped out at me:
The dual slow interleaved ADC mode is intended for the conversion of one channel. ADC1
and ADC2 convert the selected channel alternately with a period of 14 ADC clock cycles.
The channel is thus converted every 14 clock cycles. Each ADC converts the channel every
28 ADC clock cycles. The conversion can be started by external trigger or by software and
the conversion results of ADC1 and ADC2 are stored into ADC1’s data register (32-bit
format).
The maximum allowed sampling time is 14 ADC clock cycles to avoid any overlap with the
next conversion.This means that the only allowed sampling times are 1.5, 7.5 and 13.5
cycles.
Yet we still have it set to 41.5.
EDIT: Sounds like the effective sampling rate using two ADCs at 13.5 is still about half as good impedance wise as one ADC set to 41.5. However the sampling rate is higher. I guess for a small percentage of users this would be beneficial. Most would want a rock solid reading.
@BDub, good find. This was a big surprise to me as how the sampling time was bumped from the original 1.5 to the current 41.5. Think it happened during the community provided merge. I will update and test the code again to see how the change affects the whole process.
Thanks
Yes it was from a direct result of this thread See first post.
I’m guessing you’ll want to stay to the high end 13.5. Having it set to 41.5 probably yields 13.5 max anyway so I don’t know if there will be much change in how it responds. Comparing to the old way of 41.5 single channel/conversion might be interesting though.
@BDub correct after trying out with 1.5, 7.5 & 13.5, readings are pretty much similar to 41.5 sampling time. But I haven’t tested it comprehensively as you did in your first post. Would you like to repeat the test and see how the use of Dual ADC compares with the single ADC in terms of input impedence and publish the result.
Thanks,
Satish.
@BDub, Default sampling time is now set to 7.5 and added a new setADCSampleTime() which can be called in setup() to override the default ADC Sampling time.
Ahh cool! I was totally going to suggest that since it seems like some people might need faster sampling and can take care of making sure the input impedance is low enough to get good readings. I’ll try to get some testing in tonight.
Well it was very nice to return home and find that the ADC issues are solved - thanks guys. The new code gives excellent results with my 50Hz measurements so I can get back to the Energy Monitor development.
I’m getting around a 35uS conversion time with 1_5 set in setADCSampleTime() and 40uS with the default 7_5 so there is not a lot of difference. If I want faster sampling for my next project I’ll go back to the pre-DMA version of the code which was much faster but make sure I take care with input impedance.
Can someone help me out with the circuit of the temperature sensor interfaced with spark core? My program is correct but some problem in circuit.? Reply ASAP
// -----------------
// Read temperature
// -----------------
// Create a variable that will store the temperature value
int temperature = 0;
void setup()
{
// Register a Spark variable here
Spark.variable("temperature", &temperature, INT);
// Connect the temperature sensor to A7 and configure it
// to be an input
pinMode(A7, INPUT);
}
void loop()
{
// Keep reading the temperature so when we make an API
// call to read its value, we have the latest one
temperature = analogRead(A7);
}
How to read the data:
voltage = (sensor reading x 3.3)/4095
Temperature (in Celsius) = (voltage - 0.5) X 100
The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature
# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.spark.io/v1/devices/0123456789abcdef/temperature -d access_token=123412341234