Path: Home => AVR-EN => Applications => Sine generators => Fixed sine tn24   Diese Seite in Deutsch: Flag DE Logo

DAC8 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:
  1. 8-bit R/2R network,
  2. selectible and configurable crystal,
  3. either 256, 128, 64, 32, 16 or 8 resolution steps,
  4. large 16-bit delay counter, usable for very low frequencies,
  5. very fast algorithm (minimum cycle length = 16 cycles),
  6. very small 14-pin package.

Hardware

Schematic of the sine generator with ATtiny24 This is all that it needs.

The generator has

PCB layout

Copper side of PCB layout Component side of 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:
  1. the frequency that is to be generated,
  2. the crystal to be used,
  3. the resolution of the sine wave generated, if the frequency is above 3.9 kHz,
  4. if the standard amplitude of 1Veff is sufficient,
  5. 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: 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