Wednesday 3 September 2014

Waveform generator with frequency, amplitude and offset control: Part 2

Bread-boarding

For bread-boarding I will use universal SMD board I ordered from e-bay for about $10. I also ordered samples from ADI, two of each (this is the maximum allowed) and I received them after a week or so. I have one LPXpresso board with LPC1227, which is 64 pins, 30MHz Cortex-M0 microcontroller. I will use it to control the DDS and DACs via SPI interface.

Figure 2. Universal SMD bread board

Figure 3. LPCxpresso LPC1227 development board

I soldered the DDS chip, the 50MHz crystal oscillator and the components around them. I used a 2,54mm connector to connect this breadboard with the MCU kit.

Figure 4. DDS bread board

The program I wrote is quite simple. It initializes the SSP module in SPI mode. After this is simply programs the frequency, phase and control registers in the DDS. Here is the code:

/*
===============================================================================
 Name        : main.c
 Author      : elektronchika
 Version     : v0.01
 Copyright   : Copyright (C) 
 Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

// TODO: insert other include files here

// TODO: insert other definitions and declarations here

void init();
void initSpi();
void spiWrite(uint16_t writeData);
void initDDS();

int i;

int main(void) {

// TODO: insert code here

// Enter an infinite loop, just incrementing a counter
//volatile static int i = 0 ;
init();
initSpi();
initDDS();
while(1) {
i++ ;
//initDDS();
}
return 0 ;
}

void init(){
// Enable clock
LPC_SYSCON->SYSAHBCLKCTRL |= 0xE001081F;  // Enable clock for: Sys, Rom, Ram, FlashReg, FlashArray, SSP, IOCON, GPIO0, GPIO1, GPIO2
// init LED
LPC_GPIO0->MASK = 0xFFFE << 7;
LPC_GPIO0->DIR = 0xFFFF;  // Set PIO0_7 (red LED) as output
}

void initSpi(){
// initialize SSP ports
LPC_IOCON->PIO0_14 |= 0x00000082;  // SCK
LPC_IOCON->PIO0_15 |= 0x00000082;  // SSEL
LPC_IOCON->PIO0_16 |= 0x00000082;  // MISO
LPC_IOCON->PIO0_17 |= 0x00000082;  // MOSI
// Initialize SSP module
LPC_SYSCON->SSPCLKDIV = 0xff;
LPC_SSP->CR0 = 0x0000ff8F;  // Serial clock rate = ??, CPHA = 1, CPOL = 0, SPI, 16 bits
LPC_SSP->CPSR = 0x00000002; // Clock prescaler = 10
LPC_SSP->CR1 = 0x00000002;  // SSP is master
}

void spiWrite(uint16_t writeData){
LPC_SSP->DR = writeData;
//while(LPC_SSP->SR != 0x00000003) {
//}
while((LPC_SSP->SR & (0x10|0x2)) != 0x2);
}

// This function initialize AD9834 with the AN-1070 method
// with 50MHz clock, this should give 200Hz output frequency
// (this is because the DDS clock is doubled)
// 2100 4432 4000 8432 8000 C000 E000 2000
void initDDS(){
spiWrite(0x01c0);
spiWrite(0X4ac7);
spiWrite(0X8000);
spiWrite(0x11c0);
spiWrite(0X400f);
spiWrite(0X8001);
spiWrite(0XC000);
spiWrite(0XE000);
spiWrite(0x0000);
}


And here are the results. The frequency doesn't correspond to the one I set. I checked everything - SPI communication waveforms, power supply, reference voltage, I debuged the program step by step. Everything looks perfect. When I set low frequency, where only the LSB frequency register is different from zero - the output was DC level. This make me look through the internet for similar behaviour.
I found this subject in ADI Engineering Zone https://ez.analog.com/thread/45413 This guy has the similar problem, I think. But I dont have 25MHz crystal oscillator to test this, and thats why I will order 2 and check if the DDS will work correctly with it. Till then I will continue looking for a solution. Be ready for the update

No comments:

Post a Comment