How to make a pulse width of 1us at 100Hz

hello.
I am trying to make a 100Hz frequency with a pulse width of 1us using an Arduino Uno (Atmega328p / 16MHz).

void setup() {

pinMode(9,OUTPUT);
noInterrupts();
  TCNT1=0x0000;

  // WGM : 14(1110b), none-inverted mode
  TCCR1A = bit(COM1A1)|bit(COM1B1);
  TCCR1A |=bit(WGM11);
  TCCR1B = bit(WGM13)|bit(WGM12); 

 //prescailing : clock/8
  TCCR1B|=bit(CS11);

 //TOP
  ICR1 = 20000-1;

//duty cycle
  OCR1A= 1;
interrupts();  
 }

After coding like this, when I measured it with an oscilloscope, it was an intermittent output, not a periodic signal. This is not a continuous 100Hz output.
I measured it by increasing the duty cycle and it worked fine.

I'm not sure which one is the problem. Please help me.

Use CTC mode (12) for pulse generation.

it was an intermittent output, not a periodic signal.

The code you posted works fine for me, and produces a 100 Hz PWM signal with 1 us ON time. Sounds like you have intermittent connections to the scope.

Or, you have your scope triggering options set incorrectly...

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