Chip name: AVR (Atmel) mega16A microcontroller chip;
Development board: self-developed YF-A1 chip development board; (YF: is the abbreviation of my name)
In the 53rd test, I used a logic analyzer to capture the digital pulse signal output from the IO port. The pulse signal width was 1.5~1.8 microseconds. In the signal timing of every 9~11 pulses with a width of 1.5us, there was a high pulse signal with a pulse width of 3 microseconds.
I spent several hours and couldn't calculate the internal clock frequency of timer 0... What went wrong?
An external 12-mega crystal oscillator was used;
my calculation conclusion was: the internal frequency of timer 0 was 32khz, but this was obviously problematic.
The timer clock was internally divided by 8 TCCR0=0X02; the initial value of TCNTO was 250, that is, it overflowed once every 6 clock cycles, and every time it overflowed, the PB port level was inverted once, so the reverse calculation pulse width 1.5us ÷ 6 == each divided clock time ÷ 8 = clock frequency;
/*
It took me more than 3 hours to write this program, and I experimented repeatedly. God will not let down those who work hard,, hey╮(╯▽╰)╭,,,,,
Program name: Timer 0 overflow interrupt
Overview: The timer overflows once every millisecond. If the timer overflows 500 times, that is, 0.5 seconds, the LED light will jump once. I found that if
all IO ports are not initialized, the chip will become extremely unstable and cannot work properly. Once the timer 0 overflow flag
TOV0 overflows, it will be automatically cleared after entering the interrupt service program, and there is no need for software clearing. I seem to understand the meaning of
hardware clearing;
Finish time: February 28, 2014 20:40:21;
*/
#include
#include
#include
typedef unsigned char uint8;
typedef unsigned int uint16;
volatile uint16 a=0;
void io(void)
{
DDRA=0XFF;
PORTA=0X00;
DDRB=0XFF;
PORTB=0X00;
DDRC=0XFF;
PORTC=0X00;
DDRD=0XFF;
PORTD=0X00;
}
int main(void)
{
io();
TIMSK=0X01; // Overflow interrupt enable;
sei(); //Global interrupt enable;
TCNT0=69; //Timer initial value 1 millisecond overflow;
TCCR0=3; //64-division timer starts running!;
PORTB=4; //8-bit LED common anode enable;
while(1); //infinite loop;
}
SIGNAL(SIG_OVERFLOW0) //Interrupt service routine;
{
static uint16 s=0; //Static variable;
TCNT0=69; //Reset the initial value of the timer;
s++;
if(s==502) //The PA port level changes once every 500 milliseconds!
{ s=0;
PORTA^=0XFF;
}
// TIFR=0X01;//Clear the overflow flag and compare match flag of timer 0;
}
Previous article:High-speed AVR realizes vibration/temperature signal acquisition and storage
Next article:AVR microcontroller 8-bit timer LED accurate 1 second flashing program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Optimizing EMC and Efficiency in High Power DC/DC Converters Part 2
- [McQueen Trial] + Line-following Driving + Ultrasonic Obstacle Avoidance
- Can the freewheeling diode be omitted when the MOS tube controls the solenoid valve?
- HP Prime G2 calculator with MicroPython support
- STM32 output 4-20MA or 0-10V circuit sharing
- LIS2MDL array PCB engineering and code information for magnetic nail navigation AGV car
- Live Review: Rochester Electronics Semiconductor Full-Cycle Solutions (including videos, materials, Q&A)
- How to understand this parameter in the MOS tube specification?
- Italian court upholds enforceability of open source software license
- New support for C++ code in STM32 and examples of user C modules written in C++ in MicroPython