square wave pulse on output pin 11

Greetings,

I want to generate a simple square wave pulse on pin 11 with my Atmel 32u4 mcu; after reading Atmel's documentation: http://www.atmel.com/images/doc7766.pdf; I brewed the following code:

static void pulseOn(uint16_t length) {

    // compare timer value, toggle output (50% duty cylce)
    TCCR1A= _BV(WGM12) | _BV(COM1C0);
    // no clock dividing
   TCCR1B= _BV(CS10);
   // depending on the oscillating frequency
    OCR1A= length;
}

The wgm3, wgm2, wgm1, wgm0 values are set to 0, 1, 0, 0, indicating a simple CTC scenario; the CS12, CS11, CS10 values are set to 0, 0, 1 indicating no clock scaling (i.e. 16MHz) and COM1C0 is set to 1 (the only save value I can think of, but I'm not sure about it ...) the OCR1A value is set to the pulse length value.

It doesn't work (obviously?) but I don't know what I did wrong; does anyone care to shed some light on this matter?

Thanks and

kind regards,

Jos

Do you mean a single pulse or do you mean a square wave (50% duty-cycle repeated pulse train)?

I mean a pulse train (on, off, on, off … etc. The ‘on’ periods are as long as the ‘off’ periods). What I understand from the documentation, timer1 should be able to do it in CTC mode; but I can’t get those flag values correct.

btw thanks for your reply.

kind regards,

Jos

Does the Tone library (or one of the several variants) do so by producing a 50% duty cycle square wave on the output pin? Will it run on the device you are programming? If not, could it provide a starting point for what you need?

Jeez, me and my stupidity: WGM12 should be set in register TCCR1B ...

kind regards,

Jos