Serial Data interrupt and UART question

Hi all,
I have a question, and hopefully the experience on this fourm can help. I am controlling an AC motor with a precise zero-cross circuit that uses an interrupt. So whenever i need to process Serial data from Bluetooth, it delays enough to cause issues to the AC motor.

So my question, is there a work around? I was reading about a UARTs and the atmega328 (what my redboard uses) and it seems that it has a software UART ?! I believe that if I have a version like the teensy 3.1 it uses a separate hardware UART that uses its own clock to process data and therefore will let the AC circuit run independantly.

Otherwise my fix would to have a dedicated Atmega328 to process just the AC zero cross circuit.

Any ideas?

Atmega328 has a dedicated USART, But you can also use SoftwareSerial on any digital pin. However, the dedicated USART has a shallow buffer, 2 characters I think. The Arduino serial communication code builds an interrupt driven buffer for traffic. Do, you may likely get interrupt issues with h/w or s/w serial approaches.

Teensy 3.x are ARM Cortex uC,
Teensy 2.0 is an Atmel 32U4, and
Teensy++ 2.0 is AT90USB1286.

If your serial data is small and the BAUD is very fast, you may be able to interleave the zero-crossover and serial transfers... At 120 crossovers at 60Hz, if the crossover work is not lengthy there should be ample time for serial bursts.

Ray

fmeroney:
whenever i need to process Serial data from Bluetooth, it delays enough to cause issues to the AC motor.

Does this mean that the serial interrupts are taking so long, or occurring so frequently, that the zero crossing interrupt is being delayed significantly? If so, how much of a delay are you seeing?

Hi fmeroney

I sent you a PM with some other info in it, but I can't attach my LTSpice circuit of the zero crossing detector I got from here http://www.dextrel.net/diyzerocrosser.htm

So I've attached it to this posting.

Note. The V1 simulates the mains input (240V RMS mains is approx 340V peak)
V2 simulates the 5V supply on the Arduino

If you don't already have LTSpice, its free and can be downloaded from here

Its a bit clunky to use, but it does give quite accurate analogue circuit simulations.

zero_crossing2.asc (2.55 KB)

Hi Ray,
I have been talking with Other members who seem to agree that the atmega should be able to handle the task of processing serial data and detecting zero-cross... The consensus is that my code is the problem, and I have to agree after reading some other posts and some great info from RogerClark. It seems that I am calling for the serial data more than needed as well as my interrupt routine being located in the wrong area.

This would make sense since the Atmega should be up to the task...

Thanks for your comments, i will post my findings when i get to breadboard this again.

mrburnette:
Atmega328 has a dedicated USART, But you can also use SoftwareSerial on any digital pin. However, the dedicated USART has a shallow buffer, 2 characters I think. The Arduino serial communication code builds an interrupt driven buffer for traffic. Do, you may likely get interrupt issues with h/w or s/w serial approaches.
Programming AVR USART with AVR-GCC. Part 1 - Embedds

Teensy 3.x are ARM Cortex uC,
Teensy 2.0 is an Atmel 32U4, and
Teensy++ 2.0 is AT90USB1286.

If your serial data is small and the BAUD is very fast, you may be able to interleave the zero-crossover and serial transfers... At 120 crossovers at 60Hz, if the crossover work is not lengthy there should be ample time for serial bursts.

Ray

Hi Peter,
I think your spot on with the serial inputs occurring too frequently. Another member suggested that as well. Im going to rework it a bit and change where the ISR happens as well.

PeterH:

fmeroney:
whenever i need to process Serial data from Bluetooth, it delays enough to cause issues to the AC motor.

Does this mean that the serial interrupts are taking so long, or occurring so frequently, that the zero crossing interrupt is being delayed significantly? If so, how much of a delay are you seeing?

Hi Roger,
Great info, been a huge help. Im going to work the code a bit more.... Strip it down to bare bones and start over with a new approach.

rogerClark:
Hi fmeroney

I sent you a PM with some other info in it, but I can't attach my LTSpice circuit of the zero crossing detector I got from here http://www.dextrel.net/diyzerocrosser.htm

So I've attached it to this posting.

Note. The V1 simulates the mains input (240V RMS mains is approx 340V peak)
V2 simulates the 5V supply on the Arduino

If you don't already have LTSpice, its free and can be downloaded from here
Circuit Design Tools & Calculators | Design Center | Analog Devices

Its a bit clunky to use, but it does give quite accurate analogue circuit simulations.

Hi Frank,

No worries.

Feel free to use my code, but it does need an Arduino Micro or Leonardo, as they have an additional timer.

But the 2nd timer is only needed if you need smooth dimming below around 10% of the cycle. (which is likely to be when your zero crossing will occur).

Cheers

Roger