RC ESC modification part3 : Wire up RC ESC and 328P in 6 PWM with simpleFOC

Selection of MCU:

ATMega328p has 6pwm, just enough for 3p BLDC, which I can use to control the S2101 gatedrive.  and this is also a MCU supported by simple FOC, but used to control some other gatedrive and mosfet, S2101is not officially supported in the example.




the down side of 328P is the PWM frequency is fixed at 32Khz, don't see too much trouble in my eyes.

I still have a pro mini 5V 16Mhz, decide to give it a try.(not sure if 8Mhz pro mini can also do the job, I believe the PWM frequency is only half.)

Connection:

since 6PWM is still supported by simple FOC, and 328P have just enough PWM pins, so, go for 6PWM with 328P.
base on the documentation:https://docs.simplefoc.com/bldcdriver6pwm, the pair of Hin and Lin of each gate drive is fix as follow.


Arduino UNO and all the atmega328 based boards have only 6 pwm pins and in order to use the BLDCDrievr6PWM we need to use all of them. Those are 3,5,6,9,10 and 11. Furthermore in order for the algorithm to work well we need to use the pwm pins that belong to the same timer for each high/low side pair of each phase. 7 So Atmega328 pins belonging to the timers are:

TIM0TIM1TIM2
5,69,103,11

Wire up the 6 PWM wires and the GND pin.


I try to use a low Kv motor I have :a T-motor NM3508-29 with 380Kv, 14 mag, i.e. 7 pole pairs 



which I added a As5600 mag sensor, the base is 3d printed.



Tested with AS5600 library, the IIC reading is correct.

Test with open loop:

I want to first test without sensor, to make sure the wire and driving are OK.

It's recommended to put phase resistance in code, I'm not sure should it measure with real current voltage data? I pick my battery internal resistor meter and tool the measure, 3 phases are between 225-245 mOhm.

The Kv value, simple FOC recommanded to put 1.5 times of marked.



Consideration in coding:

The pair of pin of each phase should be written in code like this:
//  BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
//  - phA_h, phA_l - A phase pwm pin high/low pair 
//  - phB_h, phB_l - B phase pwm pin high/low pair
//  - phB_h, phC_l - C phase pwm pin high/low pair
//  - enable pin    - (optional input)
BLDCDriver6PWM motor = BLDCDriver6PWM(5,6, 9,10, 3,11, 8);

The enable is optional. The code should work like this:

BLDCDriver6PWM driver = BLDCDriver6PWM(5, 6, 9,10, 3, 11);

A example with 2101 is here: https://community.simplefoc.com/t/deadtime-6pwm-hacking-10-36v-500w-bldc-controller-to-run-simplefoc/431/4

2101 gatedrive does not control the relation of Hin and Lin, there is a chance that H and L are on at same time and make a short circuit.

The dead zone can be set: https://docs.simplefoc.com/bldcdriver6pwm#step-22-dead-zone-dead-time

// dead_zone [0,1] - default 0.02 - 2%
driver.dead_zone = 0.05;

it's in percentage of a duty cycle, so 0.05=5%







2101 and MOSFET both has rising delay and require rising time. I got following nr from data sheet.

2101:t on/off (typ.) 160 & 150 ns, Delay Matching 50 ns

MOSFET has someting like this:

td(on) Turn–On Delay Time 15~27 ns
tr Turn–On Rise Time 13 23 ns
td(off) Turn–Off Delay Time 62 99 ns
tf Turn–Off Fall Time
36 58 ns

Since the dead zone Nr is set in percentage of duty cycle, there is no means to calculated the delay for dead zone.

previous example need to set to 0.1 to avoid mosfet heating. I will see what would be my case.

I majorly use the code I found in part2 and modify some parameters:





Using power supply to limit the current, and hope no heating nor smoke.

The motor works when I put. PSU at 12V...

interesting is that when I change the deadzone, the current changes, if I set dead zone @=0.1, the motor is a little cogging. but the current is small.

This one is with dead zone =0.05, the current is a bit high, but motor run smooth.





This one is with dead zone =0.1, the current is low, but motor run cloggy.



This one is with dead zone =0.07, the current is between above 2, but motor runs ok...





More testing should be done on finding the "good" dead zone.....


Test on position control

although dead zone still need to be tuned, I tested position mode with AS5600,
I believe the PID also need to be tuned.(not sure if there is any auto tune...)
But to see the modified ESC works in quite interesting.



留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone