nerdyscout / Arduino_MCP3x6x_Library

Library to support Microchip MPC3x6x 16/24bit analog to digital converters.
https://nerdyscout.github.io/Arduino_MCP3x6x_Library
MIT License
17 stars 9 forks source link

Not really an issue :) #3

Closed mnemocron closed 1 year ago

mnemocron commented 1 year ago

Last year you discovered my repo for this chip and even helped out. https://github.com/fhnw-ise-qcrypt/mcp3564

I just wanted to let you know that my library is now at a point where it is working in a product that I am still developing. https://github.com/fhnw-ise-qcrypt/stm32-wiggly-pointy

And I came up with a conf.h file to have various configuration examples because this chip is just so damn adaptable. So feel free to cheat by looking through my code. This is how I handle the "streaming" mode via GPIO interrupts. It actually works according to the timing from the Excel sheet: https://github.com/fhnw-ise-qcrypt/stm32-wiggly-pointy/blob/main/Core/Src/stm32f3xx_it.c#L225

I am really curious how you implement the Stream class as I have seen in the example that you want to achieve.

nerdyscout commented 1 year ago

hi @mnemocron! great to hear you are doing progress... I am currently a bit stuck with this lib. So, for sure, I will have a look at your code.

Actually I do not really know what to do with the Stream interface. my basic idea was to put the ADC in scan mode with static conversion and setup some interrupt handler to enable dma based spi transfer. afaik this is mostly what you are doing as well... but I still see no reason why to use the stream interface... might have been just a stupid idea when I initially set this up.

mnemocron commented 1 year ago

my basic idea was to put the ADC in scan mode with static conversion and setup some interrupt handler to enable dma based spi transfer.

Yeah, that is what I had in mind first. But I was not able to use DMA since I suppose this is very much dependent of the hardware implementation of the SPI peripheral. In streaming mode, the ADC is the master that generates DRDY interrupts for each sample. The MCU then has to react on that IRQ signal on a GPIO. Unless you can configure a DMA transfer of 3-4 bytes each time a trigger is present, i don't think DMA works. But good luck anyhow. I saw you are using the ESP32.

nerdyscout commented 1 year ago

Screenshot at 2022-08-31 07-35-03 well with my latest approach (code not yet published) I do get an IRQ every 670µs (yellow), which triggers an interrupt handler reading 4 bytes which lasts 11µs. All of this with standard Arduino SPI functions, as far as I understand those fall back to DMA if the selected MCU supports it. But yes, using MCLK I was not able to, so everything is running with internal clock.