AVR MCU Mega16 timer experiment report

Publisher:科技徜徉Latest update time:2019-10-30 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental purpose

Through experiments, master the use of timers, especially the use of timer interrupts!


2. Experimental content

    1 Use the timer0 of the Mega16 microcontroller to generate a 1ms interval timer interrupt (it is recommended to use the application builder, which can use both the Normal working mode and the CTC mode). (1) Implement dynamic refresh of the 4-bit digital tube in the timer interrupt. (2) Design a 100mS time flag in the 1ms timer interrupt, query the time flag in the main program, and realize LED flashing.

    2 Reconfigure TImer0 to work in PWM mode, use the buttons to change the PWM duty cycle and adjust the motor speed;


3. Experimental preparation requirements

Carefully read the examples of timed interrupts in the textbook;


4. Experimental steps

    1 Start ICCAVR, create a project file, configure timer0, implement a 10ms timer interrupt, and use Application Builder to generate initialization code. Note: The IO ports used in this experiment must also be initialized, including the IO used by the digital tube driver, buttons, etc.

    2. Implement the timed refresh of the four-digit digital tube in the timed interrupt (Note: use the driver of HC595 from the last lab class), and implement the 100ms time mark (time stamp) in the timed interrupt, query the time stamp in the main program, and realize the flashing of the LED (any LED of PORTC port can be used);

    3 Reconfigure TImer0 to work in PWM mode, set the initial duty cycle to 10%, and then use the button INT1 (SW8 in the schematic diagram, connected to the PD3 pin of the microcontroller) to change the duty cycle. For example, each time the button is pressed, the duty cycle increases by 10%.


Note: The pins used in the experiment are: PD4, PD5, PD6, PD7, PB0, PB1, PA0, PD3. Please refer to the schematic diagram for the connection of each pin.


Experiment 3: Timer application experiment

Content of report


1. Purpose

   Through experiments, master the use of timers, especially the use of timer interrupts!

2 Experimental content

    1. Use the timer0 of the Mega16 microcontroller to generate a 1ms interval timer interrupt (it is recommended to use the application builder, which can use both the Normal working mode and the CTC mode). (1) Implement dynamic refresh of the 4-digit digital tube in the timer interrupt. (2) Design a 100mS time flag in the 1ms timer interrupt, query the time flag in the main program, and realize LED flashing.

2. Reconfigure TImer0 to work in PWM mode, use the buttons to change the PWM duty cycle and adjust the motor speed;

3 Use the timer0 of the Mega16 microcontroller to generate a timer interrupt with an interval of 1ms (it is recommended to use the application builder, which can use both Normal working mode and CTC mode). Write the working mode used and the values ​​of each timer register.


#include

#include


void port_init(void)

{

PORTA = 0x00;

DDRA = 0x00;

PORTB = 0x00;

DDRB = 0x00;

PORTC = 0x00; //m103 output only

DDRC = 0x00;

PORTD = 0x00;

DDRD = 0x00;

}


//TIMER0 initialize - prescale:8

// WGM: CTC

// desired value: 1000Hz

// actual value: 992.063Hz (-0.8%)

void timer0_init(void)

{

TCCR0 = 0x00; //stop

TCNT0 = 0x83; //set count

OCR0 = 0x7D; //set compare match

TCCR0 = 0x0A; //start timer

}


//call this routine to initialize all peripherals

void init_devices(void)

{

//stop errant interrupts until set up

CLI(); //disable all interrupts

port_init();

timer0_init();


MCUCR = 0x00;

GICR = 0x00;

TIMSK = 0x00; //timer interrupt sources

SEI(); //re-enable interrupts

//all peripherals are now initialized

}


4. Implement dynamic refresh of 4-digit digital tube in timer interrupt. (Only write out the code related to timer interrupt, this part will borrow the driver function of HC595 implemented in the last lab class)


5. Design a 1000mS time flag in the 1ms timer interrupt, query the time flag in the main program, and use the stopwatch function. (Only write the timer interrupt service program and the function code to implement the stopwatch)



Reference address:AVR MCU Mega16 timer experiment report

Previous article:Getting started with the first 74HC595 driver in C language
Next article:NEC infrared remote control signal decoding program based on attiny13

Recommended ReadingLatest update time:2024-11-16 13:28

MSP430G2553 (II) Timer Description and Examples
MSP430 has designed a TIMER timer. When the timer reaches the set value (depending on the mode), it will jump into an interrupt. As a common function, MSP430 provides three counting modes. G2553 has two 16-bit timers, Timer0 and Timer1. This article uses a timed io port operation to demonstrate how to set the timer
[Microcontroller]
Question about MSP430 Timer_A
I am using CCR1 continuous counting mode   This CCR1 needs to be assigned a value every time during the timer.   I found a strange phenomenon today. I blocked the CCR1 += 10000 in the timer interrupt, and the LED light was also on and off evenly . After you block the statement, the program runs
[Microcontroller]
Question about MSP430 Timer_A
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号