Converting PWM signal to binary on/off signal

Thread Starter

TelluriumCrystal

Joined Nov 14, 2014
32
I am currently designing a diagnostics system for gathering startup data from flight computers in a high power rocket. The flight computer relevant to my question, the StratologgerCF, outputs startup data via a buzzer. It also has a three pin connector that can be used to drive an LED or buzzer at the same frequency and pattern as the on-board buzzer. I want to interpret this signal with an ATmega328 so I know when the flight computer's buzzer is beeping.

I contacted their support about what signal was outputted via these pins and received the following information:
"The signal is a 3.3 volt digital signal that toggles at the beep frequency. The audio frequency is fast enough that if you connect it to an LED it will appear to the eye as a series of blinks at the same rate and timing of the beep tones from the beeper on board the altimeter."

So it would appear that, more likely than not, the signal is a PWM signal outputted by the flight computer at an audio frequency. A brief investigation of the store page has me suspicious that the frequency of the PWM signal is 2.5 kHz.

Now I am relatively unfamiliar with analog signals, but my understanding is that in order to get this signal into a format recognizable by the ATmega328 I need to convert it to a simple on/off signal. The best way I can think of doing this is to trigger a transistor with the PWM signal, but I have no clue how to "flatten" a PWM signal such that it will trigger the transistor. Will I need a filter of some kind? Or am I going about this the wrong way?

Any help is greatly appreciated! I am also very interested in learning more about working with analog signals, so if anyone has any recommended reading on the subject I would appreciate being pointed to it.
 

MrChips

Joined Oct 2, 2009
30,824
All electrical signals are analog signals. PWM is an analog signal, albeit it only has two voltage levels, low and high, or 0V and 3.3V in your case.

You are going about it the wrong way. There is no need for an additional transistor.
Feed the signal directly into an MCU input pin that is capable of generating an interrupt on input level change.
 

Thread Starter

TelluriumCrystal

Joined Nov 14, 2014
32
My concern though is that if I feed the microcontroller with the PWM signal, it will get interrupted very frequently. The ATmega328 I will be using will be running at 16 mHz, which is a lot faster than the audio PWM signal, which is (probably) at 2.5 kHz. Would the microcontroller not be interrupted with each "pulse" of the PWM signal?

Again, all I want to know is if the signal is present or not.
 

MrChips

Joined Oct 2, 2009
30,824
My concern though is that if I feed the microcontroller with the PWM signal, it will get interrupted very frequently. The ATmega328 I will be using will be running at 16 mHz, which is a lot faster than the audio PWM signal, which is (probably) at 2.5 kHz. Would the microcontroller not be interrupted with each "pulse" of the PWM signal?

Again, all I want to know is if the signal is present or not.
The ATmega328 is fast enough that it can service an interrupt within 10μs (my guess). All you need to do is set a flag every time you get an interrupt.
Set an internal timer to start on the interrupt and timeout for 500μs. Clear your flag when the timer expires after 500μs.

Your other solution is using external hardware. Trigger a retriggerable monostable multivibrator such as 74HC123 set with a delay of 500μs.
The output of the monostable will be high so long as it receives a trigger within 500μs of the previous trigger.

Note that the software solution more or less matches the hardware solution.
 

Thread Starter

TelluriumCrystal

Joined Nov 14, 2014
32
I guess that answers my question then. If interpreting the PWM signal won't lock up the ATmega328 then the best way is to do it in software. Thinking back I dunno why I was so convinced it would be a problem, given how much faster the ATmega328 is compared to the PWM signal.

Thanks for the help!
 

jpanhalt

Joined Jan 18, 2008
11,087
My concern though is that if I feed the microcontroller with the PWM signal, it will get interrupted very frequently. The ATmega328 I will be using will be running at 16 mHz, which is a lot faster than the audio PWM signal, which is (probably) at 2.5 kHz. Would the microcontroller not be interrupted with each "pulse" of the PWM signal?

Again, all I want to know is if the signal is present or not.
Digitizing a PWM signal is easily done with a timer. Let the timer run continuously and capture the registers with each "tick." After the start, you only need two new captures per period, as the end of the previous period is the beginning of the next. PIC's do that well. I am not familiar with Atmega, but I would be very surprised if it did not offer the same functionality. The math takes care of any rollover -- assuming it is not more than once per period.

John
 

schmitt trigger

Joined Jul 12, 2010
907
My two yen..........and at risk of over complicating stuff, perhaps a tone detector made with a CD4046 PLL would do the trick.

The 4046 has a phase-pulses digital output which can be used to detect whether a tone is present or not, and may be easily interfaced to the controller.
 

hp1729

Joined Nov 23, 2015
2,304
I am currently designing a diagnostics system for gathering startup data from flight computers in a high power rocket. The flight computer relevant to my question, the StratologgerCF, outputs startup data via a buzzer. It also has a three pin connector that can be used to drive an LED or buzzer at the same frequency and pattern as the on-board buzzer. I want to interpret this signal with an ATmega328 so I know when the flight computer's buzzer is beeping.

I contacted their support about what signal was outputted via these pins and received the following information:
"The signal is a 3.3 volt digital signal that toggles at the beep frequency. The audio frequency is fast enough that if you connect it to an LED it will appear to the eye as a series of blinks at the same rate and timing of the beep tones from the beeper on board the altimeter."

So it would appear that, more likely than not, the signal is a PWM signal outputted by the flight computer at an audio frequency. A brief investigation of the store page has me suspicious that the frequency of the PWM signal is 2.5 kHz.

Now I am relatively unfamiliar with analog signals, but my understanding is that in order to get this signal into a format recognizable by the ATmega328 I need to convert it to a simple on/off signal. The best way I can think of doing this is to trigger a transistor with the PWM signal, but I have no clue how to "flatten" a PWM signal such that it will trigger the transistor. Will I need a filter of some kind? Or am I going about this the wrong way?

Any help is greatly appreciated! I am also very interested in learning more about working with analog signals, so if anyone has any recommended reading on the subject I would appreciate being pointed to it.
Hardware solution: Set a latch on the first pulse. Clear the latch under program control.
Software solution: Ignore following pulses after the first one.
 

HW-nut

Joined May 12, 2016
97
If the micro has an analog input and you only need moderate precision, then just use an RC filter on the PWM signal and read the analogy voltage.
 
Top