Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
1,529 Views

MCU ADC Uniform Sampling

Jump to solution

I have a project where I was trying to get uniform sampling rate from the Edison ADC in python. Specifically, I read analogin values from python for a second, sleeping 1ms between samples. Obviously this wouldn't actually give me 1000 samples per second every time, but there was also way too much variability, from around 540-890 samples per second, and I assume there's no way that these were uniformly sampled.

Since Edison doesn't have an RTOS, I tried to switch to the Quark, but I saw that the Quark sleep can only go as low as 0.01s, whereas I need to be sampling an ADC (this time, I have an I2C ADC connected) at least 1KHz. Can someone provide some insight into how I might do this in an accurate manner?

And yes, I've seen the two links that have been cited as the answered posts regarding the quark adc reading.

Thanks


Accepted Solutions
Highlighted
Employee
13 Views

Hi menonv,

Yes, the MCU OS tick value is 10 ms as you know. If you want to use I2C I suggest you to guides for this:

https://software.intel.com/en-us/node/557355# APIs_to_access_I2C MCU API | Intel® Developer Zone

https://software.intel.com/en-us/node/557354# Reading_the_value_of_an_I2C_device_and_sending_it_back_to_the_host Using the MCU SDK and API: Code examples | Intel® Developer Zone

Have you tried with this code?

Are you using the https://www.sparkfun.com/products/13046 SparkFun block with ADC? If you do Jose has been doing some tests to use this block, I think it might be helpful for you:

Kind regards,

Charlie

View solution in original post

0 Kudos
8 Replies
Highlighted
Employee
14 Views

Hi menonv,

Yes, the MCU OS tick value is 10 ms as you know. If you want to use I2C I suggest you to guides for this:

https://software.intel.com/en-us/node/557355# APIs_to_access_I2C MCU API | Intel® Developer Zone

https://software.intel.com/en-us/node/557354# Reading_the_value_of_an_I2C_device_and_sending_it_back_to_the_host Using the MCU SDK and API: Code examples | Intel® Developer Zone

Have you tried with this code?

Are you using the https://www.sparkfun.com/products/13046 SparkFun block with ADC? If you do Jose has been doing some tests to use this block, I think it might be helpful for you:

Kind regards,

Charlie

View solution in original post

0 Kudos
Highlighted
Novice
13 Views

Is Jose still active on these forums? I have a few questions as to how to modify his code for the block.

Specifically, where did you (jose) read that 0x04 is where you read the data from the I2C? I looked at the data sheet, and it looks like in order to read ADC data, you need to change the pointer register at 0x01 and then read from the conversion register 0x00, whereas 0x04 is not included in the data sheet.

Thanks,

Vivek

Highlighted
Employee
13 Views

Hi vivek,

Are you using this datasheet->http://www.ti.com/lit/ds/symlink/ads1015.pdf http://www.ti.com/lit/ds/symlink/ads1015.pdf ?

I think that Jose is using 0x04 according to the bit configuration (You can change this by using the datasheet) he wanted to use in order to read the buffer.

If you want to contact Jose: Humberto_Garza you can send him a private message in his profile or you can use his github: https://github.com/humberto-garza humberto-garza (Jose Humberto Garza Rosado) · GitHub

Regards,

Charlie

0 Kudos
Highlighted
Novice
13 Views

Yes, I am using that datasheet.

I'm not sure if you looked through it, but it states that before reading from the ADC, you must write 0x01 to the pointer (which then allows access to the "Conversion" Register that stores the ADC data). After that, you must pass the I2C Address with the read/write bit high, and then read from the Conversion Register.

I realize this is asking for help for the I2C device, but Jose's code doesn't actually follow these processes which makes me wonder if any of this is taken care of in the MCU_API library's I2C functions. In addition, the 0x04 address is nowhere to be found in the datasheet (the pointer values only go up to 0x03) which is why I am asking why this address is being used. Perhaps I am fundamentally misunderstanding what is going on, but the code provided seems much simpler than what the datasheet indicates what needs to be done.

Thanks,

Vivek

Edit: If there were some sort of "i2c_write_byte" and/or "i2c_read_byte" then that would be useful, but as far as I know, those functions are only available on mraa and not in the mcu_api

0 Kudos
Highlighted
Employee
13 Views

Hi Vivek,

Have you been able to work with this? Do you have updates using the ADC with the MCU SDK?

I didn't see a place where specifically states to use 0x04 so I'm guessing he had set it regarding to the bit configuration he wanted to use.

About the functions for I2C, the availables right now are I2C_write and I2C_read, you can check these in the mcu libraries, mcu_api.h and mcu_errno.h

Regards,

Charlie

0 Kudos
Highlighted
Employee
13 Views

Hi vivek,

I would like to know if you have updates on this.

Kind regards,

Charlie

0 Kudos
Highlighted
Beginner
13 Views

Hello!

Sorry for not checking this before, I was not able to login to the site..

Regarding to your question, I totally agree that it should be 0X01 and when i tested it, it did not work, I am not sure why it was, maybe because the map to the MCU of the I2C bus may differ. But doing some testing, I concluded that the register needed was at 0X04, I could not find anywhere that would tell me where it was, so I had to do some testing in order to get it right.

Let me know if you have more questions.

Here is my personal email

mailto:humberto.garza.13@gmail.com humberto.garza.13@gmail.com

0 Kudos
Highlighted
Beginner
13 Views

Hi to all,

I am using galileo gen 2 board and i would like capture analog and digital values every 1ms with uniform sampling. Is it possible uniform sampling with this board? Can it speed up to 1khz? Are there some setting to reach this task? (For instance using timer interrupt or setting high priority level?)

Thanks in advance!

0 Kudos