Jump to content
43oh

IRremote library sometimes leaves led on


Recommended Posts

As reported in this topic (sending samsung tv raw ir codes) sometimes the led stays on after transmitting.

I see that the library defines these macros:

#define TIMER_ENABLE_PWM     (TA1CTL = TASSEL_2 + MC_1) // SMCLK, Up mode  
#define TIMER_DISABLE_PWM    (TA1CTL = TASSEL_2 + MC_0) // SMCLK, Stop mode
#define TIMER_ENABLE_INTR    ({ /*TA1CTL |= TAIE;*/ TA1CCTL0 |= CCIE;}) // SH 071112 
#define TIMER_DISABLE_INTR   ({TA1CTL &= ~TAIE; TA1CCTL0 &= ~CCIE;})
#define TIMER_INTR_NAME      TIMER1_A0_VECTOR
#define TIMER_CONFIG_KHZ(val) ({ \
      TA1CCTL0 |= OUTMOD_4;      \
      TA1CCR0 = FOSC/val/2;      \
})

and to send a space it uses TIMER_DISABLE_PWM.

Now, I don't know exactly how the timers in a msp430 work, but OUTMOD_4 is Toggle and MC_0 stops the timer.

Is it possible that if it is stopped when the led is on it will stay on?

 

Link to post
Share on other sites

I modified the library with the attached patch, now the led doesn't stay on anymore but I cannot control my TV set (lirc, which probably is more tolerant with the timing, recognizes the codes).

 

Edit: I'm not permitted to attach this kind of file, inlined here

--- IRremoteInt.h.orig  2014-04-21 10:29:43.489878975 +0200
+++ IRremoteInt.h       2014-04-21 11:33:19.417113888 +0200
@@ -142,15 +142,16 @@
 // P2SEL |= BIT3; // P2.3 option select
 #define TIMER_PIN_SELECT() ({ \
   P2DIR |= BIT3;              \
-  P2SEL |= BIT3;              \
+  P2SEL &= ~BIT3;              \
+  P2OUT &= ~BIT3;              \
 })
 
 // defines for Timer_A (16 bits)
 // NOTE: Using A1 instead of A0 because A0 is used by Serial
 #if defined(IR_USE_TIMERA)
 #define TIMER_RESET
-#define TIMER_ENABLE_PWM     (TA1CTL = TASSEL_2 + MC_1) // SMCLK, Up mode
-#define TIMER_DISABLE_PWM    (TA1CTL = TASSEL_2 + MC_0) // SMCLK, Stop mode
+#define TIMER_ENABLE_PWM     ({TA1CTL = TASSEL_2 + MC_1; P2SEL |= BIT3;}) // SMCLK, Up mode
+#define TIMER_DISABLE_PWM    ({TA1CTL = TASSEL_2 + MC_0; P2SEL &= ~BIT3; P2OUT &= ~BIT3;}) // SMCLK, Stop mode
 #define TIMER_ENABLE_INTR    ({ /*TA1CTL |= TAIE;*/ TA1CCTL0 |= CCIE;}) // SH 071112 
 #define TIMER_DISABLE_INTR   ({TA1CTL &= ~TAIE; TA1CCTL0 &= ~CCIE;})
 #define TIMER_INTR_NAME      TIMER1_A0_VECTOR
--- IRremote.cpp.orig   2014-04-21 11:36:07.333117889 +0200
+++ IRremote.cpp        2014-04-21 11:29:03.862107798 +0200
@@ -215,8 +215,8 @@
   
   TIMER_PIN_SELECT(); // P2.3 output and P2.3 option select (when TIMER_PWM_PIN is P2_3)
 
-  pinMode(TIMER_PWM_PIN, OUTPUT);
-  digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
+  //pinMode(TIMER_PWM_PIN, OUTPUT);
+  //digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
 
   // TODO: update the comments below
 

Link to post
Share on other sites

BINGO, I reduced the delays by 10% and now I can control my tv. It means that the timings are off by 10%. Why? Bad calibration data in my msp?

The commented out values are the correct ones (according to the NEC specifications).

Note that 10% was just a guess, since I don't have a scope to check the real timing.

 

Edit: in case it's relevant, I'm still using energia 0101E0011, I'll try later with the latest version.

Edit2: tried with 0101E0012, it's the same.

#define NEC_HDR_MARK    8100 //9000
#define NEC_HDR_SPACE   4050 //4500
#define NEC_BIT_MARK    504 //560
#define NEC_ONE_SPACE   1521 //1690
#define NEC_ZERO_SPACE  504 //560

Link to post
Share on other sites
  • 3 weeks later...

I just tried the code on an arduino pro mini and it works without modification, so either the port to energia is wrong or the delayMicroseconds function is way off.

As I don't have a scope I cannot say exactly, but I suspect the latter.

Worthy of a bug report?

Link to post
Share on other sites

Fwiw I reread the first post, yeah the timer configuration primitives there are bad (should use the TAxCCTLy registers to expose or unexpose a pin from PWM, or at least PxSEL/PxSEL2).

 

Not sure about delayMicroseconds but I wouldn't be terribly surprised if its precision is insufficient. No idea how "small" of a delay we're talking about without actually looking into the library...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...