Arduino leonardo timer 4, 3 pwm pulses

Is it possible to create with timer 4 with OC4A, OC4B and OC4D to create on 3 pins a pwm signal that on each pin creates one pulse of 15 micro sec 100 micro sec apart without fiddling with parameters after the pwm is started And that repeated every millisecond if the pwm has to be started every millisecond , thats fine.

Peux-tu nous donné plus de detail. Es-ce-que le signal se répette toujours avec le m^me ecart?
Si je ne me trompe pas tu peux avoir deux type 8bit de pwm voir figure 13-1 et 3 16bit dans la figure 14.1 dans la doc. du 32u4. par contre je crois qu'il sont synchronisé a partir de la m^me horloge interne et non décalé.

int led = 13;
int led2 = 12;
int led3 = 11;

void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
void loop() {
    digitalWrite(led, HIGH);   
    digitalWrite(led, LOW);    
    digitalWrite(led2, HIGH);
    digitalWrite(led2, LOW);
    digitalWrite(led3, HIGH);
    digitalWrite(led3, LOW);

Yes the signal will be the same. the purpose is to drive a ir-led with a high current for a short time and to start simultanously with the pulse an ad conversion from a fotodiode this takes 2,5 micro sec I believe the whole conversion takes about 100 micro sec here after the next pulse and conversion must be started.
the total ad conversion time can be shortened to 25 micro sec by using a faster clock for the ad converter this comes with a slightly lower resolution but that is acceptable so jin the final version the time between conversions will be lower

I do not want to use bitbanging, I think with complementary pwm I can create a short pulse . which also can start automagically an ad conversion when OC4X matches the counter. By using the ad ready ISR I can start the next pulse and ad conversion, Well do I need to stop the pwm after the first pulse but that can with a counter is zero ISR. I was looking into dead time but It isn't clear to me how big a delay you can create with that.

ok look that example;

Phase-Correct PWM example

The following code fragment sets up phase-correct PWM on pins 3 and 11 (Timer 2). The waveform generation mode bits WGM are set to to 001 for phase-correct PWM. The other bits are the same as for fast PWM.

pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS22);
OCR2A = 180;
OCR2B = 50;

[Get Code]

On the Arduino Duemilanove, these values yield:

  • Output A frequency: 16 MHz / 64 / 255 / 2 = 490.196Hz
  • Output A duty cycle: 180 / 255 = 70.6%
  • Output B frequency: 16 MHz / 64 / 255 / 2 = 490.196Hz
  • Output B duty cycle: 50 / 255 = 19.6%

Phase-correct PWM divides the frequency by two compared to fast PWM, because the timer goes both up and down. Somewhat surprisingly, the frequency is divided by 255 instead of 256, and the duty cycle calculations do not add one as for fast PWM. See the explanation below under "Off-by-one".

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.