RadioLocman.com Electronics ru
Advanced Search +
  

11-20-2010

AVR DDS signal generator V2.0 Part 2. Firmware

Part 1. Schematic

AVR DDS 2.0 Firmware

As I have mentioned DDS function is a modified Jesper’s DDS algorithm. Main modification is adding additional ASM line which enables to stop DDS generation. In version 1.0 the only option was to reset device, dds function checks if CPHA bit is set in SPCR register which is set during external interrupt service routine (stop button). So now algorithm takes 10 CPU cycles instead 9.

void static inline Signal_OUT(const uint8_t *signal, uint8_t ad2, uint8_t ad1, uint8_t ad0)
{
asm volatile( “eor r18, r18 ;r18<-0″ “ ”
“eor r19, r19 ;r19<-0″ “ ”
“1:” “ ”
“add r18, %0 ;1 cycle” “ ”
“adc r19, %1 ;1 cycle” “ ”
“adc %A3, %2 ;1 cycle” “ ”
“lpm ;3 cycles” “ ”
“out %4, __tmp_reg__ ;1 cycle” “ ”
“sbis %5, 2 ;1 cycle if no skip” “ ”
“rjmp 1b ;2 cycles. Total 10 cycles” “ ”
:
:”r” (ad0),”r” (ad1),”r” (ad2),”e” (signal),”I” (_SFR_IO_ADDR(PORTA)), “I” (_SFR_IO_ADDR(SPCR))
:”r18″, “r19″
);}

DDS Signal tables has to be placed in flash sections where address starts with 0xXX00. So these sections has to be defined in makefile for proper memory placement:

#Define sections where to store signal tables
LDFLAGS += -Wl,-section-start=.MySection1=0x3A00
LDFLAGS += -Wl,-section-start=.MySection2=0x3B00
LDFLAGS += -Wl,-section-start=.MySection3=0x3C00
LDFLAGS += -Wl,-section-start=.MySection4=0x3D00
LDFLAGS += -Wl,-section-start=.MySection5=0x3E00
LDFLAGS += -Wl,-section-start=.MySection6=0x3F00

LCD control library is described here.

LCD menu control

All actions can be viewed in LCD menu. Menu can be controlled with 5 buttons that are next to LCD module

Up and down arrow buttons are used for browsing menu while right and left arrow buttons are used for changing frequency value. When middle button is pressed – signal generating starts. Press middle button again to stop signal generator.

Here is a complete menu system of signal generator:

AVR DDS signal generator V2.0: LCD menu

Important to notice, that there is a separate menu for changing frequency step. This is convenient if you need to change generator frequencies in wide range. This allows to set any frequency with relatively few button clicks.

Noise generation don’t have frequency setting. It uses simple rand() function where results are continuously output to DDS output.

High speed signal has four frequencies available: 1, 2, 4 and 8MHz.

Testing and discussion

I have tested signal generator with oscilloscope and frequency counter. Signals look like expected in all frequency range [1 to 65535Hz]. Amplitude and offset regulator works OK. If offset is set to 5V, then maximum clear signal amplitude may be 5V as another 5V is already used for offset(same is if offset is -5V).

Here are few test signals on oscilloscope screen:

AVR DDS signal generator: sine wave signal
Sine wave signal
AVR DDS signal generator: square signal
Square Signal
AVR DDS signal generator: triangle signal
Triangle signal
AVR DDS signal generator: saw tooth signal
Saw tooth signal
DDS генератор на Atmega16:  Noise
Noise
DDS генератор на Atmega16: high speed 1MHz signal
high speed 1MHz signal

Downloads

Source code and hex – download

scienceprog.com

You may have to register before you can post comments and get full access to forum.
User Name
Fragments of discussion:Full version of discussion »
  • This Fuse bits must be programmed: OCDEN, SPIEN, BOOTSZ1, BOOTSZ0, SUT00, SUT01. But on scienceprog.com you will see that JTAG fuse programmed too. I think- it is wrong.
  • Here's a project for Proteus 7.7 SP2 and AVR Studio project files (in AVR Studio need to use an external makefile). If someone needs...
  • sir how can we use 8 bit DAC instead of r2r network
  • In this construction, the use of DAC is impossible. You will need to completely change the firmware for this decision. In addition, it would complicate the design, because the DAC will require additional external components.
  • if i use 1k resistors instead of 20k of r2r network than what happens.

News on theme:

Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus