diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b74b7a293a63746f29af406be58971f44cd2fe5b --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# MachineKit BLDC Driver + +See: [Circuit Development](https://gitlab.cba.mit.edu/jakeread/mkbldcdriver/tree/master/circuit), and [Code Development](https://gitlab.cba.mit.edu/jakeread/mkbldcdriver/tree/master/embedded) + +## Background, Motivation + +This project is largely a follow-on to [my Teensy-Powered Brushless Motor Controller](https://github.com/jakeread/tesc), and with this new work, may the TESC project RIP. A moment of silence. + +TESC, April 2016 - August 2016 +*As the world turns, +so did those motors. +Once around is never enough* + +Eulagies aside, I am still motivated to do this. Brushless motors are the go-to motive force for electromechanical systems. By that I mean that just about any time you see a robot-like thing, or machine, moving about, there's a big likelihood that the thing doing-the-moving has a brushless motor in it's guts - or some variant thereof (stepper motors count as BLDCs in my books). + +#### A few things to understand: + +**(1) Electric Motors move by rotating a magnetic field** - we have something with magnets, and something else with electromagnets, we use the electromagnets to rotate the field, we pull the magnets along. Rotating the field is called *Commutating* or *Commutation*. + +**(2) Brushed Motors rotate the magnetic field using 'brushes'** - these are mechanical switches that use the motor's own rotation to change the magnetic field. Super neat. [Here's a link to Sparkfun's explanation](https://learn.sparkfun.com/tutorials/motors-and-selecting-the-right-one/dc-brush-motors---the-classic) + +And a GIF. While the rotor rotates, different switches are connected to current, and the coils - to - pads relationship is set up such that the current will cause the motor to rotate. Pardon my abbreviated explanation. + + + +Brushes are awesome - and make motors very simple. You just pump voltage (so current) through the rotor, and things happen. However, there are resistive losses at the brushes, as well as friction losses. + +With the advent of transistor technology (for switching logic AND for switching big power) we can do this electronically - use a computer (or simple timer) to switch the phases. + +**(3) Brushless Motors rotate the magnetic field with switches** - so we can make the coils stationary, and 'artificially' switch the direction and timing of current flowing through them. Here's a nice GIF of sinusoidal commutation (where phase currents follow a nice, smooth wave). + + + +We can see the three current vectors (that translate into a combined magnetic field vector). We also have a simpler type of switching, where we only turn two of the three phases on at a time. You can see an example of that [here](https://www.youtube.com/watch?v=oFI7VW6WGR4) - including a nice diagram of the switch setup. + +#### Where it gets complicated: + +- Circuit design to switch big voltages / currents +- Closed loop control on current in motor +- Sensing: rotor position, electrical phase, offsets, shunt amplifiers oh my! + +#### Towards accessible robotics + +Mostly the motivation for me to go through this is (1) to train myself in the field, and (2) to help others along a similar journey, not just cobbling bits together, but understanding how and why they work. This is ongoing work! \ No newline at end of file diff --git a/circuit/README.md b/circuit/README.md index 3baeb1364b934748a79209d61bdc6a5df3612669..9e94df64fbe5e0574752838ff213234968491051 100644 --- a/circuit/README.md +++ b/circuit/README.md @@ -1,49 +1,6 @@ -# MachineKit BLDC Driver +# Machine Kit BLDC Driver: Circuit Development -## Background, Motivation - -This project is largely a follow-on to [my Teensy-Powered Brushless Motor Controller](https://github.com/jakeread/tesc), and with this new work, may the TESC project RIP. A moment of silence. - -TESC, April 2016 - August 2016 -*As the world turns, -so did those motors. -Once around is never enough* - -Eulagies aside, I am still motivated to do this. Brushless motors are the go-to motive force for electromechanical systems. By that I mean that just about any time you see a robot-like thing, or machine, moving about, there's a big likelihood that the thing doing-the-moving has a brushless motor in it's guts - or some variant thereof (stepper motors count as BLDCs in my books). - -#### A few things to understand: - -**(1) Electric Motors move by rotating a magnetic field** - we have something with magnets, and something else with electromagnets, we use the electromagnets to rotate the field, we pull the magnets along. Rotating the field is called *Commutating* or *Commutation*. - -**(2) Brushed Motors rotate the magnetic field using 'brushes'** - these are mechanical switches that use the motor's own rotation to change the magnetic field. Super neat. [Here's a link to Sparkfun's explanation](https://learn.sparkfun.com/tutorials/motors-and-selecting-the-right-one/dc-brush-motors---the-classic) - -And a GIF. While the rotor rotates, different switches are connected to current, and the coils - to - pads relationship is set up such that the current will cause the motor to rotate. Pardon my abbreviated explanation. - - - -Brushes are awesome - and make motors very simple. You just pump voltage (so current) through the rotor, and things happen. However, there are resistive losses at the brushes, as well as friction losses. - -With the advent of transistor technology (for switching logic AND for switching big power) we can do this electronically - use a computer (or simple timer) to switch the phases. - -**(3) Brushless Motors rotate the magnetic field with switches** - so we can make the coils stationary, and 'artificially' switch the direction and timing of current flowing through them. Here's a nice GIF of sinusoidal commutation (where phase currents follow a nice, smooth wave). - - - -We can see the three current vectors (that translate into a combined magnetic field vector). We also have a simpler type of switching, where we only turn two of the three phases on at a time. You can see an example of that [here](https://www.youtube.com/watch?v=oFI7VW6WGR4) - including a nice diagram of the switch setup. - -#### Where it gets complicated: - -- Circuit design to switch big voltages / currents -- Closed loop control on current in motor -- Sensing: rotor position, electrical phase, offsets, shunt amplifiers oh my! - -#### Towards accessible robotics - -Mostly the motivation for me to go through this is (1) to train myself in the field, and (2) to help others along a similar journey, not just cobbling bits together, but understanding how and why they work. Also, providing better tools / kits / examples to others who are putting robotic systems together. - -## Circuit Design - -This page is incomplete - I'm going to violently segue into a roughly train-of-though design process now. +Warning! Train-of-though documentation! #### FET Selection @@ -151,6 +108,46 @@ And completed - looks nice!  +## Testing + +Here's my setup: + + + +And I'm using a 24V Supply - I designed & rated this to 83V (capacitors are largely 100v, 83v rating comes from the DRV8302 and the FETS). But I want to stay safe and steer clear of burnouts for now. + +I carefully checked all of my pinouts and double-checked that I was sending a PWM signal that I liked, then I turned it on! I had some success, and then a stall. I *thought* I saw some smoke, so not sure what's up. + +I also noticed the power lines to the ATSAM chip started to flash - so I am having a power supply issue to my brain-board. This whole situation is more complicated than it needs to be. The DRV has a 5V Buck regulator, and uses that 5V Signal on a few pins... so I can't just throw it out. The ATSAM board has a 5V line, that it passes through a regulator to get the 3v3 it needs. + +I imagine the 5V Buck Regulator on the DRV8302 is unhappy - it's actually a fairly complex thing, using some feedback loops to control a PWM cycle, that then is filtered with an LC on the output to generate a smooth 5V. I imagine this is going unstable. + +What I did to diagnose the whole thing was connect my logic analyzer to the 5V line, 3V3 line, and to my three phases. Note - not *directly* to my three phases, as they will be being driven to 24v, and I'm quite sure I would fry my logic analyzer. I already have voltage dividers setup for the microcontroller to read the phase voltages, so here I'm just reading off of those. Nice. + + + +The first three are my gate voltages - they're being driven very nicely, thanks very much. The bottom two lines are my 5V (Channel 3) and 3V3 lines (Channel 4). So, this is dropping, the pwms are becoming very sad, and this oscillation starts. + +It looks like I can remedy this by just supplying also 3V3 with my UART Cable - although I know I'll be introducing basically conflicting 3V3 lines, which is bad. We'll give it a go. + +OK, great success! First thing's first, my motor turns: + + + +This is good news. Better news, I can read all of my phase voltages, and it looks like I'm getting satisfactory reading on my current sensing circuitry as well. + +The traces here are: (0) Phase U Voltage, (1) Phase V Voltage, (2) Phase W Voltage, (3) 5V Line, (4) 3V3 Line, (5) Phase V Current, and (6) Phase W Current. + +Here we see happy PWM cycles above, and what looks like a chopped sinusiod (of current) below. + + + +Zoom in: + + + +I sped this up some and it looks more like a chopped sinusoid - this means I should either dial down the sense amplification (I think the two options are gains of 10 and 40), or put smaller shunts on - right now I have 0.005 Ohm shunts (I wanted a more sensitive measurement for smaller currents). + ## Incremental Notes - 2.2uF @ 100v -> 1206 smallest available package. Can replace with 1uF or up package. - Would via to heat-pad underneath fets, next time. could also go to 2oz copper but have to push out to 0.2mm spacing. diff --git a/embedded/README.md b/embedded/README.md index b947d151ac6d197f9232dc01f8e8d04e8ac09a70..b4c49b8033345494ccb39795262e5f21a9c58860 100644 --- a/embedded/README.md +++ b/embedded/README.md @@ -140,10 +140,6 @@ Here we go, a sinusoidal PWM: I think I'm ready to check all of my other motor controller IO's - like, do I need to assert, also, an enable pin? I forget. Then I'll plug it in, and flip the switch, ho-ha! Yep - I just have on extra PIO to add, an Enable Pin. Set this up. -I also took a minute to make this test stand, wire up all of the high power lines etc... - -- img - ## UART OK, I'm going to bring up the UART. I have a block of code for this from my networks project that I'll try bringing in. @@ -191,6 +187,6 @@ Note - the handler does not distinguish between an RXReady event and the other i Some ARM Documentation is [here](http://infocenter.arm.com/help/index.jsp) - navigate to Cortex-M7 Documentation, the latest revision, and look for NVIC. -## Hardware, Awaken! +From here, I brought up the hardware - a satisfying adventure. Go [here](https://gitlab.cba.mit.edu/jakeread/mkbldcdriver/tree/master/circuit) for that. -OK, this is satisfactory, for now, for register banging. I'm going to try bringing the hardware up now, i.e. turning the motor on. \ No newline at end of file +Then I worked (briefly) on implementing a control interface for this using mods. That should be [here](http://fab.cba.mit.edu/classes/863.17/CBA/people/jakeread/) in week 12. \ No newline at end of file diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.bin b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.bin index dc922000258461b2da44bfa2e7b3d8fa3f6c455f..3a6d833130a3ce0304dbbf592a37208351b75858 100644 Binary files a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.bin and b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.bin differ diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.elf b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.elf index fa8edb19fa7ced118d5b950e31a3adec9b8b813e..4184c85e74f8c35844bbcfbb91bd204e4b2e6f2c 100644 Binary files a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.elf and b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.elf differ diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.hex b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.hex index eab266bb78c88b6bc7a5a7da459d3be2ef25e795..1de0ae18df3808443acf7f02d8ec6b329589627b 100644 --- a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.hex +++ b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.hex @@ -135,7 +135,7 @@ :100850007F43C7F8283259F825309B01A8FB0323B2 :10086000DB09043323F07F43C7F8483259F82630B8 :100870009B01A8FB0323DB09043323F07F43C7F864 -:1008800068324FF2CE10194B98470D48184B9847D5 +:10088000683241F2F820194B98470D48184B9847A9 :100890000028C3D00A48174B9847C2E7C10340005D :1008A0002D02400050180E40EB0140007D06400034 :1008B0006906400070144020000E0E40F301400015 diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.lss b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.lss index f955431dd77c2e06a97979f4c2850a151ad222d6..0205e272fdd215354397f442394a156e4e000ed9 100644 --- a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.lss +++ b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.lss @@ -19,21 +19,21 @@ Idx Name Size VMA LMA File off Algn CONTENTS, READONLY 7 .debug_info 00009e32 00000000 00000000 000214c3 2**0 CONTENTS, READONLY, DEBUGGING - 8 .debug_abbrev 00001541 00000000 00000000 0002b2f5 2**0 + 8 .debug_abbrev 00001532 00000000 00000000 0002b2f5 2**0 CONTENTS, READONLY, DEBUGGING - 9 .debug_loc 00001263 00000000 00000000 0002c836 2**0 + 9 .debug_loc 00001263 00000000 00000000 0002c827 2**0 CONTENTS, READONLY, DEBUGGING - 10 .debug_aranges 00000430 00000000 00000000 0002da99 2**0 + 10 .debug_aranges 00000430 00000000 00000000 0002da8a 2**0 CONTENTS, READONLY, DEBUGGING - 11 .debug_ranges 00000390 00000000 00000000 0002dec9 2**0 + 11 .debug_ranges 00000390 00000000 00000000 0002deba 2**0 CONTENTS, READONLY, DEBUGGING - 12 .debug_macro 00017323 00000000 00000000 0002e259 2**0 + 12 .debug_macro 00017323 00000000 00000000 0002e24a 2**0 CONTENTS, READONLY, DEBUGGING - 13 .debug_line 0000656d 00000000 00000000 0004557c 2**0 + 13 .debug_line 0000656d 00000000 00000000 0004556d 2**0 CONTENTS, READONLY, DEBUGGING - 14 .debug_str 0006cca6 00000000 00000000 0004bae9 2**0 + 14 .debug_str 0006cca6 00000000 00000000 0004bada 2**0 CONTENTS, READONLY, DEBUGGING - 15 .debug_frame 00000964 00000000 00000000 000b8790 2**2 + 15 .debug_frame 00000964 00000000 00000000 000b8780 2**2 CONTENTS, READONLY, DEBUGGING Disassembly of section .text: @@ -1366,7 +1366,7 @@ __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) 40087a: f023 437f bic.w r3, r3, #4278190080 ; 0xff000000 40087e: f8c7 3268 str.w r3, [r7, #616] ; 0x268 delay_us(period * 10); - 400882: f24f 10ce movw r0, #61902 ; 0xf1ce + 400882: f241 20f8 movw r0, #4856 ; 0x12f8 400886: 4b19 ldr r3, [pc, #100] ; (4008ec <main+0x1b4>) 400888: 4798 blx r3 if(pin_get_state(&stlr)){ // ? diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.map b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.map index 4bd327e49aca9d09cfc8a0faab97e0a9df477f03..c2589ca79bdf03a8cf5496f8cdd986737f1ec76f 100644 --- a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.map +++ b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.map @@ -3573,7 +3573,7 @@ OUTPUT(atsams70-bldc.elf elf32-littlearm) .debug_info 0x000072eb 0x55b src/ASF/sam/utils/cmsis/sams70/source/templates/system_sams70.o .debug_info 0x00007846 0x25ec src/main.o -.debug_abbrev 0x00000000 0x1541 +.debug_abbrev 0x00000000 0x1532 .debug_abbrev 0x00000000 0x12d src/tinyport.o .debug_abbrev 0x0000012d 0x230 src/ASF/sam/drivers/wdt/wdt.o .debug_abbrev 0x0000035d 0x232 src/pin.o @@ -3583,7 +3583,7 @@ OUTPUT(atsams70-bldc.elf elf32-littlearm) .debug_abbrev 0x00000dca 0x1a4 src/ASF/common/boards/user_board/init.o .debug_abbrev 0x00000f6e 0x153 src/ASF/sam/utils/cmsis/sams70/source/templates/gcc/startup_sams70.o .debug_abbrev 0x000010c1 0x102 src/ASF/sam/utils/cmsis/sams70/source/templates/system_sams70.o - .debug_abbrev 0x000011c3 0x37e src/main.o + .debug_abbrev 0x000011c3 0x36f src/main.o .debug_loc 0x00000000 0x1263 .debug_loc 0x00000000 0xca src/tinyport.o diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.srec b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.srec index af4dec552eecc589e74297e77e518ae4c52ac86c..ac398e804c069d68357794c18ee950e1feeb2ea5 100644 --- a/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.srec +++ b/embedded/atsams70-bldc/atsams70-bldc/Debug/atsams70-bldc.srec @@ -135,7 +135,7 @@ S21440084059F824309B01A8FB0323DB09043323F02B S2144008507F43C7F8283259F825309B01A8FB03236D S214400860DB09043323F07F43C7F8483259F8263073 S2144008709B01A8FB0323DB09043323F07F43C7F81F -S21440088068324FF2CE10194B98470D48184B984790 +S214400880683241F2F820194B98470D48184B984764 S2144008900028C3D00A48174B9847C2E7C103400018 S2144008A02D02400050180E40EB0140007D064000EF S2144008B06906400070144020000E0E40F3014000D0 diff --git a/embedded/atsams70-bldc/atsams70-bldc/Debug/src/main.o b/embedded/atsams70-bldc/atsams70-bldc/Debug/src/main.o index 3a92c8236b896a584c85a84b7e54802c1a6f3e60..6a891228c9063db6b3dc03a4c50a91d85a3200f1 100644 Binary files a/embedded/atsams70-bldc/atsams70-bldc/Debug/src/main.o and b/embedded/atsams70-bldc/atsams70-bldc/Debug/src/main.o differ diff --git a/embedded/atsams70-bldc/atsams70-bldc/src/main.c b/embedded/atsams70-bldc/atsams70-bldc/src/main.c index 3e13924775f060af24d97b1d20578e662060f963..da7fb041d18fa4405b9c46ec999ca52a3c7878be 100644 --- a/embedded/atsams70-bldc/atsams70-bldc/src/main.c +++ b/embedded/atsams70-bldc/atsams70-bldc/src/main.c @@ -181,7 +181,7 @@ int main (void) startupflash(); uint8_t scalar = 64; // 0 -> 255 (these will be chars from serial) - uint8_t period = 255; // us between ++ in phase + uint8_t period = 20; // us between ++ in phase uint32_t phaseu = 0; // 0 -> 1023 uint32_t phasev = 341; // advanced 120 degrees diff --git a/images/test-all-sensing-one.jpg b/images/test-all-sensing-one.jpg new file mode 100644 index 0000000000000000000000000000000000000000..31da3060623c81aa1bd54eca4f53502ef7b80bf8 Binary files /dev/null and b/images/test-all-sensing-one.jpg differ diff --git a/images/test-all-sensing-three.jpg b/images/test-all-sensing-three.jpg new file mode 100644 index 0000000000000000000000000000000000000000..402a358a940623c16fdfd7093528f31b06769987 Binary files /dev/null and b/images/test-all-sensing-three.jpg differ diff --git a/images/test-all-sensing-two.jpg b/images/test-all-sensing-two.jpg new file mode 100644 index 0000000000000000000000000000000000000000..92ba1f22cb947631badc1eb7e7989bc34a6b51f3 Binary files /dev/null and b/images/test-all-sensing-two.jpg differ diff --git a/images/test-buck-unbuck.jpg b/images/test-buck-unbuck.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6b3bab9340f5d0ab59bff1be1a305861277518f1 Binary files /dev/null and b/images/test-buck-unbuck.jpg differ diff --git a/images/test-first-turns.gif b/images/test-first-turns.gif new file mode 100644 index 0000000000000000000000000000000000000000..a82dd91b75ab65bac4b5ed2547bab8d7e1afe4ee Binary files /dev/null and b/images/test-first-turns.gif differ diff --git a/images/test-stand.jpg b/images/test-stand.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4f7f3fc73e1e9de9c64c2df7fada867678d68605 Binary files /dev/null and b/images/test-stand.jpg differ