Posts

Showing posts from February, 2020

GD32F103 ADC , it actually works

One problem spotted, i was abusing the STM32 without knowing it The GD32 did not like it at all The culprit is the ADON bit of the ADC CR2 register. The  relevant part is that from the doc : Note:If any other bit in this register apart from ADON is changed at the same time, then conversion is not triggered. This is to prevent triggering an erroneous conversion. The trick is to setup the ADC CR2 register, wait a bit, then just toggle the ADON bit, and only that one. So, the GD32 ADC works, but the accuracy does not seems to be on par with the STM32 one. On the other hand, it can be faster by reducing the number of bits sampled. Edit : it really has only 64kB of flash!

GD32F103 ?

Image
You might have heard of that one or not : The  GD32F103C8T6 MCU What is it ? It is a alternative (i.e. compatible) chinese MCU to the STM32F103C8T6 as found on the bluepill. It is cheap (1.5$) , but so is the STM32 (about the same price) Why bother ? First, for the fun of it :). Second, it can run faster (108 Mhz) Third it has a DAC, that the STM32F103 lacks, could be very handy for the component tester So i removed a STM32 from a bluepill and put a GD32 instead (nb: That board had ADC problem prior to sacrificing it). Same software as with the STM32F103, zero change whatsoever. and.... drum roll.... * Boot ok ! * SPI ok !! * GPIO ok !!! * USB ok !!! * ADC : Fail ! Bummer So far, it looks like a really compatible  chip, drop in replacement for most things. The verdict is still out concerning the ADC, maybe the bluepill board is acting funny or i overheated the chip when soldering it back (i had ADC problem with the older chip on the same board) The basic te

Capacitor, updated

Image
So here is the new method to measure capacitor : First, identify if it is a low cap, medium cap or high cap. If it is medium cap we select the right range and capture 512 samples of the charging voltage. When we have those 512 points , we take 2 points at ~ 10% and ~ 70% to compute the capacitor value                                     C=   (t2-t1)/Rcharge*Ln((4095.-V1)/(4095.-V2)); If it is a low cap, we take the 2nd point at ~ 90% to have a better accuracy (it takes 2.3x more time to go to 90% compared to 70%) If it is a high cap, we do the same thing but poll the ADC instead of doing dma capture (it takes a long time, the error introduced by polling is very small). But how do we select the right method ? First do a high speed dma capture. If we are under 10% of the 512 samples to reach 70% of the charge, it means it is a low cap. If not, do a slow speed dma capture. If the 512 samples are not enough to charge the cap > 70%, it is a high cap. If neither are

STM32F1 ADC Weirdness

That one had me scratching my head for a while. Depending on the speed of the ADC, there is a small current being eaten by the ADC itself, in the range of 0.5uA to 3 uA. Why is that a problem ? 1- It happens even if the ADC is not sampling, which is really weird. When using high current ( a few mA), it is not visible at all. 2- But when using a large resistor (i.e. 300kOhm), that small current is enough to cause a voltage drop of sever tenth of a volt, ruining the measures. For reference, with the 300 kOhm (or 2x300 kOhm) the current is ~ 10 uA (or 5uA) , so a ADC leaking 2uA is not neglectable at all. At the fastest speed (worse effect), it causes the capacitor to cap at 3v (or 2.5v) rather than ~3.3v which ruins the estimation. To confirm, i cut the ADC wire and voila, back to ~ 3.3 v The estimation of the current is as follows (the different rates/scales of the ADC clock can yield different result for the same sampling period) : Samp period (us) i (ua) 2.16666666