Elektroda.com
Elektroda.com
X

V and A led meter modification on HC32F003 chip (4 bit, 0-100V, 0-10A)

wsxcde 10962 20
This content has been translated flag-pl » flag-en View the original version here.
  • V and A led meter modification on HC32F003 chip (4 bit, 0-100V, 0-10A)

    Hello all.
    Some time ago I bought a LED current and voltage meter (4 bit, 0-100V, 0-10A) on the Chinese website. According to the description, it was to provide values with a frequency of 3 times per second. It turned out differently, i.e. he gave them less than once per second, which was unacceptable for my applications.
    The meter is built on the HC32F003 processor. On Chinese websites I found full documentation, SDK and utilities for this processor. I decided to play with him.
    Attempting to connect with the SWD connector has failed. This should have been done using the serial port. It worked, but the flash could not be read - it was secure. So one thing remained - delete the flash and write the software from scratch, which I also did. By the way, I modified the circuit to measure 0-30V. Wiring diagram:

    V and A led meter modification on HC32F003 chip (4 bit, 0-100V, 0-10A)

    What difficulties did I encounter? A dedicated program did not detect my processor on any USB adapter - serial (I tried on PL2303 and CH340). The FlyMcu program detected the PL2303 chip, but I can't remember why I didn't use it to delete the chip (it didn't allow it?). Eventually, I deleted flash on a Linux computer with a Python program. Now I had full access to the CPU. I programmed and debugged it through the already active SWD port using J-Link (how to make a J-Link adapter with Blue Pill can be found in the network).
    As a result of my scribble (I am not a programmer) I have a meter that gives values very quickly and does it more accurately than on the original software. The measurement frequency can be modified by changing the byte in the flash.bin file under the offset 0xbee (in the range 1-255).
    Included software and flash batch.

    Cool? Ranking DIY
    About Author
    wsxcde
    Level 12  
    Offline 
    wsxcde wrote 30 posts with rating 83, helped 2 times. Been with us since 2005 year.
  • #2
    khoam
    Level 41  
    Bravo for this reverse engineering :) Did a colleague check the "linearity" of the voltage measurement in the new 0-30V range?
  • #3
    metalMANiu
    Level 20  
    Congratulations and I appreciate you sharing your work ?
  • #4
    wsxcde
    Level 12  
    The measurement is calibrated for the one I have and it gives the correct values throughout the voltage range (it was not possible to set it in the original software). I have one copy of the meter and I do not know how exactly it will be for others.
  • #5
    RomanWorkshop
    Level 12  
    Where did "4-bit" in the topic name come from? The HC32F003 microcontroller is 32-bit (ARM Cortex-M0 + core) and has an accurate 12-bit ADC (SAR) converter.
  • #6
    piotr_go
    DIY electronics designer
    RomanWorkshop wrote:
    Where did "4-bit" in the topic name come from?

    The Chinese call this 4ro digital displays.
    Why? I have no idea.
  • #7
    wsxcde
    Level 12  
    Exactly, under this name you can search for it on Chinese sites.
  • #8
    User removed account
    Level 1  
  • #9
    Duch__
    Level 31  
    Does RS read something in the original software?
  • #10
    wsxcde
    Level 12  
    The point is, does soft send something via RS? No, the serial port pins are used for other functions.
  • #11
    eurotips
    Level 39  
    I bought one too and I am pissed off by another thing: the disappearance of current indications after exceeding the 10A range.
    Maybe rummage around here and give him a chance for the 0-20A range?
  • #12
    wsxcde
    Level 12  
    It is similar in my program - at 10 A, horizontal lines will appear. You would have to modify the system (voltage amplification from the measuring resistance) or supply it with 5 V (i.e. also modify it) and change the program.
  • #13
    eurotips
    Level 39  
    This can be done by replacing the shunt because I always do it in order not to give two in series if the power / charging module has its own shunt. The only thing left to do is change / switch the range.
    As in the CC power supply, the shunt has a different value than in the AV module, I correct the LM321 / LM358 gain in the input stage by replacing one resistor and calibrating the existing peer. Well, but without modifying the program, the range is always limiting me, the charger gives me a maximum of 12A and above 10A the indications go out. Only one of the dozen tested by me does not have this blanking.
  • #14
    wsxcde
    Level 12  
    Even those that should show up to 20 A go out? You have a soft attached, which will turn off at 20 A. Anyway, the ADC will saturate earlier, but I think that 12 A will show. The current is given with two decimal places.
  • #15
    eurotips
    Level 39  
    I wrote only about those in the 0-10A range, that only one in a dozen or so copies does not go out after exceeding the range.
    It is very difficult to buy VA with a current up to 20A at this price, usually they are with an external shunt and much more expensive.

    Thank you for the batch, I will try it because I have the equipment for this, to be lucky, I need a modification that will increase the range without ADC supersaturation, i.e. replacing the shunt with one with twice less resistance, i.e. practically the second same shunt connected in parallel - in the program it means multiplication of the current indication by two and increase the range to 20A.
    I only have two VAs on such a processor, the rest are on the STM8F103.
  • #16
    ElectroTom
    Level 25  
    How about the accuracy of these measures?
  • #17
    wsxcde
    Level 12  
    After calibration, it is ok. Unfortunately, the diagram does not allow for the solutions recommended by the manufacturer to increase the accuracy of measurements.
  • #18
    AlexSt
    Level 2  
    Hi wsxcde,
    Thank you very much for the arcticle and files!
    Can I ask you some questions?

    I need to do the similar things with another device based on this HC32F003 MCU. With your python script I was able to unlock MCU`s flash and with attached flasher - to read and write flash as well.
    You said that you are able to debug it via SWD and JLink. I tried to flash a bluepill with JLink fw and install Segger JLink software (in ubuntu). But unfortunately it doesn't know anything about this chip. The same is with STLink. Can you say few words how you managed to connect JLink to this MCU?
    Which development SW did you use to develop a firmware for this MCU? I found SDK only for Keil/EWW, but I cannot use none of them...
  • #19
    wsxcde
    Level 12  
    Hi AlexSt.

    I was a little bit out here and didn't notice this post.
    If it is still valid, I will try to help.
  • #20
    AlexSt
    Level 2  
    Hi wsxcde,

    Currently I solved the issue by replacing the chip by STM8L103 which is pin-to-pin compatible, and wrote a firmware.
    But I think, any details may be very helpful to anyone who tries to program HC32 chips.
  • #21
    wsxcde
    Level 12  
    I used the IAR. The CPU SDK is available e.g. here:
    https://github.com/yanjainxiong/HDMCU_ZLG/tree/master/HC32F003_SDK
    There are configuration files for the IDE, sample programs, full pinout and processor documentation.
    I connected to the system via SWD (pinout in the documentation, in the photo these are the 5 holes vertically on the left side of the board).

    How to make a J-Link adapter, how to connect? I don't know, he can search for:
    ?????? ?? BluePill ??????????? / ???????? JLink OB-STM32F103
    Official documentation of the J-Link adapter:
    https://www.segger.com/downloads/jlink/UM08023_JLinkOBSTM32F103.pdf