# Processor speed for generating PWM at 1 MHz

I want to generate square pulses at around 1 MHz to drive an H-bridge inverter. Now, I want to choose a suitable microcontroller, microprocessor, or a DSP board. I need to generate a few pulses (minimum 4) with the possibility of controlling the duty and the phase. The resolution I am aiming for is around 5 ns. I also want to execute some control logic. What would be the minimum speed of the processor for this purpose?

For example, I have TI MCU F28379D LaunchPad in mind which include 200 MHz TMS320F28379D. If I can use the full 200 MHz speed, I should be able to get $$\5~\rm{ns}\$$ resolution. But what will be the practical resolution in a real implementation?

• This sounds like something you could offload to a timer? I would have thought most of the reasonably quick micro controllers would suffice – Colin Feb 11 at 13:45
• Are you interested in a recommendation on how to select a platform or rather a specific platform recommendation? Your question asks for a speed requirement, but your comment to an answer mentions specific platform. – Jurkstas Feb 11 at 14:48
• @Jurkstas, I edited the question to fit with the rules and deleted the comment now. in fact, if I can get recommendations on "how to select a platform", I should be able to select a specific platform. – Pojj Feb 11 at 14:55
• @Colin, Thanks, I will try your suggestion. – Pojj Feb 11 at 16:09
• You'll have to read the datasheets and compare timer peripherals and the maximum clock frequency for that peripheral. Some processors (TI is one supplier) use some interesting tricks to get as good as 150ps PWM resolution without insane clock frequencies. – Spehro Pefhany Feb 11 at 16:24

You could use something as simple as an Arduino Nano (main processor is an ATMega328) and run the following code (from official arduino site):

int outPin = 8;                 // digital pin 8

void setup()
{
pinMode(outPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
digitalWrite(outPin, HIGH);   // sets the pin on
delayMicroseconds(5);        // pauses for 5 microseconds
digitalWrite(outPin, LOW);    // sets the pin off
delayMicroseconds(5);        // pauses for 5 microseconds
}

The code as I've shown it here should get you to 200KHz

However, I believe that function can only go down to 3us so in reality you may not be able to quite make it to 1MHz.

• Arduino default digitalWrite() is slow. – Long Pham Feb 11 at 14:46
• @LongPham It may be but I successfully created a simple square wave generator using this method and I tested it using a very simple hobbyist oscilloscope (amzn.to/2BukFWE) and it worked well enough for my purposes. It was just an idea. – raddevus Feb 11 at 15:04