Question about ADC in Particleboard P2

Hello,

I have a couple of questions regarding the Analog-to-Digital Converter (ADC) configuration in Particleboard P0, P1 and P2.

For P1, I couldn't find specific information about its ADC in the documentation. However, P1 employs the STM32F205RGY6 microcontroller, which has 3 ADCs with 16 channels in total. P1, on the other hand, only provides 13 pins for ADC usage. Does this mean that P1 doesn't utilize all of the three ADCs on the STM32F205RGY6? If so, how many ADCs does P1 actually use? Or it uses all these three ADCs, but just use parts of the channels?

Regarding P0, it also uses the STM32F205RGY6 MCU and offers only 8 pins for ADC input. Similar to P1, does P0 also utilize a subset of the available ADCs on the STM32F205RGY6? If so, how many ADCs are utilized by P0? Or it also uses all these three ADCs, but just use parts of the channels?

Moving on to P2, I noticed that it has 6 ADC input pins as specified in the datasheet.

However, when I reviewed the datasheet for the Realtek RTL8721DM, I found that it provides 7 ADC channels.

Does this imply that P2 utilizes 6 out of the 7 ADC channels available on the RTL8721DM? I'm particularly interested in interleaving ADCs to enhance the sampling rate. Will P2 support such an arrangement?

Thank you for your assistance in clarifying these details.

On STM32 devices, analogRead() uses two ADC blocks in the MCU running in parallel, and averages the output. The number of channels available in as specified in the datasheets, 8 on the Photon/P0 and 13 on the P1. The other channels are not available for use as ADC inputs. It is possible to use all three ADCs and DMA from user firmware, but there is no support in Device OS for doing so.

On the P2 and Photon 2, there are 6 pins that can be used for ADC. The 7th ADC input is used for VBAT_MEAS for measuring the battery voltage.

If you need a lot of ADCs, the best option is to add a SPI or I2C ADC chip.

1 Like

Thank you so much for your reply!

Hello,

I have some questions about particle photon, which offers 8 pins for ADC input. I wonder are all of these pins connected ADC1? Are there any pins mapped to ADC2?

On STM32 devices, the mapping between an ADC pin and its hardware ADC (1-3) is done in software.

An ADC input on the Photon are read simultaneously by both ADC1 and ADC2 and the values averaged when analogRead() is called.

If you implement custom ADC reading you could simultaneously read any three pins at the same time using the three ADC channels, but there is no support for this in Device OS. It can be done from user firmware, however, with a lot of low-level STM32-specific code.

1 Like

Hello,

I'm currently delving into the Device OS firmware for the Particle Photon so as to customize ADC, and have encountered some problems. I am specifically looking to understand the ADC pin mapping and functionality for the Photon. However, I'm facing some confusion:

In the device-os/platform/MCU directory, the code appears to be tailored for Photon 2. Is there a separate section or repository for the original Photon?

And the hal/src directory doesn't seem to contain specific source files for the Photon either:

Could you please point me in the right direction to find the ADC pin mapping and functionality specifically for the Particle Photon within the Device OS firmware? Any guidance on navigating the codebase or documentation would be greatly appreciated.

The current develop branch in device-os only supports Gen 3 and later platforms.

To work with the Photon 1, look at the release/v2.x branch.

Also look at the photonAudio repo. Example 3 shows how to use the ADC in DMA mode on STM32 devices. It can be done entirely from user firmware without having to modify Device OS. Also, the STM32 standard peripheral library is available to user firmware which makes it much easier.

The only caveat is that a special technique is necessary if you need to handle an interrupt. The photonAudio example shows how to do it using attachSystemInterrupt.

1 Like

Hello,

I have another question about the buffer size. I try to increase the buffer size to 48KB, but it cannot be compiled.

When I use 10KB or 20KB, it has no problem. I wonder why the buffer cannot be larger? And how large the buffer can be?

Best,

The free RAM on the Photon 1 is around 55K, so depending on the RAM usage in the rest of your program, it's not surprising that 20K works and 48K doesn't.

And you can't use everything report\ed from System.freeMemory() because the system needs some (especially if you use listening mode) and also because of general use and fragmentation.

2 Likes

Hello,

Thank you so much for your previous help. I've modified it a bit so that I can use two ADCs each operating at a 32kHz sample rate, giving me a 64kHz sample rate. Now I'm trying to increase this to 1MHz. However, I'm unable to trigger the sampling at this rate using a timer. Switching to continuous sampling mode hasn't resolved the issue either. Using continuous sampling mode by :
ADC1_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC2_InitStructure.ADC_ContinuousConvMode = ENABLE;
or using a timer triggering at a very high frequency will give me sampling results similar to the following:

I wonder if this board support higher speed sampling? Because I saw that the STM32 official website has an example code for high-speed sampling in continuous mode.

Best,

I never tried it that fast, but it should work. However things that come to mind:

I think there's a divisor on the timer that may need to be changed to set that speed.

What are you doing with the samples? With only 50K of RAM or so, you'll be filling the buffer at very high speeds. This means the buffer full interrupt will be firing so often that the system will probably fail to function properly. At that rate I don't even think you could even run something simple like a FFT on it. You definitely cannot write it to the network and even a serial logging message will take too long at one per buffer.

Hello,

I want to sample a signal around 100kHz, but its duration is very short, and I only need to sample about 1ms. Do you mean the RAM is not big enough and will cause some failure?

Best,