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:
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:
Sine wave signal |
Square Signal |
Triangle signal |
Saw tooth signal |
Noise |
high speed 1MHz signal |
Downloads
Source code and hex – download