Pages: [1]   Go Down
Author Topic: PWM coding for BLDC motor  (Read 1524 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50123
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26477
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 29, 2011, 05:49:59 am by AWOL » Logged

"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.

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

AWOL nailed it.
Logged

Per Arduino ad Astra

Pages: [1]   Go Up
Jump to: