I have a bug with the arduino 1.0.1 IDE
I have 2 brushless controllers, which require 1-2ms of pulses.
So i write BLDC_us=1500; and I get nothing, so I measured with digital signal osciloscope, and it was actually 2000us. Now I have to use Kproportional=0.75 to change it. In software 1500*0.75=1125
Well I dont like this anyway it consumes my time. =(
Please help to fix the delayMicroseconds() function
#define UP 0x2C9B //Inflate duty cycle, as button T #define DOWN 0x6C9B //Deflate duty cycle, as button W #define POWER 0x4C9D //Turn off 0 as RED "Power" button
#define BLDC 12
int BLDC_us=1125; //1125/0.75=1500us
void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {
case UP : BLDC_us=constrain(BLDC_us+1,750,1500); break;
case DOWN : BLDC_us=constrain(BLDC_us-1,750,1500); break;
case POWER : BLDC_us=1125; break;
default: break;
}
irrecv.resume(); //Prepare to receive the next value
}
digitalWrite(BLDC, HIGH);
delayMicroseconds(BLDC_us);
digitalWrite(BLDC, LOW);
delayMicroseconds(BLDC_us);
}
(especially if you prepare the bitmasks in advance).
And I would remove the constrain from the switch and use only 2 if statements.
partially patched - not tested
void loop() {
if (irrecv.decode(&results))
{
switch (results.value)
{
case UP : if (BLDC_us < 1500) BLDC_us++;
break;
case DOWN : if (BLDC_us > 750) BLDC_us--;
break;
case POWER : BLDC_us=1125;
break;
default: break;
}
irrecv.resume(); //Prepare to receive the next value
}
//digitalWrite(BLDC, HIGH);
PORTB = highmask;
delayMicroseconds(BLDC_us);
// digitalWrite(BLDC, LOW);
PORTB = lowmask;
delayMicroseconds(BLDC_us);
}
I have 2 brushless controllers, which require 1-2ms of pulses.
Do you have a link to the controller?
The pulse timings you give are suspiciously like R/C PWM timings, except your code always give a low frequency 50% duty cycle, which is fairly unusual.
If it is an R/C controller, you'll get better results with the servo library.
Well, i tested the stuff, before I had arduino, directly with ATmega16 and Atmel Studio, and it just receives a pulse width 1-2ms, possible minimum gap between as low as 10us.
Hobby King 100A Car ESC. But it doesent matter, the code bugs with the other ESC from Ebay. I have to keep a correction.