Help Creating a Two Channel Complimentary Waveform Generator

Status
Not open for further replies.

DBennett63

New member
Hi, I need help designing a two channel complementary generator. This is basically two PWM channels that have opposite timing (when one channel is high the other one is low) plus there needs to be a little dead band time (at least 1 usec) between them. Such a circuit is typically used to drive MOSFET or IGBT half bridges. The dead band is needed to prevent conduction through both switches at the same time which would be a short. So obviously the two channels have to stay phased together as well. I built the circuit at the following link and it works fine, but the frequency and duty cycle have to be adjusted using potentiometers and I'd like them to be software adjustable:

http://www.edn.com/design/analog/4314069/Build-a-simple-complementary-bracket-pulse-generator

I'd like to adjust the frequency from about 1kHz to 30kHz. I'd like to adjust the duty cycle from 10% to 90%. A fixed dead band of 2usec would be fine. I came to this forum because I read some Ardunio forum comments from Paul about writing a function called analogwritefrequency() for the teensy board which seemed very close to what I was looking for. The update speed of changing the frequency etc is not important and doesn't happen often. As such an Arduino Uno board could talk serially to a teensy and it could output the desired dual channel pulse train.

This circuit needs to be developed in the next week or two and will be going on an industrial piece of equipment costing around $500K. So the hardware costs for these hobby boards is not a concern at all.
However, the solution does need to be reliable. We have written a lot of Arduino uno code which accepts serial commands from a PC and sets relays and power supply voltages among other tasks. We don't want to start over on this code so a device that programs in a manner similar to Arduino is very interesting. We have purchased a Due and a Mega board as well. We were considering trying to get the Due to output the dual channel signal but are having difficulty knowing how to do this.

I'd be glad to pay $2k for someone to help me figure this out. I don't know if looking to hire someone through a forum is appropriate. If not, I apologize, but I am getting a little desperate.
 
I've written some code than does what you want, it does eat up an interrupt though?

I had a bit of free time, so I have written a complete "Complimentary PWM" class. It accepts the Frequency in Hz and the duty cycle in percentage (real values so 23.34%, for example, is valid). I also have some us methods in case you want to set the duty and period in microseconds. Both Frequency and Duty can be adjusted in real time, and will always remain in phase. The dead time, microseconds, can also be adjusted in real time.

-edit- this code will only work on Teensy 3.0 or Teensy 3.1
 
Last edited:
I've written some code than does what you want, it does eat up an interrupt though?

I had a bit of free time, so I have written a complete "Complimentary PWM" class. It accepts the Frequency in Hz and the duty cycle in percentage (real values so 23.34%, for example, is valid). I also have some us methods in case you want to set the duty and period in microseconds. Both Frequency and Duty can be adjusted in real time, and will always remain in phase. The dead time, microseconds, can also be adjusted in real time.

-edit- this code will only work on Teensy 3.0 or Teensy 3.1

Wow! that was fast and sounds great.

Can the frequency go as high as 30KHz? Any suggestion on talking to the Teensy 3.1 from my Arduino Uno? Or can I port the code from the Arduino to the Teensy 3.1? I looked at the specs of the Teensy 3.1 and it has plenty of I/O. I wrote the original code so I can move the I/O assignments around as needed to give you the PWM channels you want. I'd also like to do some tweaks to the code so that I can shut off the pulses when needed of reduce frequency. I guess I can get the source from you. Can you help with porting code if I do get stuck? How can I get the code and get you paid?? I have not done business like this before. I can have money wired to the UK. Is there somehow you can show me that it works? Screen capture from a O-scope for example?
 
Wow! that was fast and sounds great.

Can the frequency go as high as 30KHz?

Should do, I originally wrote the code to run at 15Hz for another project... I've not tested it any faster...

Any suggestion on talking to the Teensy 3.1 from my Arduino Uno? Or can I port the code from the Arduino to the Teensy 3.1? I looked at the specs of the Teensy 3.1 and it has plenty of I/O.

I would recommend using the Teensy 3.1 as your base platform, it has far more I/O, Flash, RAM, and CPU power... it's smaller too.

-Edit- Paul has does a great job on making the Teensy 3.1 VERY Arduino compatible... I would expect your code to work pretty much out of the box (with a few pin reassignments).

I wrote the original code so I can move the I/O assignments around as needed to give you the PWM channels you want. I'd also like to do some tweaks to the code so that I can shut off the pulses when needed of reduce frequency. I guess I can get the source from you. Can you help with porting code if I do get stuck? How can I get the code and get you paid??

My Complimentary PWM code allows you to assign any two pins you like to be the complimentary pair. I have added a pause method, which might help if you need to pause the PWM output.

I'm always on these forums if you need help.

I have not done business like this before. I can have money wired to the UK. Is there somehow you can show me that it works? Screen capture from a O-scope for example?

Probably best if I email you the code first, if it works for you (I can obviously help if you get stuck) then we can talk about payment :)
 
Last edited:
Great. That sounds wonderful!! I'm ordering my Teensy 3.1 right now!! When I signed up I checked the box that allows others to send me emails. If you need it some other way then let me know through this forum.
 
Hi -- I have no problem with bloodline's code, but if you are controlling hardware and need guaranteed and robust performance (for a $500k machine ?), I would suggest you also go for a hardware solution.

1) Consider if it is acceptable for a software fault (or MCU upset) to cause the outputs to be stuck in one state for a significant time, or if your deadtime overlap extends too far. Consider what could happen while debugging the code also, or what happens to your hardware before the MCU boots
2) The Teensy usually processes interrupts quickly, but occasionally when USB or millis() activities (or any other high priority interrupts) are happening, it takes some 100's of ns longer.

For 2 -- you can just use a simple R & C circuit to delay a PWM signal by a few us (e.g. 10k Ω & 100 pF). Use CD4001-type logic gates to combine the original and delayed signals to generate your software-failure-proof deadtime. A CD4001 contains 4 NOR gates -- one directly generates one signal; combine the others (using de Morgan's rules) to make an AND gate for the other signal

For 1 -- you might consider a 555-type oscillator with the frequency adjusted via an analog-type output from Teensy. That way, you will always have a PWM signal as soon as power is applied.
 
I would agree that the hardware approach is more deterministic, but understanding David's specification a bit more, I can see why he would prefer a software approach for at least this phase of the project. The overall problem is more complex than the example given in the original post.
 
If reliability is a serious concern, how about redundant devices? The key is to make a design that minimizes common cause failures and shuts down safely in case of a failure.

A controller combining a T3.1, a T2, and an FPGA board (e.g. Papilio One, Mojo, or Xilinx Spartan-6 FPGA LX9 MicroBoard) could be extremely reliable system and not very expensive. The FPGA boards I mentioned range from $38 to $89.
 
Reliability is a very complex topic. Actually an FPGA would be quite a lot less reliable than a CD4001 quad NOR gate -- simplicity is best for reliability. In my circuit suggestion, probably the resistor and capacitor are the least reliable components (if he buys the CD4001 from a reputable manufacturer). Putting two R's and two C's in parallel makes the circuit quite insensitive to a single failure in one component.

Generally in these systems you actually need a third state -- where all devices are off (during startup of the power supplies and software, and while you test that there are no shorts etc.). Unless he can withstand a 100 % on configuration, he will need additional controls to prevent runaway.




If reliability is a serious concern, how about redundant devices? The key is to make a design that minimizes common cause failures and shuts down safely in case of a failure.

A controller combining a T3.1, a T2, and an FPGA board (e.g. Papilio One, Mojo, or Xilinx Spartan-6 FPGA LX9 MicroBoard) could be extremely reliable system and not very expensive. The FPGA boards I mentioned range from $38 to $89.
 
I had a bit of free time, so I have written a complete "Complimentary PWM" class. It accepts the Frequency in Hz and the duty cycle in percentage (real values so 23.34%, for example, is valid). I also have some us methods in case you want to set the duty and period in microseconds. Both Frequency and Duty can be adjusted in real time, and will always remain in phase. The dead time, microseconds, can also be adjusted in real time.

I am interested in using this code. Do you make it available and could you post a link?

Thanks,
Josh
 
Actually, if the machine goes into runaway because of a lack or malformed PWM on startup then it has bigger issues. That is what estops, limit switches, possibly accelerometers acting as limit switches, etc are for. In case the electronics get stupid. All electronics can get stupid if the environment is bad. Such as moisture in a food plant getting into VFDs.
 
Status
Not open for further replies.
Back
Top