Three phase motor control with Teensy 3.2

Status
Not open for further replies.

MotorErik

Member
I'm starting an AC motor control project. Roughly like making my own specialized VFD -- Variable Frequency Drive. One piece of good news is that I've got a small three-phase AC motor spinning under Teensy control. Just using an open loop six-step sequence. Kind of the "Hello World" program for a motor. It runs and gives me confidence. Took less than 100 lines of code. The other piece of good news is that I'm a fairly experienced programmer (mostly on PIC lately).

My questions are around where to start with PWM generation. The Teensy (I'm using 3.2 now) has all these fantastic on-chip peripherals.... But I don't know them at all yet. Where is the TRIS register? :) (PIC joke) I've looked at the rather intimidating Reference Manual, and am reading some NXP ap notes. Any other suggestions? Anybody done something similar?
 
The interval timer library allows you to use up to four timers (assuming they're not being used elsewhere) to precisely control events, which would be where to start if you wanted to write all your own code; there's analogWrite() that generates PWM and the servo library that generates pulses for servos.

Teensy has a decent reference section on pjrc.com for wherever it's libraries differ from Arduino (or are otherwise better) which will be far easier to read than manuals.
 
Thanks, Edward!
Where is the Teensy Duino library reference? I have been unable to find it. Lots of good stuff on the forum and PJRC site, but I'm having trouble finding things.

For example I saw mention on the forum of the function digitalReadFast Where is this documented? Searching the forum on that term did not turn it up.

I found the digital I/O reference: https://www.pjrc.com/teensy/td_digital.html
but it seems to cover only the usual Arduino stuff not any Teensy extensions like digitalReadFast.
 
A better variant would be to study the Teensy's reference manual. The 8-channel FTM0 allows to bundle several channels in order to generate multi-phased output signals. Plus, there is a complementary mode with configurable dead time so that 3 H-Bridges could be controlled from 3 pairs of synced PWM outputs with only a few lines of code and without the overhead which most libraries bring with them.
 
Last edited:
Just for fun, here are a few photos and the "hello motor" code.

I'm using an ST IPM15b eval board, which is not much more than a breakout board for the STGIB15CH60TS integrated power module. Six 15a 600V IGBT's plus all their gate drive and protection circuitry, all in one $16 brick. Takes a lot of the black magic out of the power electronics. Much larger IPM's are available, but I thought I'd learn some of the ways to let the smoke out, using this small inexpensive smoke before I move up to the larger stuff.

One gotcha is that this module is not isolated from the power line. So the Teensy ground could be at 115v or whatever, typically half of the incoming AC voltage. Yikes! At first my improvised isolation transformer was not right, and I let the smoke out. Fortunately not my own smoke out of myself! This stuff can be dangerous. Got a better isolation setup now.

And... I really like the Adafruit USB isolator. Keep your fragile PC away from all that high voltage nastiness. Highly recommended.

So here are three photos of the experimental setup.
https://eriknjacob.smugmug.com/Tech2017

From left to right you can see a small 3-phase AC blower motor, then past the current probes is the IPM15 eval board powering it. There is a Variac in the background setting the input voltage to the IPM. Moving right is the Teensy on a breadboard, controlling the IPM. Then the Adafruit USB isolator in front of the scope showing current in one of the three legs. Yes, not very sine-like but the motor is running quietly and happily. Not bad for one afternoon of work!

The third photo is a hand drawn "six step" trapezoidal waveform for a three phase motor. This is typically used in BLDC motors. If you look closely the three phases are in three different colors.

What is the recommended way to post code here?
Here is my motor control program, cut-n-pasted.

Yes I know there is a lot this program does not do -- pwm for voltage control, true sine, etc. But hey, it's Hello World, spinning a motor in 100 lines of code.


// first motor control program
// EK 1/15/2017
// BLDC-style six-step motion, open loop, simple.
// Just get the damn thing running!

// pindefs
//switch pins are on PWM-capable pins even tho we're not doing PWM now.
const int AL = 3;
const int AH = 4;
const int BL = 5;
const int BH = 6;
const int CL = 9;
const int CH = 10;
const int LED = 13;

void setup() {
// put your setup code here, to run once:

// pindefs


// set pins as outputs
pinMode (AL, OUTPUT);
pinMode (AH, OUTPUT);
pinMode (BL, OUTPUT);
pinMode (BH, OUTPUT);
pinMode (CL, OUTPUT);
pinMode (CH, OUTPUT);
pinMode (LED, OUTPUT);

// and make sure they are all turned off
ShutDown();

// parameters for operation
const float hz = 20; // speed to run -- 60hz = full rated speed
const int runtime = 3600; // seconds to run

int steptime;
steptime = 1000000 / (hz*6); // time in microseconds for each step. six steps per cycle.
digitalWrite (LED, 1);
DoWave(steptime, (runtime*hz));
digitalWrite (LED,0);

// that's all folks!

ShutDown();

}

void loop() {
// put your main code here, to run repeatedly:

}

//////////////// SUBROUTINES
//-------------------------------------------

void DoWave(int steptime, int n)
{
int qq;
for (qq=0; qq<n; qq++)
{
//step 1
digitalWrite (AL,1); //A goes negative
digitalWrite (CL,0); // turn off C
delayMicroseconds (steptime);

//step 2
digitalWrite (BH,0); //B was high now off
digitalWrite (CH,1); // C goes high
delayMicroseconds (steptime);

//step 3
digitalWrite (AL,0);
digitalWrite (BL, 1);
delayMicroseconds (steptime);

//step 4
digitalWrite (CH,0);
digitalWrite (AH, 1);
delayMicroseconds (steptime);

//step 5
digitalWrite (BL,0);
digitalWrite (CL, 1);
delayMicroseconds (steptime);

//step 6
digitalWrite (AH,0);
digitalWrite (BH, 1);
delayMicroseconds (steptime);
} // next qq
} // return

void ShutDown(void)
{
digitalWrite (AH,0);
digitalWrite (AL,0);
digitalWrite (BH,0);
digitalWrite (BL,0);
digitalWrite (CL,0);
digitalWrite (CH,0);

}
 
About 2 years ago I started playing with the Idea of electrifying a go cart. Unlike others I decided to take my experience at work and apply it instead of just buying a controller. Initially I looked at 3phase control but decided against it due to the shear amount of unknowns. There is very little help available because its so far from what most users do, I also have a hard time wrapping my head around much of this stuff as is so it was apparent to me that I would not be able to do it without significant help from others.

Instead I went with a DC motor (ME0708), after blowing 2 pairs of $20 mosfets I was inspired to do as I was told at work and implement a PI loop. Im still tuning the loop and working on snubbers for the fets to prevent large voltage spikes. But if you plan to do anything more then spine something at a constant speed with no change in load you must use a PI loop. Or like me the first time you roll your cart out of the shed and the wheels drop 4" to the sand causing a large change in load you will be sorry.

Oddly enough just as I am having issues with Mosfets I was put on a project to take 650VDC and drop it down to provide 37.5V @ 175A, which also has noise issues similar to what I'm having at home, so I'm sticking close to our head engineer and picking up a few things on snubbers and how to calculate them.

Building a motor controller from scratch is a lot of work and takes significant time and some amount of money. It will most likely cost 1.5 - 4x as much as if you just bought a ready made controller, but it will afford you much more room for customization along the way.
 
Yes I've worked with plenty of motor controllers and VFD's but never built a serious one before. This is a paying project. We need features not available in commercial VFD's, and we need to develop this expertise in house for other more advanced projects. Yes we will have more controls, a PI loop and/or active current limiting. A fan is an "easy" load with no abrupt current changes, where a traction motor is exactly the opposite.

I've blown up a few MOSFET's myself, doing roll-your-own power projects. That's one of the reasons I like these "integrated power modules", they have all the gate drive circuitry and most of the protection circuits for over current etc built in. It's nice to work on the software with reasonably robust hardware. Then if we later decide to do more of the electronic design ourselves, we will have well behaved software to test it with. Divide the problem into manageable bites and conquer.

Donziboy wrote:
"...issues with Mosfets I was put on a project to take 650VDC and drop it down to provide 37.5V @ 175A.."

Yow, you're describing a 6.6 kW buck converter! Not a small design challenge. What are you using for the inductor?
 
Are you using sensors to know the angular position, or will you be trying to detect it b measuring currents in the undriven phase?
 
No sensors at this time. I think I can run a fan without them.

Sensors are in the plan for other applications. At the power level we're headed for the cost of the sensors is not a huge deal, and it should be simpler (and more robust?) than trying the "sensorless" approaches. If you have any suggestions they are welcome. I've got experience working with BLDC traction motors with Hall sensors.
 
Donziboy wrote:
"...issues with Mosfets I was put on a project to take 650VDC and drop it down to provide 37.5V @ 175A.."

Yow, you're describing a 6.6 kW buck converter! Not a small design challenge. What are you using for the inductor?

Using a step down transformer with a split secondary. We also have 30uH after the schottky diodes and before the bus caps.


Are you using sensors to know the angular position, or will you be trying to detect it b measuring currents in the undriven phase?

A lot of our locomotive projects use a quadrature encoder(2 hall sensors few degrees apart) with 256 teeth in the motors. Exact position is not always required. Most of our smaller projects have high accuracy sensing built into the motors.
 
Status
Not open for further replies.
Back
Top