Transmitter code question in old IR post

In the below old post (read only), in the transmitter code, is the transmitter 38khz pulse being output all the time, or just only when a serial bit is being sent? If the 38khz pulse is being continuously sent, then I'm curious about the 74ALS02 logic and just how the communication takes place (74ALS02 and TSOP1138 data sheet links below).

http://forum.arduino.cc/index.php/topic,10555.0.html

http://pdf.datasheetcatalog.com/datasheet/philips/74ALS02D.pdf

http://www.vishay.com/docs/82006/tsop11xx.pdf

The 38kHz signal is being generated all the time - you can detect it if you have a multimeter that can measure frequency.

It is only allowed to get to the IR LED when data is sent by the Tx pin - that's the purpose of the LS02 NOR gate.

Although I have been using this circuit recently I haven't actually thought about why a NOR gate is used or whether any other type could be used - for example an AND or NAND?

I guess you could write code to make the 38kHz signal go on and off directly but the beauty of this design is that it works directly with the normal serial output.

...R

It is only allowed to get to the IR LED when data is sent by the Tx pin - that’s the purpose of the LS02 NOR gate.

Looking t the function table, it seems to me that the only time the IR LED will be turned off is when both the 38khz pin and the tx pin are high. When the tx is not sending anything, it is normally high, but the 38khz line is continuously going high/low. When the 38khz line is low, the out put of the gate is high, lighting the LED.

When I posted yesterday I was thinking the same as @zoomkat. But I've just remembered that I have a red led connected to the same output as the IR led so I can be sure it is working and I have viewed the IR led with my phone camera which can see a bit of IR. The led is only ON in flashes that correspond with data being sent. I obviously can't distinguish the 38khz signal but if you use a low baud rate you can see the bits causing flicker.

The signal from the TSOP is high in the idle state (which is standard for serial data) so perhaps the Arduino Tx is also high in the idle state. This seems likely to be true because when I was testing the code in my receiver it worked fine if I bypassed the IR system and wired the Arduino Tx to my device's Rx. My code relies on idle "high" to know nothing is being transmitted so it can go back to sleep.

...R

The arduino tx and rx pins are normally high in the idle state. This combined with the hardware in use led to my question if the 38khz modulation is only instated when the tx pin is in a low state. If the 38khz modulation is always present, I couldn't see how the setup was able to work. From your observation of your setup it appears that the code somehow monitors the state of the tx pin and only does the 38khz modulation when tx is low. Below is the original tx code, but it is beyond my easy understanding of what is going on.

// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define SYSCLOCK 16000000  // main system clock (Hz)
#define PULSECLOCK 38000  // Hz
#define IROUT 11

uint8_t timer2top(unsigned long freq) ;

void setup() {
  Serial.begin(2400) ;

  cbi(TCCR2A,COM2A1) ; // connect OC2A (COM2A0 = 1)
  sbi(TCCR2A,COM2A0) ;
  
  cbi(TCCR2B,WGM22) ;  // CTC mode for TIMER2
  sbi(TCCR2A,WGM21) ;
  cbi(TCCR2A,WGM20) ;
  
  TCNT2 = 0 ;
  
  cbi(ASSR,AS2) ;  // use system clock for timer 2
  
  OCR2A = 255 ;   // set TOP to 255 for now
  
  cbi(TCCR2B,CS22) ;  // TIMER2 prescale = 1
  cbi(TCCR2B,CS21) ;
  sbi(TCCR2B,CS20) ;
  
  cbi(TCCR2B,FOC2A) ;  // clear forced output compare bits
  cbi(TCCR2B,FOC2B) ;

  pinMode(IROUT, OUTPUT) ;  // set OC2A to OUPUT  
  OCR2A = timer2top(PULSECLOCK) ; 
  sei() ;
}

// main loop
void loop() {
  Serial.println("Hello, world!") ;  
  delay(5000) ;
}

// return TIMER2 TOP value per given desired frequency (Hz)
uint8_t timer2top(unsigned long freq) {
  return((byte)((unsigned long)SYSCLOCK/2/freq) - 1) ;
}

I believe the output of a NOR is only high if both inputs are low. That means that the idle HIGH of the Tx pin will prevent the IR square wave from appearing at the output.

The code just sets up timer 2 to count up to a certain number and then flip the state of the output pin and start counting again.

...R

I believe the output of a NOR is only high if both inputs are low. That means that the idle HIGH of the Tx pin will prevent the IR square wave from appearing at the output.

That would be the logic that works, but I'm having trouble matching that to the logic shown in the function table for the chip. But I'm not that use to function/logic tables (or maybe I'm looking at the wrong chip!).

What chip?
What function/logic table?

…R

I discuss here how to generate and modulate a 38 kHz signal:

http://gammon.com.au/forum/?id=11504&reply=6#reply6

What chip?

The 74ALS02 I thought was used in the schematic in the original IR post.

What function/logic table?

The one I copied from the 74ALS02 data sheet and attached in a previous post.