I’m learning “TIMER” recently, and trying to verify the signal by Oscilloscope to see if the code are right. Unfortunately, they are NOT the same. Can anyone kindly let me know where the problem is in the code, or have something coding wrong else?
By the way, I knew there are more examples on this purpose with “PWM setting” and “enable overflow interrupt setting”, but I just want to know what is the difference.
const int pin = 3;
void setup() {
pinMode(pin,OUTPUT);
TCCR1A = 0x00; // Normal mode, just as a Timer
TCCR1B = 0x01; // no prescaler
TCNT1 = 0;
}
void loop() {
digitalWrite(pin,HIGH);
delays();
digitalWrite(pin,LOW);
delays();
}
void delays(){
while(TCNT1<=15){ // Would like to have 1Mhz,
}
TCNT1=0;
}
What frequency does that give you?
So, what does that tell you?
Thanks for the point, I capture the digitalWrite waveform by scope, the speed is bigger than 1 (us). The speed around is 8 us as attachment. So, that’s why the 10 us was observed in my codes.