Go Down

Topic: BUG delayMicroseconds(input), output=input/0.75 (Read 2110 times) previous topic - next topic

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

Quote

#include <IRremote.h>
#define TSOPG         49
#define TSOPV         51
#define RECV          53

#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

IRrecv irrecv(RECV);
decode_results results;

void setup() {
  pinMode(TSOPG, OUTPUT);
  pinMode(TSOPV, OUTPUT);
  pinMode(RECV, INPUT);
  pinMode(BLDC, OUTPUT);
  digitalWrite(TSOPG, LOW);
  digitalWrite(TSOPV, HIGH);
  irrecv.enableIRIn();          //Start the IR receiver
}

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);
}


robtillaart


Note that the other instructions in loop() especially digitalwrite() also consumes time.

have a look at - http://www.arduino.cc/en/Reference/PortManipulation - for faster writing.

(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
Code: [Select]

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);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AWOL

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

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.

AWOL

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy