BLDC motor

Can anyone give the code for sensor less bldc motor. Hope it will very useful anyone helps.

You must give us more information.
What motor? Do you have a link to the data sheet or specs?
What are you hoping to do?

There are many commercial speed controls that run brushless motors. Is that an option for you?

google open-bldc

Sorry for the short message. I am using 3 phase bldc motor which has a spec of 36v and 10amps(360w).
I have used a h bridge circuit to control it. But the motor is running only on single direction. And the mosfet gets heated up.Mosefet irf3205(55v and 98amp) and irf4905(55v and 75 amp).

I have attached the code which was already coded by someone in this forum.

#include <PWM.h>
int32_t frequency = 20000; //pwm frequency in Hz
unsigned int n = 0, timer2_initial_value, s = 0;
void setup(){
InitTimersSafe();
bool success = SetPinFrequencySafe(9, frequency);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(13, OUTPUT);
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
// initialize timer2 interrupt for adc reading
noInterrupts(); // disable all interrupts
TCCR2A = 0;
TCCR2B = 0;
timer2_initial_value = 0;
TCNT2 = timer2_initial_value; // preload timer
TCCR2B |= (1 << CS22) |(1 << CS21) | (1 << CS20); // 1024 prescaler
TIMSK2 |= (1 << TOIE2); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
ISR(TIMER2_OVF_vect) // interrupt service routine
{
TCNT2 = timer2_initial_value; // preload timer
n++;
if (n>20){
n = 0;
if (s != analogRead(A0)){
s = analogRead(A0);
pwmWrite(9,s/4);}}
}
int fwd(){
while(1){
if (digitalRead(2)==1){
if (digitalRead(1)==0){
if (digitalRead(0)==1){
digitalWrite(8,0);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,1);digitalWrite(4,1);digitalWrite(3,0);}
else {
digitalWrite(8,1);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,1);digitalWrite(4,0);digitalWrite(3,0);}}

if (digitalRead(1)==1){
if (digitalRead(0)==0){
digitalWrite(8,1);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,1);}}}

if (digitalRead(2)==0){
if (digitalRead(1)==1){
if (digitalRead(0)==0){
digitalWrite(8,0);digitalWrite(7,0);digitalWrite(6,1);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,1);}
else {
digitalWrite(8,0);digitalWrite(7,1);digitalWrite(6,1);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,0);}}

if (digitalRead(1)==0){
if (digitalRead(0)==1){
digitalWrite(8,0);digitalWrite(7,1);digitalWrite(6,0);
digitalWrite(5,0);digitalWrite(4,1);digitalWrite(3,0);}}}
if (digitalRead(12)==0) break;}
}
int bwd(){
while(1){
if (digitalRead(2)==1){
if (digitalRead(1)==0){
if (digitalRead(0)==1){
digitalWrite(8,0);digitalWrite(7,0);digitalWrite(6,1);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,1);}
else {
digitalWrite(8,0);digitalWrite(7,1);digitalWrite(6,1);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,0);}}

if (digitalRead(1)==1){
if (digitalRead(0)==0){
digitalWrite(8,0);digitalWrite(7,1);digitalWrite(6,0);
digitalWrite(5,0);digitalWrite(4,1);digitalWrite(3,0);}}}

if (digitalRead(2)==0){
if (digitalRead(1)==1){
if (digitalRead(0)==0){
digitalWrite(8,0);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,1);digitalWrite(4,1);digitalWrite(3,0);}
else {
digitalWrite(8,1);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,1);digitalWrite(4,0);digitalWrite(3,0);}}

if (digitalRead(1)==0){
if (digitalRead(0)==1){
digitalWrite(8,1);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,1);}}}
if (digitalRead(12)==0) break;}
}

void loop(){
digitalWrite(13, LOW);
pwmWrite(9,s);
digitalWrite(8,0);digitalWrite(7,0);digitalWrite(6,0);
digitalWrite(5,0);digitalWrite(4,0);digitalWrite(3,0);
if (digitalRead(10)==0) {digitalWrite(13, HIGH);bwd();}
if (digitalRead(11)==0) {digitalWrite(13, HIGH);fwd();}
}

The mosfets need drivers to make them switch faster. That will solve the (over)heat problem.

The other solution is to add a prebuilt motor controller (ESC)

Nihaludeen:
Mosefet irf3205(55v and 98amp) and irf4905(55v and 75 amp).

Both mosfets are not logic level, and can't be driven directly with a 5volt Arduino pin.
Mosfet drivers are needed both for voltage swing (10-12volt) and switching speed.
Post a diagram, showing how you have connected the mosfets.
Leo..

I have made changes in the circuit . But still the motor is running only on single direction.

Mart

MarkT:
google open-bldc

I have googled, but i doesn't get an exact code for arduino.

36volt motor?
I hope you don't use a 36volt supply for that h-bridge diagram.
Vgs(max) of the mosfets is 20volt.
Leo..

Look at the FAN7388 and FAN7888 datasheets for how to make a 3-phase MOSFET bridge that has
a hope of working at 36V. You can make a 3-phase bridge from 3 1/2 H-bridges like the IRS2001
(which is available in DIP form unlike the FAN7388).

But be aware at high powers you will be on a steep learning curve and will blow up a few MOSFETs
and drivers along the way unless very careful. You need to understand shoot-through and how
to prevent it, you need to think about fast over-current protection.

Do not start working at full voltage and current, start at much lower powers, with current limited
supply, and build up to higher powers. You really will benefit from access to an oscilloscope because
without being able to see the switching waveforms you won't know what went wrong if things go
wrong...

And lastly if by 36V 10A motor you mean one with a running current of 10A, expect it to be easily able
to pull stall currents in the range 50 to 100A, power supply permitting, which can be very challenging.

Good advice on the BLDC Controller, Mark_T. On a similar note, I'm working on an application where I need to ping an ultrasonic sensor at 1MHz.

I remember not too far back, you had written code around using the Atmega32U4, if I remember correctly, to do 3-phase PWM Motor Control. The 32U4 is a natural for this, but Timer4 can be intimidating. If you still have the code around, could you either post it or email it to me?

Being able to study what you did should help me in getting the Timers set up. I should add my app needs two complementary phases, which is why I'd like to study what you did.
--- Thanks.

A timer with two output pins can be configured for complementary phases, since each pins' polarity
is set by one of the control registers. Deadtime is then managed by outputting slightly different values
to the OCR for each pin.