Skip to main content
Arduino

Return to Question

fixed units, added non-breaking space before units
Source Link
Greenonline
  • 3.2k
  • 7
  • 36
  • 48

Generating 200khz200 kHz pulse on Arduino Uno in normal mode

I need to obtain 200KHz200 kHz from Arduino Uno. I am using Timer0Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16Mhz16 MHz). TCNT0TCNT0 is set to 0xFB0xFB and the code toggles 2 pins of PORTBPORTB as timer overflow flag is set. Here's My

Here is my code (I am using Atmel Studio 7):

#include <avr/io.h>
int main(void)
{
 DDRB = 0x03;
 PORTB |= 0x02;
 while (1) 
 {
 TCNT0 = 0xFB;
 TCCR0A = 0X00;
 TCCR0B = 0x02;
 while ( (TIFR0 & 0x01) == 0 );
 PORTB ^= 0x03;
 TCCR1A = 0x00;
 TCCR1B = 0x00;
 TIFR0 = 0X01;
 }
}

When I check on the oscilloscope, it shows that the pulse is 166Khz166 kHz instead of 200Khz200 kHz. Although I can use Fast PWM Mode and use interrupts, I am just curious to know why it doesn't work? Did I make any mistake?

Generating 200khz pulse on Arduino Uno in normal mode

I need to obtain 200KHz from Arduino Uno. I am using Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16Mhz). TCNT0 is set to 0xFB and the code toggles 2 pins of PORTB as timer overflow flag is set. Here's My code (I am using Atmel Studio 7):

#include <avr/io.h>
int main(void)
{
 DDRB = 0x03;
 PORTB |= 0x02;
 while (1) 
 {
 TCNT0 = 0xFB;
 TCCR0A = 0X00;
 TCCR0B = 0x02;
 while ( (TIFR0 & 0x01) == 0 );
 PORTB ^= 0x03;
 TCCR1A = 0x00;
 TCCR1B = 0x00;
 TIFR0 = 0X01;
 }
}

When I check on the oscilloscope, it shows that the pulse is 166Khz instead of 200Khz. Although I can use Fast PWM Mode and use interrupts, I am just curious to know why it doesn't work? Did I make any mistake?

Generating 200 kHz pulse on Arduino Uno in normal mode

I need to obtain 200 kHz from Arduino Uno. I am using Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16 MHz). TCNT0 is set to 0xFB and the code toggles 2 pins of PORTB as timer overflow flag is set.

Here is my code (I am using Atmel Studio 7):

#include <avr/io.h>
int main(void)
{
 DDRB = 0x03;
 PORTB |= 0x02;
 while (1) 
 {
 TCNT0 = 0xFB;
 TCCR0A = 0X00;
 TCCR0B = 0x02;
 while ( (TIFR0 & 0x01) == 0 );
 PORTB ^= 0x03;
 TCCR1A = 0x00;
 TCCR1B = 0x00;
 TIFR0 = 0X01;
 }
}

When I check on the oscilloscope, it shows that the pulse is 166 kHz instead of 200 kHz. Although I can use Fast PWM Mode and use interrupts, I am just curious to know why it doesn't work? Did I make any mistake?

Source Link

Generating 200khz pulse on Arduino Uno in normal mode

I need to obtain 200KHz from Arduino Uno. I am using Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16Mhz). TCNT0 is set to 0xFB and the code toggles 2 pins of PORTB as timer overflow flag is set. Here's My code (I am using Atmel Studio 7):

#include <avr/io.h>
int main(void)
{
 DDRB = 0x03;
 PORTB |= 0x02;
 while (1) 
 {
 TCNT0 = 0xFB;
 TCCR0A = 0X00;
 TCCR0B = 0x02;
 while ( (TIFR0 & 0x01) == 0 );
 PORTB ^= 0x03;
 TCCR1A = 0x00;
 TCCR1B = 0x00;
 TIFR0 = 0X01;
 }
}

When I check on the oscilloscope, it shows that the pulse is 166Khz instead of 200Khz. Although I can use Fast PWM Mode and use interrupts, I am just curious to know why it doesn't work? Did I make any mistake?

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /