1

I'm asking this because I'm using a timer to generate a 38KHZ signal to drive an IR diode, and I also need to use SoftwareSerial to talk to an HC-12 radio using serial communication.

The code I'm using was written by Nick Gammon and is here:

//Setup Conter/overflow to create 38KHZ drive for IR38KHZ
//38khz, no interrupts
#define IR_CLOCK_RATE 38000L
// toggle on compare, clk/1
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
// 38kHz carrier/timer
OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
pinMode(IR38KHZ, OUTPUT);

I'm not quite up-to-date on the timer use on an Arduino (I'm using a Nano), plus I've no idea what the SoftwareSerial library uses.

2

No. It uses pin-change interrupts to trigger reception, and both reception and transmission use calibrated delay loops. However, interrupts are disabled during both transmission and reception so that the calibrated delay loops remain always the precise length - so if you do anything with any other interrupts they will not work at the same time as SoftwareSerial.

  • The SoftwareSerial uses almost all cpu time. The AltSoftSerial uses less cpu time, but it does use Timer1 : pjrc.com/teensy/td_libs_AltSoftSerial.html Since you use Timer2, you still have the option to use AltSoftSerial. Even when all three timers are used, it is still possible to add a speaker to your Nano with TimerFreeTone: bitbucket.org/teckel12/arduino-timer-free-tone/wiki/Home – Jot Feb 23 '17 at 22:35
  • When I try to link to altsoft serial, I get this:The owner of www.pjrc.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website. This site uses HTTP Strict Transport Security (HSTS) to specify that Firefox may only connect to it securely. As a result, it is not possible to add an exception for this certificate. – crusader27529 Feb 23 '17 at 22:44
  • I was able to get a copy of the library directly from github......now to try it out.....THANKS. – crusader27529 Feb 23 '17 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.