Path: Home =>
AVR-EN =>
Applications =>
Sine generators => Fixed sine tn24
Diese Seite in Deutsch:
 |
Tutorial for learning avr assembler language of
AVR-single-chip-processors AT90S, ATtiny, ATmega, ATxmega
of ATMEL using practical examples.
Fixed frequency sine generator tn24 |
Fixed frequency sine wave generator with ATtiny24
If you need a fixed frequency sine wave generator you can go with that. It
has the following properties:
- 8-bit R/2R network,
- selectible and configurable crystal,
- either 256, 128, 64, 32, 16 or 8 resolution steps,
- large 16-bit delay counter, usable for very low frequencies,
- very fast algorithm (minimum cycle length = 16 cycles),
- very small 14-pin package.
Hardware
This is all that it needs.
The generator has
- the usual R/2R network with 8 bit resolution,
- a crystal for exact timing,
- a driver that protects the network and provides enough output power,
- an LC low-pass filter that rips off remaining rectangles,
- a standard six-pin ISP interface to program the controller.
PCB layout
This is the tiny PCB of the sine generator (40-by-50 mm). Click on
the small pictures to get the original size (download the original with
right-clicking and Save as ...). The holes in red in the component
plan are 0.8 mm, in violett 1.0 mm.
If you have Linux you can work with the originals with tgif: Copper side
and components with color layers = here,
component plan = here.
Configuration
All you need to decide is:
- the frequency that is to be generated,
- the crystal to be used,
- the resolution of the sine wave generated, if the frequency
is above 3.9 kHz,
- if the standard amplitude of 1Veff is sufficient,
- whether the two-stage LC filter is sufficient.
For configuration you can use the LibreOffice calc document
here. It holds the following
single calculation sheets:
- Ranges: This shows the ranges of the generator with the
available six different resolutions (from 0.02 Hz to 125 kHz),
if you select a crystal, the ranges are shown, if you select a
frequency the nearest generatible frequency is shown,
- FixedSine: This helps to select the crystal. All available
crystals on the market can be tested for suitability and the error
margin of the generated frequency.
- Crystals: This sheets serves as a selector for the
crystals.
The next chapter shows how to implement your favourite settings.
Software
The assembler software can be downloaded from
here. It holds the following
header lines:
; **********************************
; A D J U S T A B L E C O N S T
; **********************************
;
; The clock frequency of the crystal
.equ clock = 16000000 ; Clock in Hz
;
; The following combinations are possible:
; Frequency only (Assembler decides on resolution and delay)
; Frequency and Resolution (Assembler calculates delay)
; Frequency and Delay (Assembler calculates Resolution
; Resolution and Delay (Assembler calculates Frequency)
; Unselect all undefined parameter by preceding semicolon
;
; If you want to fix the frequency,
; define it here
;.equ cFreq=1000000 ; Frequency in mHz
;
; If you want to fix the resolution,
; define the resolution here
.equ cResol=32 ; resolution 256/128/64/32/16/8
;
; If you want to fix the delay,
; define it here
.equ cDelay=122 ; between 1 and 65536
;
In that case, the frequency is not selected but only the
resolution and the delay constant. The assembler then decides
to uses these two given parameters.
If you define the frequency (remove the ; in the respective
line) and either the resolution or the delay, it calculates
the other parameter. If you neither define the resolution
nor the delay, the assembler decides on its own: by using
the highest possible resolution and the smallest delay
constant.
If you assemble the software with either gavrasm of avr_sim,
you'll get the following symbol table at the end of the listing:
List of symbols:
Type nDef nUsed Decimalval Hexval Name
T 1 1 25 19 ATTINY24A
L 1 0 0 00 MAIN
L 1 2 2 02 SINELOOP
L 1 2 4 04 SINELOOP1
L 1 2 8 08 SINELOOP2
L 1 2 16 10 SINETABLE
L 1 1 144 90 SINETABLEEND
R 1 4 16 10 RMP
R 1 2 24 18 RCNTL
R 1 1 25 19 RCNTH
C 1 1 27 1B PR2RO
C 1 1 26 1A PR2RD
C 1 1 16000000 F42400 CLOCK
C 1 3 32 20 CRESOL
C 1 3 122 7A CDELAY
C 1 2 8 08 CRESADD
C 1 0 1000000 0F4240 FREQUENCY
V 1 4 32 20 CRES
V 1 6 122 7A CDEL
The listing shows all parameters that the assembler uses.
Among them is the frequency, that results from that selection,
in mHz (to be able to see the accuracy also for very low
frequencies).
Re-assemble if you need different settings and burn the code
into the controller's flash via the ISP interface.
Don't forget to change the clock fuse to the oscillator,
otherwise your sine might have a too small frequency.
To the top of that page
©2005-2017 by http://www.avr-asm-tutorial.net