Question

Using AVR write a subroutine that can create a time delay that is a multiple of...

Using AVR write a subroutine that can create a time delay that is a multiple of 1ms. The multiple is passed in register r16, assume the CPU clock in 16MHz. (please include full working code) The processor used is the ATMEGA328P

0 0
Add a comment Improve this question Transcribed image text
Answer #1

While planning defer programs in (XXXX microcontroller), ascertaining the underlying worth that must be stacked inot TH and TL registers frames a critical thing. Give us a chance to perceive how it is finished.

Expect the processor is timed by a 16MHZ precious stone.

That implies, the clock info will be 16MHZ/16 = 1MHz

That implies, the time taken for the clock to make one augmentation = 1/1MHz = 1uS

For a period postponement of "X" uS the clock needs to make "X" increases.

2^16 = 65536 is the maximim number of checks feasible for a 16 bit clock.

Give TH a chance to be the esteem that must be stacked to TH registed and TL be the esteem that must be stacked to TL enlist.

At that point, THTL = Hexadecimal likeness (65536-X) where (65536-X) is considered in decimal.

Illustration.

Give the required defer a chance to be 1000uS (ie; 1mS).

That implies X = 10001

65536 – X = 65536 – 1000 = 64536.

64536 is considered in decimal and changing over it t0 hexadecimal gives FC18

That implies THTL = FC18

Along these lines TH=FC and TL=18

Program for producing 1mS defer utilizing XXXX microcontroller clock.

The program appeared beneath can be utilized for producing 1mS deferral and it is composed as a subroutine with the goal that you can call it anyplace in the program. Likewise you can place this in a circle for making longer time delays (products of 1mS). Here Timer 0 of XXXX microcontroller is utilized and it is working in MODE1 (16 bit clock).

Deferral: MOV TMOD,#00000001B/Sets Timer 0 to MODE1 (16 bit clock). Clock 1 isn't utilized

MOV TH0,#0FCH/Loads TH0 enroll with FCH

MOV TL0,#018H/LOads TL0 enroll with 18H

SETB TR0/Starts the Timer 0

HERE: JNB TF0,HERE/Loops here until the point when TF0 is set (ie;until move over)

CLR TR0/Stops Timer 0

CLR TF0/Clears TF0 hail

RET

The above defer routine can be circled twice so as to get a 2mS deferral and it is appeared in the program beneath.

Primary: MOV r16,#2D/number of ms you need delay

Circle: ACALL DELAY

DJNZ r16,LOOP

SJMP MAIN

Postponement: MOV TMOD,#00000001B

MOV TH0,#0FCH

MOV TL0,#018H

SETB TR0

HERE: JNB TF0,HERE

CLR TR0

CLR TF0

RET

Add a comment
Know the answer?
Add Answer to:
Using AVR write a subroutine that can create a time delay that is a multiple of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT