Not simple BLDC controller It RUNS! :)

Arlo1 said:
Thanks ricky. I almost didnt even need to ask lol I just did not see that when I fisrt looked while I was tired last night.
OK I will go work at this for today.
Its sometimes a can't see the wood for the trees type thing when you look at someone else's code.
 
frock. I hooked AVss to VCC instead of pin 28 AVdd. Well there goes my first dspic chip. Now that I learnt my lesson on taking time. IM going to order some dspic30f401130I/P so I have a 40pin Dip to work with. I will Start fresh. with that in a couple weeks. Later today I will look at using my second 30f3010 chip to wip together a new brain. But my time for this is limited. Anyways progress is being made. I learnt a lot and now I build my first voltage regulator :) ... It was with a lm350 it does get hot though they say you dont need heat sync but I would advise in using one.
 
OK.... Im not proud of this but I found a preassembled prototyping board... Here http://www.ebay.ca/itm/MCU-BOARD-DEVELOPMENT-KIT-BASE-dsPIC30F4011-/120796691915?pt=LH_DefaultDomain_0&hash=item1c200b3dcb

I also ordered 2 dspic30f401130I/P chips so I can build what ever I want. But for those of you who want to get a flashed chip from leboski shoud look at the board because you just have to hook up what sensors you want and run wires to the power stage and whamy you have a killer controller you can whip together in ~ 1 day!

I figure I will work on my dspic30f3010 controller till this gets here then start on it as well. I want to build the whole thing from scratch but I still need to get a layout and make or get some boards made.
For now this will save me some time so I can work on the code.
This really is a good board for a open source project like this. I am really confident in my power stage design the isolated power supplies make life so simple!

I have worked hard on all this in the last 5 days and I learn more in 5 days then I did in the last 3 years! Man I feel like this is what I belong doing...

Next step is to build a 6 fet layout that can test the limits of the big TO247 fets and figure out whats my best choice!
 

Attachments

  • $(KGrHqF,!g8E6ZfyIOPhBOnvPsb7bg~~60_35.jpg
    $(KGrHqF,!g8E6ZfyIOPhBOnvPsb7bg~~60_35.jpg
    19.9 KB · Views: 1,956
Ok so after removing and replacing my dspic30f3010 chip this is what It looks like. I found the last chip caused the regulator to get very hot... I licked my finger and touched the regulator and it sizzled off so >100 deg C! Then I went to flash it and the pickit3 said over current problem on VDD or VSS so I tested and tested till I found I had to replace the main pic-chip not sure what caused it but now the regulator stays cool and the new chip programs. This is my last one till the dspic30f4011 chips and or the development board show up. I built the power stage with 3 isolated 12v - 12v dc supplies to run the hi side. And all of it can be plugged in to the main board. in seconds... So this will be handy if a power stage pops I can just swap it but leave the controller section!
And big PLUSS with a modular system like this you can make a power stage for ANY power level you want.... 1000 volts 10,000 amps or 10v and 10 amps what every your heart desires!
 

Attachments

  • 001.jpg
    001.jpg
    75.5 KB · Views: 1,935
  • 003.jpg
    003.jpg
    71.7 KB · Views: 1,935
  • 006.jpg
    006.jpg
    69.5 KB · Views: 1,935
  • 007.jpg
    007.jpg
    77.1 KB · Views: 1,935
  • 008.jpg
    008.jpg
    87.3 KB · Views: 1,935
  • 009.jpg
    009.jpg
    87.1 KB · Views: 1,935
Arlo, just a tip, you don't need a Xtal with the 30F4011, it has an internal oscillator. It's not as accurate as
a Xtal but you don't need accuracy (I mean, who's going to care the chips runs 3% faster or slower ?)

The 30F4011 takes 180 mA out of 5V when running at 120 MHz clock (30 MIPS), make sure your supply can handle this.

happy new year dude !
 
Lebowski said:
Arlo, just a tip, you don't need a Xtal with the 30F4011, it has an internal oscillator. It's not as accurate as
a Xtal but you don't need accuracy (I mean, who's going to care the chips runs 3% faster or slower ?)

The 30F4011 takes 180 mA out of 5V when running at 120 MHz clock (30 MIPS), make sure your supply can handle this.

happy new year dude !
My voltage regulator is good for 3 amps Happy new year to you too dude! I was hopping to make this run before the end of 2011 but I dont know whats up ATM I think there is something im missing in the code. I used this layout froim bigmoose.
 

Attachments

  • 3phBLDC-dsPIC30F3010-MTG-Technologies-V1.2.pdf
    96.1 KB · Views: 92
I just found some reading thats going to help me in the long run.
http://ww1.microchip.com/downloads/en/devicedoc/70151a.pdf only 132 pages and
http://ww1.microchip.com/downloads/en/DeviceDoc/70046D.pdf which is 760 pages on dspic chips! :shock: Ima be buisy. When im done the end of the world should be over.

As I learn all this I would like to see If i can get what I have to run a motor (just in a vise for now) but not sure what I have missed in the code I have loaded but I can't get it to do anything although I can get the led to flash at startup like bigmoose put in the one sample for me. I will build something to build up a powerstage that I can test in more depth with soon as well.
 
OK so as Dave pointed out my schematic was wrong!
It was close but here is what I belive it shoiuld be.
I am not sure on the center pin on the back so I put a ? mark anyone know???
 

Attachments

  • Capture powerstage v1.1 (800 x 425).jpg
    Capture powerstage v1.1 (800 x 425).jpg
    31.8 KB · Views: 2,023
Arlo1 said:
I am not sure on the center pin on the back so I put a ? mark anyone know???
Its an internally not connected pin. they leave it unconnected to increase the voltage difference tollerable between the high side and the low side because the standard pin spacing is too close for higher voltages. You do not need to do anything with it.
 
OK so I got my powerstage fixed up.... I am not sure why but something is cause the motor to have resistance when I power the brain up. The powerstage it self can be powered or un powered its still the same as soon as I hook 12v to the main board (which only feeds 12 to the powerstage and the brain gets 4 from the regualtor) the engine feels like the brake is on then I unhook the power and it spins freely. Im in a hurry of course lol so I will try to look again tomorow.
 
Arlo1 said:
OK so I got my powerstage fixed up.... I am not sure why but something is cause the motor to have resistance when I power the brain up. The powerstage it self can be powered or un powered its still the same as soon as I hook 12v to the main board (which only feeds 12 to the powerstage and the brain gets 4 from the regualtor) the engine feels like the brake is on then I unhook the power and it spins freely. Im in a hurry of course lol so I will try to look again tomorow.

Porbably either all 3 high side or all 3 low side FET's are on....?
 
OK I forgot to ground 2 of my isolated supplies and the corasponding H bridges. It turns freely now but I still cant make it run I have to make switch S2 or remove it from the code... Not sure what else Im missing.
 
Did some more testing tonight after I removed all the S2 parts of the code and got it to build and program. And I found one PWM output puts a pulse out but its more random then anything. I could only find the one the rest didnt seem to do anything I will do some more testing tomorow. I also knoticed the throttle has no effect on the PWM width.
I will also try to get going on the rs232 tomorow as well.
 
Arlo, building up everything, flip the switch and start debugging is the biggest mistake you can do. You gotta go "progressive bring up" dude. Disconnect everything from the microcontroller section forward (control and power signals), and then debug that part until you see the right signals with the scope on the control lines that go to the drivers. Then move on to the next stage for testing and debugging, move to the next when everything behind is already working, and so on. Otherwise, if the motor doesn't run, where is the problem? It could in in A, B or C, now guess. If you go progressive, when you're testing one stage and it's not working, you already know that the problem is only on that stage and not somewhere in the entire system, because everything behind is working and you can concentrate only on the current stage. By the time you get to the motor, everything will just work, because everything left behind is already working ;).
 
I did test things as I went along eg. Test the 5 volt regulator before connecting it. I also started with the pickit3 header pins and progtamed the dspic30f to flash an LED before hooking up there rest, and the rest is a 5 volt regulator set at 4v which I will look at today a throttle giving 1-4v to the pin for the pot and the rs232 header which I have not figured out yet other then that I have 6 resistors from the PWM pins going to the header for the powestage. I dont have a lot hooked up so its realy not hard to diagnose. And I did try to build it in stages and test each stage as I went along so Im not to lost there is not a lot it can be other then something up with the chip it self. I have DIP style chips on their way so It it is a problem with the dspic30f I should be able to correct it soon.
 
On this link to the data sheet it says in table 23-1 Operating MIPS VS. voltage
vdd range 4.5-5.5 for the dspic30f301x Not sure what modle they are trying to describe lol. Im going to have to come back when the coffee kicks in. I will try 5 volts instaed of 4 today.
 
Ok I think the brain works ok. I upped the regulator to 4.9v output and now i get pwm on all three hi side outputs and the low side comes one as I twist the throttle. I think the Pulse width is realy small so after I get back from the shop I will double check the code but I might have the wrong timer bits in the code. This shit is so fun I make a little progress every day I work on it. :mrgreen: Oscilloscopes are a must for this but so worth it!
 
When I turn the throttle I get about a 9 uS pulse from the low side....
 
Arlo1 said:
When I turn the throttle I get about a 9 uS pulse from the low side....

check how many bits the PWM register requires, and how many are in the variable that you declared. As in: int, unsigned int, long int, long unsigned int... You may not be "populating" the bits higher than 8.
 
bigmoose said:
Arlo1 said:
When I turn the throttle I get about a 9 uS pulse from the low side....

check how many bits the PWM register requires, and how many are in the variable that you declared. As in: int, unsigned int, long int, long unsigned int... You may not be "populating" the bits higher than 8.
The varible is 32bits
unsigned int StateLoTable[] = {0x0000, 0x1002, 0x0420, 0x0402,
0x0108, 0x1008, 0x0120, 0x0000};
 
This is the whole code
I am going to dig though it today

Code:
#define   __dsPIC30F3010__
#include "p30F3010.h"
#define FCY 5000000   // 5 MHz Xtal*PLLof4/(4*Postscalerof1)
#define MILLISEC FCY/10000// 1 mSec delay constant
#define FPWM 16000
#define Ksp 1200
#define Ksi 10
#define RPMConstant 60* (FCY/256)
void InitTMR3(void);
void InitADC10(void);
void AverageADC(void);
void DelayNmSec(unsigned int N);
void InitMCPWM(void);
void CalculateDC(void);
void GetSpeed(void);
struct {
unsigned RunMotor : 1;
unsigned Minus : 1;
unsigned unused : 14;
} Flags;
unsigned int HallValue;
int Speed;
unsigned int Timer3;
unsigned char Count;
unsigned char SpeedCount;
int DesiredSpeed;
int ActualSpeed;
int SpeedError;
int DutyCycle;
int SpeedIntegral;
/*************************************************************
Low side driver table is as below. In this StateLoTable,
the Low side driver is PWM while the high side driver is
either on or off. This table is used in this exercise
*************************************************************/
unsigned int StateLoTable[] = {0x0000, 0x1002, 0x0420, 0x0402,
0x0108, 0x1008, 0x0120, 0x0000};
/****************************************************************
Interrupt vector for Change Notification CN5, 6 and 7 is as below.
When a Hall sensor changes states, an interrupt will be caused which
will vector to the routine below.
The user has to then read the PORTB, mask bits 3, 4 and 5,
shift and adjust the value to read as 1, 2 ... 6. This
value is then used as an offset in the lookup table StateLoTable
to determine the value loaded in the OCDCON register
*****************************************************************/
void _ISR _CNInterrupt(void)
{
IFS0bits.CNIF = 0; // clear flag
HallValue = PORTB & 0x0038; // mask RB3,4 & 5
HallValue = HallValue >> 3; // shift right 3 times
OVDCON = StateLoTable[HallValue];// Load the overide control register
}
/*********************************************************************
The ADC interrupt loads the DesiredSpeed variable with the demand pot
value. This is then used to determing the Speed error. When the motor
is not running, the PDC values use the direct Demand value from the pot.
*********************************************************************/
void _ISR _ADCInterrupt(void)
{
IFS0bits.ADIF = 0;
DesiredSpeed = ADCBUF0;
if (!Flags.RunMotor)
{
PDC1 = ADCBUF0; // get value ...
PDC2 = PDC1; // and load all three PWMs ...
PDC3 = PDC1; // duty cycles
}
}
/************************************************************************
The main routine controls the initialization, and the keypress to start
and stop the motor.
************************************************************************/
int main(void)
{
LATE = 0x0000;
TRISE = 0xFFC0; // PWMs are outputs
CNEN1 = 0x00E0; // CN5,6 and 7 enabled
CNPU1 = 0x00E0; // enable internal pullups
IFS0bits.CNIF = 0; // clear CNIF
IEC0bits.CNIE = 1; // enable CN interrupt
SpeedError = 0;
SpeedIntegral = 0;
InitTMR3();
InitMCPWM();
InitADC10();
while(1)
{
DelayNmSec(10);
// read hall position sensors on PORTB
HallValue = PORTB & 0x0038; // mask RB3,4 & 5
HallValue = HallValue >> 3; // shift right to get value 1, 2 ... 6
OVDCON = StateLoTable[HallValue];// Load the overide control register
PWMCON1 = 0x0777; // enable PWM outputs
Flags.RunMotor = 1; // set flag
T3CON = 0x8030; // start TMR3
while (Flags.RunMotor) // while motor is running
   {
if (HallValue == 1) //IF in sector 1
{
HallValue = 0xFF; // force a new value as a sector
if (++Count == 5) // do this for 5 electrical revolutions or 1
// mechanical revolution for a 10 pole motor
{
Timer3 = TMR3;// read latest tmr3 value
TMR3 = 0;
Count = 0;
GetSpeed();// determine spped
}
}
PWMCON1 = 0x0700;// disable PWM outputs
OVDCON = 0x0000; // overide PWM low.
Flags.RunMotor = 0;// reset run flag
DelayNmSec(10);
}
} // end of while (1)
}
/*******************************************************************
Below is the code required to setup the ADC registers for :
1. 1 channel conversion (in this case RB2/AN2)
2. PWM trigger starts conversion
3. Pot is connected to CH0 and RB2
4. Manual Stop Sampling and start converting
5. Manual check of Conversion complete
*********************************************************************/
void InitADC10(void)
{
ADPCFG = 0xFFF8; // all PORTB = Digital;RB0 to RB2 = analog
ADCON1 = 0x0064; // PWM starts conversion
ADCON2 = 0x0000; // sample CH0 channel
ADCHS = 0x0002; // Connect RB2/AN2 as CH0 = pot.
ADCON3 = 0x0080; // Tad = internal RC (4uS)
IFS0bits.ADIF = 0; // clear flag
IEC0bits.ADIE = 1; // enable interrupt
ADCON1bits.ADON = 1; // turn ADC ON
}
/********************************************************************
InitMCPWM, intializes the PWM as follows:
1. FPWM = 16000 hz
2. Independant PWMs
3. Control outputs using OVDCON
4. Set Duty Cycle using PI algorithm and Speed Error
5. Set ADC to be triggered by PWM special trigger
*********************************************************************/
void InitMCPWM(void)
{
PTPER = FCY/FPWM - 1;
PWMCON1 = 0x0700; // disable PWMs
OVDCON = 0x0000; // allow control using OVD
PDC1 = 100; // init PWM 1, 2 and 3 to 100
PDC2 = 100;
PDC3 = 100;
SEVTCMP = PTPER; // special trigger is 16 period values
PWMCON2 = 0x0F00; // 16 postscale values
PTCON = 0x8000; // start PWM
}
/************************************************************************
Tmr3 is used to determine the speed so it is set to count using Tcy/256
*************************************************************************/
void InitTMR3(void)
{
T3CON = 0x0030; // internal Tcy/256 clock
TMR3 = 0;
PR3 = 0x8000;
}
/************************************************************************
GetSpeed, determins the exact speed of the motor by using the value in
TMR3 for every mechanical cycle.
*************************************************************************/
void GetSpeed(void)
{
if (Timer3 > 23000) // if TMR3 is large ignore reading
return;
if (Timer3 > 0)
Speed = RPMConstant/(long)Timer3;// get speed in RPM
ActualSpeed += Speed;
ActualSpeed = ActualSpeed >> 1;
if (++SpeedCount == 1)
{SpeedCount = 0;CalculateDC();}
}
/*****************************************************************************
CalculateDC, uses the PI algorithm to calculate the new DutyCycle value which
will get loaded into the PDCx registers.
****************************************************************************/
void CalculateDC(void)
{
DesiredSpeed = DesiredSpeed*3;
Flags.Minus = 0;
if (ActualSpeed > DesiredSpeed)
SpeedError = ActualSpeed - DesiredSpeed;
else
{
SpeedError = DesiredSpeed - ActualSpeed;
Flags.Minus = 1;
}
SpeedIntegral += SpeedError;
if (SpeedIntegral > 9000)
SpeedIntegral = 0;
DutyCycle = (((long)Ksp*(long)SpeedError + (long)Ksi*(long)SpeedIntegral) >> 12);
DesiredSpeed = DesiredSpeed/3;
if (Flags.Minus)
DutyCycle = DesiredSpeed + DutyCycle;
else DutyCycle = DesiredSpeed - DutyCycle;
if (DutyCycle < 100)
DutyCycle = 100;
if (DutyCycle > 1250)
{DutyCycle = 1250;SpeedIntegral = 0;}
PDC1 = DutyCycle;
PDC2 = PDC1;
PDC3 = PDC1;
}
//---------------------------------------------------------------------
// This is a generic 1ms delay routine to give a 1mS to 65.5 Seconds delay
// For N = 1 the delay is 1 mS, for N = 65535 the delay is 65,535 mS.
// Note that FCY is used in the computation. Please make the necessary
// Changes(PLLx4 or PLLx8 etc) to compute the right FCY as in the define
// statement above.
void DelayNmSec(unsigned int N)
{
unsigned int j;
while(N--)
for(j=0;j < MILLISEC;j++);
}
 
I removed this video because I don't want metallica suing me lol.
The good news is Im all the way to the pwm at the gates.
 
OK SO im getting a 8.6 uS pulse on one Hi and a different low side at the same time when turning the throttle. I think I must still have a problem with the powerstage.
 
Whats the minumum voltage to turn a 4115 mosfet on? It says it has a gate charge of 77nC typ. and 120nC max. I am 7.8v at first to the gate then it climbs to 9.8 after 8.6uS
And the Hi side gets 9.6v then falls to 8.4 at the end of the 8.6uS
 
Back
Top