The AM Forum
October 10, 2024, 01:37:10 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Calendar Links Staff List Gallery Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: PWM on the Raspberry Pi  (Read 6554 times)
0 Members and 1 Guest are viewing this topic.
ka1tdq
Member

Offline Offline

Posts: 1506


Red part turned in for a refund.


« on: November 23, 2020, 12:40:59 PM »

I can muddle my way through the Raspberry Pi. Anyone know of a good cookie cutter program to do audio PWM on it?

Jon
Logged

It’s not just values, it’s business.
ka1tdq
Member

Offline Offline

Posts: 1506


Red part turned in for a refund.


« Reply #1 on: November 24, 2020, 09:51:45 AM »

I've searched the web and found nothing.

If someone on the forum is able and willing, I'll pay a reasonable fee for someone to write code to modulate an LED with a square wave up to 4 KHz, with a variable carrier frequency, according to an analog input. It would be plug-and-play as a PWM generator.

Jon
Logged

It’s not just values, it’s business.
w8khk
Member

Offline Offline

Posts: 1211


This ham got his ticket the old fashioned way.


WWW
« Reply #2 on: November 24, 2020, 10:22:49 AM »

The Raspberry Pi does not have any analog inputs, only digital.  An external ADC would be needed to process analog inputs.  So you would be looking at both hardware and software development.

A maximum frequency of 4 kHz for the PWM clock would not provide even an approximate rendering of a typical audio signal.  Or did you mean an input analog signal sampled up to 4 kHz?

You might consider using either an ESP-32 or better yet a fast Teensy 4.1, as they both have analog inputs and PWM outputs, and would probably be a better fit for your application.
See: https://www.pjrc.com/store/teensy41.html

But a much simpler approach would be to implement the analog to PWM conversion using a switching power supply IC, as is commonly done on many PWM generator designs for amateur radio use. 

Steve has provided a tried and true solution on the Class-E site.
Logged

Rick / W8KHK  ex WB2HKX, WB4GNR
"Both politicians and diapers need to be changed often and for the same reason.”   Ronald Reagan

My smart?phone voicetext screws up homophones, but they are crystal clear from my 75 meter plate-modulated AM transmitter
ka1tdq
Member

Offline Offline

Posts: 1506


Red part turned in for a refund.


« Reply #3 on: November 24, 2020, 10:59:42 AM »

I meant modulating the square wave up to 4 KHz, or the upper range of the human voice, not sampling rate of the analog signal.

The analog input board is cheap.

Surely someone should be able to do it. I'm not a code guy.

Yes, I can get Steve's board very easily or build it and I could analog modulate the rig. I'm just looking into maybe trying something new (for example every project I've ever done).

Jon
Logged

It’s not just values, it’s business.
steve_qix
Contributing
Member
*
Offline Offline

Posts: 2595


Bap!


WWW
« Reply #4 on: November 25, 2020, 01:21:04 PM »

Hi Jon,

A 4kHz switching rate is WAY WAY too low to resolve even low quality voice.

You must switch, at MINIMUM at twice the highest audio frequency you want to resolve (Nyquist theorem).

Furthermore, the PWM generator ____MUST____ have a sharp, low pass filter ahead of it, or you will get aliasing, caused by harmonics of the modulating frequency that will mix with the switching frequency and cause really bad artifacts in the audio range.

The other problem comes about when you are converting the PWM to an analog signal.  The output filter can only be so sharp.  Even a 6 pole filter should have its corner frequency well above anything we really care about audio-wise.  I typically set this to somewhere in the vicinity of 12.5kHz.  The anti-aliasing filter corner (at least for my designs) is 5.7kHz.

However, if you are only going to use this to modulate visual devices (such as an LED),  _and_ never demodulate this into audio, you could use a low sample rate because distortion and quality are not important in this case.  You could probably get away with a very modest anti aliasing filter as well.

Talking about switching frequencies, the Gates (Harris) MW5 PWM transmitter used a 70kHz sample rate to resolve a high end of 10kHz.  I built such a transmitter way back in the day (a tube PWM transmitter), and I have to say, that 70kHz was hard to filter to the point where it was down at least 70dB.  The rate was kept low because tube PWM transmitters have issues at high switching frequencies....  If you're ever interested, I could elaborate.

With modern solid state devices, switching frequencies of hundreds of KHz or even MHz are possible and practical.

The designs I publish use a 160kHz switching frequency.  This is a very good compromise between easy output filtering (high frequency switching is easy to filter out with modest L/C filter designs), and still resolving a 1% duty cycle pulse without too much pulse distortion (pulse modification, which gets worse at high switching frequencies).
Logged

High Power, Broadcast Audio and Low Cost?  Check out the class E web site at: http://www.classeradio.org
ka1tdq
Member

Offline Offline

Posts: 1506


Red part turned in for a refund.


« Reply #5 on: November 25, 2020, 05:48:39 PM »

Hey Steve,

Thanks for the detailed response. I mentioned modulating an LED because your design of the PWM output board uses an opto-isolator (like an LED but not quite). It was just a simple way to put the request.

I get what you're saying about the low pass input filtering and output filtering. And from looking at your PWM generator board schematic, the Raspberry Pi would only be replacing a small section of the whole board. It'd be engineering overkill for what needs to be done other than being able to tinker with sampling rates with just programming. For amateur use though, nobody would even notice. This probably isn't worth the hassle but the discussion is good.

The tube PWM's are neat. I can't think of a good horse and buggy / formula one race car analogy, but you get the idea. Quite the engineering feat.

My new E rig is coming slowly but getting there. Honestly, motivation comes in fits and starts. I'm about ready to test the scaled down VFO / phase splitter / duty cycle adjuster. That's really the hardest part and an area where you can make soldering mistakes. Once I get a good output from that, the rest is easy with just drilling and blasting (some soldering).

I'm hoping that the waveforms come out as clean as my last 8-FETter. They should since I'm being smarter about shielding and component coupling/placement.

Jon
Logged

It’s not just values, it’s business.
Pages: [1]   Go Up
  Print  
 
Jump to:  

AMfone - Dedicated to Amplitude Modulation on the Amateur Radio Bands
 AMfone © 2001-2015
Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.049 seconds with 18 queries.