Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCMM protocol sender disables delayMicroseconds()? #20

Open
caliban17 opened this issue Mar 23, 2017 · 5 comments
Open

RCMM protocol sender disables delayMicroseconds()? #20

caliban17 opened this issue Mar 23, 2017 · 5 comments

Comments

@caliban17
Copy link

I am attempting to send RCMM protocol IR codes and wrote a very simple test sketch. Weirdly the call to delayMicroseconds after each send does not work at all (no matter what value I attempt to delay, the 3 'sends' are always 17.4 microseconds apart, which I assume is the loop overhead.) I tested delayMicroseconds() with another sketch (not using the IRLib2) and it works fine on my UNO board.

/*

  • Taken from send.ino Example sketch for IRLib2
  • Illustrates how to send a code.
  • Modified to try and send sky remote codes
    */
    #include <IRLibSendBase.h> // First include the send base
    #include <IRLib_P11_RCMM.h>

IRsendRCMM mySender; //declare a sender object

const uint8_t SEND_REPEATS = 3; // total number of times to send an IR message
const uint16_t SEND_DELAY = 90; // delay between repeats in microseconds (us)
const uint32_t CODE_IR = 0x23802603; //code for button '3'

/*********************************************************
*

  • Purpose: Sends the IR signl in the nz Sky protocol
  • Calls:
  • Parameters: uint32_t data to be sent
  • Return: void
    *********************************************************/
    void sendSkyNZ(uint32_t data) {
    for (uint8_t i = 0; i < SEND_REPEATS; i++)
    {
    mySender.send(data,32);
    //Serial.print(F("Abt to delay, i= "));Serial.println(i,DEC);
    delayMicroseconds(SEND_DELAY);
    }
    }

void setup() {
Serial.begin(115200);
delay(2000); while (!Serial); //delay for Leonardo
Serial.println(F("Every time you press a key is a serial monitor we will send."));
}

void loop() {
if (Serial.read() != -1) {
//send a code every time a character is received from the
// serial port.
sendSkyNZ(CODE_IR);
Serial.println(F("Sent signal."));
}
}

@cyborg5
Copy link
Owner

cyborg5 commented Mar 24, 2017

How are you measuring the resulting gap between signals? Keep in mind that 90 micro seconds isn't very long. I set up your output sketch and change your SEND_DELAY to "1". I sent the signals using one Arduino and receive them using a second one and the autoResume sample sketch. The "Gap" value was about 17,000 micro seconds. But it varied up or down a few hundred. Changing your SEND_DELAY to value as small as 90 is barely going to make a measurable difference. Are you sure you didn't want to use "Delay (SEND_DELAY);" instead of delayMicroseconds (SEND_DELAY);? I changed SEND_DELAY to 1000 and got measurable results.

Also if you look at the code for sending RCMM it always concludes the transmission with a space of
space(27778-extent);

where "extent" is the total length of the transmitted code. I don't exactly recall where I got that number 27778 from but that is the reason for some of the delay between signals. You always have to end a transmission with a reasonable amount of blank space so that the receiver can detect that you really ended a frame of data. The IRP notation for 12 and 24 bit versions of the product, doesn't show what the closing space should be. The 32-bit version says 100m so I can't really say why I put 27778. I must've gotten that number from some other reference.

Whether or not my trailing space is correct or not, your delay of 90 microseconds is still pretty insignificant. Why did you pick that value? Why is the inter-frame timing important to you?

@cyborg5
Copy link
Owner

cyborg5 commented Mar 24, 2017

Add the following code to your sketch.

uint32_t Value= micros();
 delayMicroseconds(SEND_DELAY);
 uint32_t Duration=micros()- Value;
 Serial.print("gap duration ="); Serial.println(Duration,DEC);
 

I get a consistent value of 92 which is as accurate as the micros() can measure.

@caliban17
Copy link
Author

caliban17 commented Mar 24, 2017 via email

@caliban17
Copy link
Author

caliban17 commented Mar 24, 2017 via email

@cyborg5
Copy link
Owner

cyborg5 commented Mar 24, 2017

If you did space(20000);space(20000);space(20000);space(20000);space(20000);space(10000); then what you got was 90 milliseconds not 90 microseconds. That is why I suggested you use "delay(90)" and not "delayMicroseconds not (90)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants