STM32 Boards for Energy Monitoring

Whilst discussing the Arduino Due on another thread I took another look at the specs and even they are 84MHz Cortex-M3 based MCU’s with 12x 12bit ADC’s, which (although I can’t see it right now) I seem to recall reading somewhere was capable of a sample rate of 1MHz, which if that is the case, would mean it can run all 12x 12bit ADC’s around 30x faster than the emonTx can run 5x 10bit ADC’s, if I’m not mistaken. Not quite on par with the STM’s, but possibly an easier transition??

the link doesn’t work.(takes you to best.com, but there’s nothing there) :disappointed:

Typo!! Somehow I copied over the link wrong, fixed now.

Actually, I think that’s on par with the STM32, at least the one I’m using. 1MHz and 1usec are just inverses of each other right? I just did a quick timing test of analogRead() on my Due and it takes a little under 5 usecs… still a lot better than the AVR’s 110 usecs. You’d need to poke around in analogRead() with the SAM datasheet in hand to see why it’s not 1 usec… could be they’ve slowed it down for source impedance issues like I described above for the STM32. I’d look but I don’t think I’ve got room in my head for a third ADC architecture, and don’t want to lose the two I’m still using (AVR and STM32 ;-).

From a compatibility point of view, I think the Due would be a great way to go. The only downside is it seems to be a discontinued product. No idea why.

It’s probably worth distinguishing between the number of ADCs the device has (typically 1 or 2) and how wide the MUX is that’s in front of them (often 12 or higher), which I think is what you’re referring to there. Now those that do have 2 ADCs almost all have a way of triggering synchronised conversions. Rather than starting one and then starting the other, which would introduce at least a few CPU cycles of lag, you can arm each of them, and then with a single write say “START”.

Utilising that in an OEM product would eliminate one source of phase shift as you could dedicate one ADC to the V (or Vs in the case of 3-phase) and the other to the CTs (always choosing the correct V for a particular I). Of course you won’t be able to do that if you’re sitting on top of the classic analogRead() HAL but it’s a potential performance tweak that extreme power-geeks could add later.

Since f = 1/t wouldn’t that make them reciprocals? :wink:

Yes, I probably should have specified multiplicative inverse ;-).

I should have added this on my earlier posts, but I was thinking of the emonESP as the solution for the comms. Which if you followed that protocol I guess you could design rfm69 and BT options although obviously these would need processors and code to the receive and retransmit which would put the price and complexity up. emonESP is already there so a good solution.

Simon

dBC, here’s a wiki with all the various ‘pills’ → STM32duino wiki.

This is actually a great entry point as alongside the Boards section with the schematics, poinouts etc. there’s also info on the bootloader, arduino installation, uploading sketches and the libraries as well as a link to the community forum.

Simon

EDIT

Paul, thanks for the link, now you mention it I remember that discussion. If you follow the link to Roger Clark’s post in the STM32duino forum you’ll see that he has already been there and done that so to speak, including thinking of using the ESP to transmit the data.

I believe so, but I guess since the Due has 12 ADC inputs whilst the common STM32’s seem to have 8 would give the STM32’s the edge to tune of 125KHz verses 83.3KHz per input (assuming both devices to be single ADC’s), and at the time of writing I wasn’t so sure the 1MHz quoted was for the 12bit resolution as I read it’s 10bit by default to match the AVR Arduino’s, so in my mind there was some ambiguity over whether the 1MHz was valid 12bit op,

http://www.mouser.com/ds/2/268/doc11057s-1066060.pdf

Having now took a brief look at the headlines on the Atmel datasheet, it appears to have the 1x 1MHz 12bit ADC and it actually has a 16channel MUX, I assume Arduino have made the choice to only break out 12 of those on their Due board.

I went looking for the info after reading an interesting article that stated the Due has 16 ADC’s.

2 ADC’s could well be a really good feature to look for, I don’t think the STM’s or the SAM.

Other considerations I’ve noted are the Due doesn’t seem to have an eeprom which is a bit disappointing, but it does have a RTC which could be very useful. The SAM3X also seems to have “programmable gain stage” ADC inputs although I find no mention of such on the Arduino spec’s.

I was aware it was “older” tech but it does seem to still be a current model, sometimes a tried and test tech can be a better route than bleeding edge tech that imposes a steep learning curve and lots more trial and error.

I feel I should point out I am not suggesting we consider using the Due itself, other than just an evaluation board for that MCU, much like the current emonTX is not actually an Uno. Plus I am not pushing this particular MCU option either, rather it is just another idea thrown in the ring for discussion.

Both the wiki page’s for the red pill and the blue pill state “Analogue power and ground is connected directly to digital power and ground, which can cause additional noise on the ADC input.” as known issues, so possibly not a great starting block. perhaps for proper evaluation there is a better choice of board? I notice some of them even have Arduino connectors so that Arduino shields can be connected directly, but care for the 3.3v/5v differences still need to be observed as many shields may be set up for 5v Arduinos.

EDIT - the NUCLEO-F072RB STM32-F0 evaluation board isn’t that expensive.

Sounds like this is the kind of thing you’re speaking of:

With analogRead(), you can measure many signals, but only 1 at a time. Teensy 3.2 & 3.1 has a second ADC, so you can concurrently measure 2 analog signals. For stereo audio or power monitoring, sampling both left and right, or voltage and current at the same moment is very beneficial.

The processor is a ARM Cortex M-4 MK20DX256VLH7, but the downside as dBC has mentioned, is the issue with analogRead()

If a person wanted to tinker, a library that supports synchronous ADC operation is available.

The Teensey v3.6 seems to have 24x 16bit (13bit usable?) ADC channels across 2 ADC’s, (I really hope their software is easier to navigate than their website!!)

Actually, even many of the old AVR based Arduinos like the Mega2560 I use have that. The Arduino HAL only supports the basics, if you want to use the more powerful features you need to bang on the h/w registers directly.

Absolutely. Last time I looked at the Due page it had a big “Discontinued Product” stamp on it and the Italians had announced they were going to stop producing them. But in any case, in this thread Bill reveals the Chinese will be making them probably forever regardless of where the Italians settle.

Whether you go with the NXPs Bill found in the Teensys above, the Atmels found in the Due or the STM32s probably doesn’t much matter. They all seem to have landed on very similar ADC specs (1 usec 12-bit conversions at the least).

Very nice!

Changing tack again :slight_smile:

Do any of you have a link to the specs for the ADC on the ESP32. I can’t seem to find any detail anywhere. Probably using the wrong giggle search words. The ESP32 should also be a contender, especially as WiFi and BT are baked in.

Simon

Simon,

Is this what you’re looking for?

Hi Bill, thanks. That’s one I’d found but if you take a look at page 21 it doesn’t really have the full spec for ADC, i.e. speed, voltages etc.

Simon

I noticed that too.

From the Sparkfun website:

Analog-to-Digital Converter (ADC) – Up to 16 channels of 12-bit SAR ADC’s. The ADC range can be set, in firmware, to either 0-1V, 0-1.4V, 0-2V, or 0-4V – no more weird 0-1V ADC!

Nice, but still nothing on the speed. I wonder if they’ve published anything at all yet.

Maybe I’ll just have to get one of the evaluation kits to experiment. I’ll also check out Scargill’s blog and a couple of other folks to see if they have anything.

Simon

It supports differential synchronous operation too.

Here’s an STM32F103 based Maple clone that is Arduino Shield compatible.
Works well with Roger Clark’s STM32Duino libraries. Costs USD 5.80