Path:Home => AVR-EN => Applications => Signal generator
Signal generator AVR applications

Sine/Triangle/Rectangle/saw-tooth signal generator with ATmega16
Hardware, mounting, use and software for a signal generator
Logo

Signal generator ATmega16

  1. Features
  2. Hardware
  3. Mounting
  4. Software
These pages as PDF (62 pages, 2.2 MB).

1 Features of the signal generator with ATmega16 and R/2R network

The hardware properties of this signal generator:

Top of page Features Hardware Mounting Software

2 Hardware

2.1 Controller and signal processing

Functional overview of the hardware This provides an overview over all external components that are connected to the controller.

Input sources are Output via controller ports are the following:

2.2 Schematic

This is the complete schematic with all components.

Scheme of the signal generator

The LCD is connected via a 16 pin standard connector so it can be plugged in from above. The data bus is, eight bit wide, connected to port C. The control bits are connected to port A (bits 5, 6 and 7). The current for backlight can be driven from the stabilized 5 V supply or from the unregulated 9 or 12 V of the power supply. The resistor can be calculated from the formula
RLCD-LED = (Umiddle - 4,1) / ILCD-LED(mA) * 1000

(at 9 V and 150 mA the resistor is e. g. 33 Ω).

The 100k potentiometer for frequency adjustment is connected to the ADC0/PA0 pin. The internal ADC is supplied via a 22 µH choke and a ceramic capacitor. The ADC's reference voltage is internally connected to the ADC supply and is blocked on the AREF pin by a capacitor.

The switches S1 and S2 for the frequency range and S3 and S4 for the wave form are connected to the ports PA1 to PA4. All switch input pins are internally connected to a pull-up resistor and have high potential when the switch is open.

The R/2R Digital-Analog-Converter is built with nine resistors of 2k20 and eight of 1k10 (1% metal film) on port D. The output of the DAC is connected via 10k to the first analog switch 4066 and via another 10k to the second analog switch. Both switches control capacitors of 470 pF, 1 nF, 10 nF and 100 nF and adds these to the RC network. The capacitors to be connected are controlled by the port pins PB0 to PB4.

The RC filtered signal is connected to the positive input pin of the FET operational amplifier CA3140, its negative input connected with ita output (gain = 1). This buffers the signal with an amplitude of 3 Vpp resp. 1,0 Veff and provides it directly or via an electrolytical capacitor to the output plug.

The ATmega16 is clocked by a 16 MHz xtal and two 18 pF capacitors on the XTAL1 input and XTAL2 output pins.

On the port pins PB5 to PB7 as well as on the Reset pin (via 10k to plus) the ISP6 standard programming plug is connected, by which the ATmega16 can be programmed in the system.

2.3 LCD interface

Common LCDs with 14 (without backlight) or 16 pins (with backlight LEDs) can be attached directly to the 16 pin plug on the PCB. If the LCD is a 14 pin you do not need the resistor and the pins 15 and 16 are not connected.

If the LCD type DIP081 is used, which has larger characters than standard LCDs, interfacing to the different pin distances is necessary. The following changes are necessary: Adapter for the DIP081 This is the schematic of the interface.

For the backlight of the DIP081 two options can be chosen:
  1. Operation with a current of 150 mA through the LEDs (as specified by the datasheet), or
  2. operation with 60 mA (current saving option).
In both cases it makes some sense to source the backlight directly from the rectified AC of the supply, because this does not require a constant voltage. In that case a small 78L05 regulator is necessary to supply the controller and its peripherals. The excess heat is then beared by the resistor and not by the regulator. At 9V and 150 mA the heat is 735 mW, at 60 mA 294 mW. Use that for dimensioning the resistor.

At 9V and 60 mA a 82 Ω resistor is required, which should be designed for a heat power of 400 mW (e.g. a standard metal film). If option 2 is used a 15 Ω resistor is required.

2.4 Power supply

The design of the power supply depends majorly from the chosen backlight current. Without backlight a transformer with less than 1 VA or battery operation can be used. With an elevated current for the backlight (e.g. for the DIP081) two options can be chosen:
  1. current like specified with 150 mA for the backlight: a 3.6 VA transformer is necessary, or
  2. half current operation with 60 or 70 mA: a 1.2 VA is required.

2.4.1 The 3,6 VA option

Power supply 3.6VA This is the high-current 3.6 VA option that can supply the backlight with 150 mA steady current. The regulator supplies the controller and its peripherals.

Voltages and currents 3VA6 under load These are the voltages and currents under a load of 170 mA (simulated with this software). The average voltage on the electrolytic capacitor is at 12 V. The current limiting resistor therefore should be
R = (12 - 4,1) / 0,15 = 53 Ω
(practically E12: 56 or 47 Ω; E48: 53,6 Ω)

The resistor should have a power load of 2 W.

Voltages and currents 3VA6 without load These are the voltages without a load. The voltage on the capacitor exceeds 16 V and 25 or 35 V capacitors shall be used.

2.4.2 The 1.2 VA option

Power supply with 1.2VA This is the power supply with reduced LED current.

Voltages and currents with 1.2VA These are the voltages and currents under a load of 100 mA. At an average voltage of slightly above 9 V the current limiting resistor shall be
at 60 mA: R = (9 - 4,1) / 0,06 = 82 Ω
with P = (9 - 4,1) * 0,06 = 294 mW
at 80 mA: R = (9 - 4,1) / 0,08 = 61 Ω
with P = (9 - 4,1) * 0,08 = 392 mW

Due to the higher resistance of the transformer coils the voltage without load current is even higher than in the 3.6 VA case. Dimensioning the capacitors has to consider that to avoid exceeding specification limits.


Top of page Features Hardware Mounting Software

3 Mounting

3.1 PCB layout and component placement

3.1.1 Controller and signal processing

This is the photo mask for the 80-by-80 mm PCB.

Soldering side of the PCB

The related component placement is here:

Component placement on the PCB

All bridges have been made with solderable enamaled copper wire to avoid short-circuits.

3.1.2 LCD interface

Here is the layout for the DIP081 interface PCB.

LCD interface PCB

Note the more than unusual numbering of the DIP081 pins and the two non-connected pins.

LCD pin connector Note further that the 16 pin header is soldered upside down to fit into the female pin header on the PCB.

3.2 Pictures

Components placed on the PCB These are all components placed on the PCB. The external connections for the potentiometer, the four switches as well as the audio and digital outputs as well as the power supply are 1 mm solder pins.

Power supply Power supply from the side The 1.2 VA transformer and the 78L05 are mounted on a matrix board.

3.3 Box

As a shell a small plastic box can be used, as available from household supply stores.

Box from above Box from the side Box opened All fits into a nice little plastic box, with an opening for the mounted LCD and with switches and Cinch connectors.


Top of page Features Hardware Mounting Software

4 Software

4.1 Fuses of the ATmega16

To work correct the fuses of the ATmega16 have to be changed. Working with 1 :MHz by default the fuse for the clock has to be changed, and the JTAGEN fuse. To the left the default fuses are seen, to the right the required changes.

Fuses by default Fuses properties to be changed

The programming of the fuses has to be made with the crystal attached, preferably within the installed system. Otherwise the post-programming verification of the fuse settings fails.

4.2 Software overview

The software subdivides into three relevant functional blocks:
  1. determination of the potentiometer value and the four switches, followed by calculation of the next parameter set,
  2. the take-over of next parameter set during the next zero-crossing of the generated wave, and
  3. the frequency output.

4.2.1 Determination of potentiometer values and switches

The reading of potentiometer values is initiated by the ADC interrupt.

ADC clocking The timer TC0 starts AD conversions. With a prescaler of 1024 and a compare A value of 243 the AD conversion starts with 64.04 Hz resp. a repetition time of 15.6 ms. The compare match initiates AD conversion and clears the T flag to prevent reading results during ongoing conversions.

When completed after 128*13=104 µs the AD conversion ready interrupt sets the T flag in the status register. This holds delay times by that interrupt extremely short to not interfere with fast frequency generation with relevant delays.

Outside the interrupt service routine the AD conversion result is read and 16 of those measurements are summed up. After all 16 measurements have been made (approximately every 250 ms) the switch's positions for the course frequency range are read and the desired frequency is calculated by an 8-by-16 bit multiplication. From this the next CTC value for the frequency generation with TC1 is calculated by a 32-by-24 bit division. If a sine wave is selected the necessary capacitor is derived from the potentiometer value and the frequency range.

Depending from the switches, and if the frequency is 2.500 Hz or above, the resulting wave form (saw-tooth, sine, triangle or rectangle with one, two, four or eight waves per cycle) is determined. If this curve form differs from the previously used form the flag bit bSetR2R is set. If the desired frequency changes the flag bit bSetCtc is set. Further processing of those flags is delayed until the flag bit bStart signals a zero-crossing of the generated wave. Until that transfer starts, the values are stored in SRAM.

4.2.2 Zero-crossing and takeover of the stored values

If during frequency output the 256th step is reached the flag bStart is set and a zero-crossing of the wave form will happen in the next step. Outside the interrupt service routine this flag is checked. This allows synchronization of parameter changes with the frequency generation process.

Parametertransfer If bStart signals zero-.crossing the flag bSetR2R is consulted. In that case the table of the curve form in flash memory is copied to the SRAM. According to the frequency parameters either
  1. each single, or
  2. every second, or
  3. every fourth, or
  4. every eighth
table value from the flash table is copied. In the second to fourth case copying restarts from the beginning if the original table ends, so that multiple waves are written to the SRAM table.

Following the transfer of values or if the flag bit bSetCtc is set the CTC value of TC1 is set according to the stored value. From now on the new frequency is outputted. Both flags are cleared and the new parameters overwrite the previous ones.

From the CTC values and the frequency-specific number of decimal digits the frequency to be displayed is calculated with a 40-by-16 bit division. The result is formated with the decimal point and with thousand separator and displayed on the LCD, together with a wave form character Symbols.

4.2.3 Frequency output

The output is produced by the timer TC1, which is operated in the PWM-CTC mode and, by the compare match A interrupt, reads the next wave table entry is read from SRAM and written to the port to which the DA converter is attached.

TC1 CTC interrupt Depending from the adjusted frequency TC1 produces an interrupt request on compare match A between 512 and 640,000 times per second because the compare values vary between 31,249 and 25. The next table value for frequency generation is read from the table in SRAM and written to the DAC port. If the last table value has been read the bStart flag is set and the table starts from the beginning.

4.3 Software description and details

The software is completely in assembler to allow for an exact timing control, especially for the wave curve output to the DAC.

The assembler source code is here for download. Add the LCD include routines here as well as the wave form tables here to the same path before assembling. If your virus protection software thinks that *.inc files are dangerous: those are simple text files and are not dangerous in that case.

Top of page Features Hardware Mounting Software

5 Application simulation

Here are two simulated curves:

Sine 2 kHz A sine curve with 2 kHz in 256 steps resolution per cycle, without the attached RC filters.

saw-tooth 5 kHz And here is a saw-tooth with 5 kHz with 64 steps per cycle.

Both look fine.


Praise, error reports, scolding and spam please via the comment page to me.

©2018 by http://www.avr-asm-tutorial.net