help me, something wrong with my output (pwm arduino)

Thread Starter

haneys

Joined May 25, 2012
7
I need help.. i have the coding as shown below, but its not working as what i expected.. base on what i know, the coding below should provide me a 2MHz frecuency at output pin 9 and 1kHz at ouput pin 8.. but when i test it with oscilloscope i only obtain 2kHz at output pin 9.. what should i do to obtain 2MHz at output pin 9?? how can i change/modified the code?? many2 thankz..

code:
Rich (BB code):
#include <util/delay.h>
int rog = 8;
void setup() {
  pinMode(9, OUTPUT);
  pinMode(rog, OUTPUT);
  
  TCCR1A = 0;
  TCCR1B = 0;
  
  TCCR1A |= _BV(WGM11) | _BV(COM1A1);
  TCCR1B |= _BV(WGM12) | _BV(WGM13) | _BV(CS10) | _BV(ICNC1);

  ICR1= 7;

  OCR1A = 3;
}

void loop(){
delayrog(); 

}

void delayrog(){
   while (1)
	{
		
  digitalWrite(rog, HIGH);
  _delay_ms(0.52);
  digitalWrite(rog, LOW);
  _delay_ms(0.52);
  
	}
}
 

Thread Starter

haneys

Joined May 25, 2012
7
but, why i can get 2Mz at output pin 9 when i only use code below, but when i add up another output at pin 8 i wont get 2Mz at output pin 9.. i found this weird.. help me..

Rich (BB code):
void setup() {
  pinMode(9, OUTPUT);
  
  TCCR1A = 0;
  TCCR1B = 0;
  
  TCCR1A |= _BV(WGM11) | _BV(COM1A1);
  TCCR1B |= _BV(WGM12) | _BV(WGM13) | _BV(CS10) | _BV(ICNC1);

  ICR1= 7;

  OCR1A = 3;
}

void loop(){

}
 
Top