IRremote irSendRaw hangs arduino mkr1000

Im trying to blink my IR LED through the IRremote library's irSendRaw function but upon running the code the mkr just hangs up, it cant even serial print in the setup.

#include <IRremote.h>

IRsend irsend;

int khz = 38; // 38kHz carrier frequency for the NEC protocol

unsigned int irSignal1[] = {9028, 4478, 664, 1644, 662, 544, 662, 544, 662, 1646, 663, 543, 663, 1645, 662, 544, 662, 544, 662, 1646, 663, 1645, 662, 543, 663, 544, 663, 543, 662, 544, 663, 544, 662, 545, 662, 544, 662, 544, 663, 544, 661, 544, 663, 544, 662, 1646, 663, 1645, 663, 543, 664, 543, 663, 543, 663, 544, 663, 543, 662, 1646, 662, 544, 663, 1645, 663, 543, 663, 544, 662, 1646, 662, 543, 663, 19976, 663, 544, 663, 543, 664, 544, 663, 543, 669, 537, 662, 544, 662, 544, 662, 544, 663, 543, 663, 544, 662, 544, 663, 543, 664, 542, 664, 1644, 663, 543, 663, 544, 663, 543, 663, 543, 662, 543, 664, 542, 664, 543, 663, 543, 663, 544, 662, 544, 663, 543, 663, 543, 663, 543, 663, 543, 663, 543, 663, 543, 664, 543, 663, 1644, 663};

unsigned int irSignal2[] = {9030, 4478, 658, 1651, 658, 527, 680, 550, 657, 549, 658, 548, 659, 1649, 659, 527, 680, 549, 657, 1650, 658, 1649, 634, 574, 657, 549, 658, 549, 633, 573, 633, 572, 635, 572, 634, 573, 633, 574, 657, 551, 630, 577, 630, 576, 631, 1677, 632, 575, 632, 575, 631, 576, 631, 575, 632, 574, 633, 574, 633, 1675, 633, 575, 631, 1678, 631, 573, 634, 576, 631, 1676, 633, 575, 632, 20012, 635, 574, 638, 570, 631, 576, 631, 575, 632, 574, 632, 574, 633, 575, 632, 575, 632, 575, 632, 574, 634, 572, 634, 573, 634, 573, 633, 1675, 633, 575, 631, 575, 633, 572, 634, 572, 635, 573, 633, 574, 633, 575, 631, 575, 633, 574, 633, 573, 634, 574, 634, 574, 631, 577, 630, 576, 631, 575, 631, 576, 632, 575, 631, 575, 632};

void setup()
{
  Serial.begin(115200);
Serial.println("Running Program");

}

void loop() {
  Serial.println("Starting");

  Serial.println("Turning Aircon ON");
  irsend.sendRaw(irSignal1, sizeof(irSignal1) / sizeof(irSignal1[0]), khz); //Note the approach used to automatically calculate the size of the array.

  delay(3000);

  Serial.println("Turning Aircon OFF");
  irsend.sendRaw(irSignal2, sizeof(irSignal2) / sizeof(irSignal2[0]), khz); //Note the approach used to automatically calculate the size of the array.

  Serial.println("Ending");
  delay(3000);
}

The code above does not work nothing show up on serial monitor even the "Running program" inside setup. BUT if i comment out irsend.sendRaw() everything works fine all the serial prints show up.

I conclude that the sendRaw() function is the one messing up,

I even disconnected PIN 12, where the irLED should be connnected on the MKR1000, and it still doesnt work. anyone know why?

Have you tried running the examples that come with the library?

gfvalvo:
Have you tried running the examples that come with the library?

yes same situation with the sendRaw function commenting it out prints the console log i added

I've never used that library (although I know many on the forum have), so I have no insights. My usual debugging technique in a case like this is to start digging into the library's source code. Sprinkle in some debug prints and try to determine how far execution gets before hanging and where that happens.

gfvalvo:
I've never used that library (although I know many on the forum have), so I have no insights. My usual debugging technique in a case like this is to start digging into the library's source code. Sprinkle in some debug prints and try to determine how far execution gets before hanging and where that happens.

Can you help me with some terminologis sooo i have found sendRaw

void  IRsend::sendRaw (const unsigned int buf[],  unsigned int len,  unsigned int hz)
{ 

  Serial.println(len);
  Serial.println(hz);
 // Set IR carrier frequency
 enableIROut(hz);
//
// for (unsigned int i = 0;  i < len;  i++) {
// if (i & 1)  space(buf[i]) ;
// else        mark (buf[i]) ;
// }
//
// space(0);  // Always end with the LED off
}

the first line from top to bottom that hangs is enableIRout(hz) I followed that

void  IRsend::enableIROut (int khz)
{
 // Disable the Timer2 Interrupt (which is used for receiving IR)
 TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt

 pinMode(TIMER_PWM_PIN, OUTPUT);
 digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low

 // COM2A = 00: disconnect OC2A
 // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
 // WGM2 = 101: phase-correct PWM with OCRA as top
 // CS2  = 000: no prescaling
 // The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
 TIMER_CONFIG_KHZ(khz);
}

and the line that cause it is TIMER_CONFIG_KHZ(khz) which there 10 instances its begin defined i here is the code of the entire file where those 10 are placed

Code too long so ill link the github of the library file

Thats where i am now i still have to figure out which of the 10 defines does my program compiles// defines for TCC/TC timers on MKR1000
#elif defined(IR_USE_TIMER_MKR)

#define TIMER_RESET { \
  REG_TC5_INTFLAG = TC_INTFLAG_MC0; /* clear interrupts */ \
}

#define TIMER_ENABLE_PWM { \
  REG_TCC0_CTRLA |= TCC_CTRLA_ENABLE; \
  while (TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_MASK); \
}

#define TIMER_DISABLE_PWM { \
  REG_TCC0_CTRLA &= ~TCC_CTRLA_ENABLE; \
  while (TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_MASK); \
}

#define TIMER_ENABLE_INTR { \
  NVIC_EnableIRQ(TC5_IRQn); \
  REG_TC5_INTENSET = TC_INTENSET_MC0; \
}

#define TIMER_DISABLE_INTR { \
  NVIC_DisableIRQ(TC5_IRQn); \
  REG_TC5_INTFLAG = TC_INTFLAG_MC0; \
}
#define TIMER_INTR_NAME     TC5_Handler

//-----------------
#ifdef ISR
#	undef ISR
#endif
#define  ISR(f) void f(void)

//-----------------
#define TIMER_CONFIG_KHZ(val) ({ \
  REG_TCC0_CTRLA &= ~TCC_CTRLA_ENABLE; \
  while (TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_MASK); \
  uint32_t cc = SYSCLOCK / (val * 1000) - 1; \
  REG_TCC0_CC3 = cc / 2; \
  while (TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_MASK); \
  REG_TCC0_PER = cc; \
  while (TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_MASK); \
})

#define TIMER_CONFIG_NORMAL() ({ \
  REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TC4_TC5); \
  while (GCLK->STATUS.bit.SYNCBUSY); \
  REG_TC5_CTRLA &= ~TC_CTRLA_ENABLE; \
  while (TC5->COUNT16.STATUS.bit.SYNCBUSY); \
  REG_TC5_CTRLA = TC_CTRLA_SWRST; \
  while (TC5->COUNT16.CTRLA.bit.SWRST); \
  REG_TC5_CTRLA |= TC_CTRLA_MODE_COUNT16 | TC_CTRLA_WAVEGEN_MFRQ; \
  uint16_t cc = SYSCLOCK / (1000000 / USECPERTICK) - 1; /* 20 khz */ \
  REG_TC5_COUNT16_CC0 = cc; \
  while (TC5->COUNT16.STATUS.bit.SYNCBUSY); \
  REG_TC5_CTRLA |= TC_CTRLA_ENABLE; \
  while (TC5->COUNT16.STATUS.bit.SYNCBUSY); \
})

#define TIMER_PWM_PIN  12

this seems to be the most reasonable one. But since its register manipulation i dont have the knowhow

Im going to look for a rawsend that does not use the library

It's not clear to me if that library supports SAMD boards. Not sure how you even got it to compile.

gfvalvo:
It's not clear to me if that library supports SAMD boards. Not sure how you even got it to compile.

I ohh i had a customized IRlib for mkr1000. Anyway i gave up on that and instead going to use adafruits IRLib wich fully states its supports the mkr1000

even that needs some minor tweaking like increasing buffer length, but for the send I CANNOT FIND A DAMN PIN NUMBER TO USE !!!!

Apologies for the slight loose of temper. I cant find what pin to use or how to set it. I tried placing a visible LED i seem can to find the pin by manually trying all of them (Maybe too fast to blink)

Well, that was a waste of my time. How do you expect to get meaningful help if you don't disclose the libraries you're actually using?

no no no i did not mean to They both have the same name, until i checked its README which contains this line . I am really thankful for your help. I do not remember where i got this library from. Because when i looked back on the github i first gave you, it did not contains the samd21 definition, so i went looking why

It finally worked. Upon using Adafruits IR library which has better support for the MKR1000. The only modification i made was increase the buffer size since i needed it on IRLibGlobals.h. IR send and recieved worked using the example files