Go Down

Topic: PWM coding for BLDC motor (Read 1 time) previous topic - next topic

adityasreekumar

Hi,

I wanted to generate a 0.92 ms to 1.92 ms, varying ON TIME PWM signal. Total signal duration is 20ms. For testing the code, i tried generating the maximum and minimum signals.

CODE:

int inmain;
int in1;
int ipmain = 22;  //input control pin
int ip1 = 24;
int op1 = 53;    //PWM output pin


void setup()
{

pinMode(op1,OUTPUT);
pinMode(ipmain,INPUT);
pinMode(ip1,INPUT);

}


void loop()
{

inmain=digitalRead(ipmain);
in1=digitalRead(ip1);

if(inmain==LOW)
{
  digitalWrite(op1,HIGH);
  delayMicroseconds(900);
  digitalWrite(op1,LOW);
  delay(19.1);
}
else
{
  digitalWrite(op1,HIGH);
  delayMicroseconds(2000);
  digitalWrite(op2,LOW);
  delay(18);
}

}

I want to give this signal to an ESC to power the BLDC motor. The code however doesnt seem to be working. Pls Help

Aditya

PaulS

Code: [Select]
delay(19.1);
Apparently, you haven't bothered to look at the documentation for the delay function.

Quote
The code however doesnt seem to be working.

Maybe it's just taking a short vacation.

On the other hand, you could try explaining what it does do, what it does not do, and how what it does differs from what you want it to do.

There are too many things you haven't said for us to be able to help you. For instance, what is connected to pins 22 and 24? Do you KNOW that you can read consistent data from those pins? That is, are you certain that the results of digitalRead on those pins is consistent with the input you are providing?

AWOL

#2
Mar 29, 2011, 10:46 am Last Edit: Mar 29, 2011, 12:49 pm by AWOL Reason: 1
Quote
I wanted to generate a 0.92 ms to 1.92 ms, varying ON TIME PWM signal.

Have you thought about using the servo library?
It makes PPM, but 9/10 of people (when questioned) couldn't tell the difference.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Groove

Your thread title is misleading; the code is for an ESC, so the motor type is irrelevant.

AWOL nailed it.
Per Arduino ad Astra

Go Up