TEENSY 4.1 as CLASS D pwm driver

Hi, I'm new here, so I apologize in advance for a simple question for some of you. I would like to use the teensy audio library. USB soundcard will be defined as input than some filters and etc. As an output, I would like to use two pins that would directly drive the HB MOSFET driver (IR2110 for example). That is, PWM output with a carrier of 125 kHz with 10-bit resolution (I don't need HIFI quality) on one pin and the same on the other, only inverted. Even better with the possibility of inserting a small deathtime (100-200ns). I could ask for information on whether it is at all feasible and whether someone could guide me on how to deal with the setting of such an output. Or whether someone has already solved this problem.
Once again, many thanks for your patience and possible answer.
 
Teensy has a special PWM output called MQS. It's a standard feature of the audio library which you can find in the design tool. PWM carrier is approx 352 kHz.

It doesn't have complementary outputs with dead time.
 
Thanks Paul for quick response !
So MQS is coded the same as classic PWM with 16-bit depth?

I could replace the missing complementary output with a driver with one input and programmable DT directly in the driver. For example LM5106. Do you think it will work this way?

thanks again in advance for your reply
 
As an output, I would like to use two pins that would directly drive the HB MOSFET driver (IR2110 for example). That is, PWM output with a carrier of 125 kHz with 10-bit resolution (I don't need HIFI quality) on one pin and the same on the other, only inverted. Even better with the possibility of inserting a small deathtime (100-200ns).

The links below are for a forum thread and github repository for eFlexPwm library by user @epsilonrt. With this library you can produce center-aligned, complementary PWM, with programmable deadtime. I have used it at 10 kHz, but I think you could also use 125 kHz and get 10+ bits of resolution. There is a single-phase example program in the library that you could use as a starting point for test. I don't know how you would "combine" the Audio library on the input side and also use this eFlexPwm library for the outputs, but perhaps it is possible.

https://forum.pjrc.com/threads/72458-New-Arduino-eFlexPWM-Library?highlight=eflexpwm

https://github.com/epsilonrt/eFlexPwm
 
Thanks Joe for your response.
I looked at the mentioned library. However, I really have a problem with which interface to link the output from the audio library to the input of the dutycycle flexPWM control. I suppose it could be done via reading the output audio buffer. Or via DMA. However, I'm not yet that experienced in programming at this level of registry manipulation etc...
 
Thanks Joe for your response.
I looked at the mentioned library. However, I really have a problem with which interface to link the output from the audio library to the input of the dutycycle flexPWM control. I suppose it could be done via reading the output audio buffer. Or via DMA. However, I'm not yet that experienced in programming at this level of registry manipulation etc...

Okay. Sorry I can't help more. I don't know anything about the Audio library.
 
If you're not yet familiar with the audio library, this 31 page tutorial is the place to start.

https://www.pjrc.com/store/audio_tutorial_kit.html

You might skip forward to page 8 to learn how to use the design tool. Even though the tutorial uses only I2S, hopefully you can see how you could drag any of those other outputs onto the canvas and connect the signals. Many of them are able to work concurrently. For example, you could have a signal which goes to PWM, MQS and I2S all at the same time. If you drag any 2 or more hardware input / output features onto the canvas which can't work simultaneously, you'll see little yellow error icons appear.


I suppose it could be done via reading the output audio buffer. Or via DMA. However, I'm not yet that experienced in programming at this level of registry manipulation etc...

The library does all that low-level stuff for you. Unless you want to do something very special, you can probably just use the design tool and just use the PWM and/or MQS signals. Refer to the right-panel documentation in the design tool for each of those outputs to learn which pins they use.
 
Paul, thanks again for your reply and the links you sent. Basically, I don't have a problem with not knowing the audio library. The only problem that I need to solve in my project is actually mapping the output to a PWM signal, which I could use to control the mosfet driver for HB Class D amplifiers. The PWM eFlex library knows what I need, but I don't know how to map the software output from the audio library to the pwm duty cycle control input of the pwm eflex library.
I'm sorry, English is not my native language, so maybe I'm expressing myself wrong.

Basically, to begin with, I would need to find out how to get a transformation from the audio library into the Sm20.updateDutyCycle command from eflexpwm, which will represent its output.

maybe I'm imagining it too simply and I'm totally wrong.
 
I still encountered another problem that the program cannot be compiled if I use the object USB audio input or output AudioInputUSB usb1; . When I look in the declaration of the audio.h library, this input/output is not listed there at all. At the same time, I have the latest teensy 4.1 board support installed in IDE2.0.

teensy_n.jpg
 
In either version of Arduino IDE, to use AudioInputUSB you need to set the Tools > USB Type menu to Audio.


Basically, to begin with, I would need to find out how to get a transformation from the audio library into the Sm20.updateDutyCycle command from eflexpwm, which will represent its output.

The low-level code for PWM (and MQS) is already inside the audio library. So all you need to do is draw a wire in the design tool, like this:

screenshot.png
 
thanks, I'm slowly getting the hang of it :) Would anyone have an idea how to simulate an MQS output, for example, with a fixed sine modulation of 10Khz in the LTSpice program?

LTSPICE.jpg

is this correct way ?
 
Last edited:
I made some progress. Test for now. It doesn't look as bad as I thought.
Power stage HB class D drived directly by MQS output. Looks that MQS is some delta-sigma variant pwm modulation.
DS1Z_QuickPrint27.png
 
Back
Top