3

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.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Feb 23, 2017 at 22:10

1 Answer 1

3

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.

answered Feb 23, 2017 at 22:29
3
  • 1
    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 Commented Feb 23, 2017 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. Commented Feb 23, 2017 at 22:44
  • I was able to get a copy of the library directly from github......now to try it out.....THANKS. Commented Feb 23, 2017 at 22:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.