Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] stm32f100 and dds ad9850, take a look at this code. problem.

Status
Not open for further replies.

matise

Newbie level 4
Newbie level 4
Joined
Nov 15, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,321
that dds just doesent work.

Have i done something wrong with my code?
Anyone?
Any ideas?

Code:
#include <stm32f10x.h>
#include <stm32f10x_rcc.h>
#include <stm32f10x_gpio.h>

int main(void)
{
	  GPIO_InitTypeDef GPIO_InitStructure;

		   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);      // Enable Peripheral Clocks
		   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);

		   GPIO_StructInit (& GPIO_InitStructure);
		   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 |GPIO_Pin_8 | GPIO_Pin_7 | GPIO_Pin_6;
		   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
		   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
		   GPIO_Init(GPIOC , &GPIO_InitStructure);

		   GPIO_StructInit (& GPIO_InitStructure);
		   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
		   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
		   GPIO_Init(GPIOA, &GPIO_InitStructure);

    while(1)
    {
    	MM_AD9850_Init();
    	MM_AD9850_SetFreq();
    }
}

void MM_AD9850_Init()
{
	/*
		Initialize AD9850
	  	PC9 - W_CLK
		PC8 - FQ_UD
		PC7 - DATA
		PC6 - RESET
		All output 2Mhz
	*/

	// UP
	GPIO_WriteBit(GPIOC, GPIO_Pin_9 |GPIO_Pin_8 | GPIO_Pin_6, Bit_SET);

	//DOWN
	GPIO_WriteBit(GPIOC, GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_6, Bit_RESET);
}

void MM_AD9850_SetFreq()
{
	int n=0;

     char frequency = 0x0A3D70A4; // 5MHz

	for (n=0; n<32; n++)
	{
    		// set data pin (2) to 1 or 0
		if ((frequency & 0x1) == 1)
		{
			// set data pin (2) to 1
			GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);
		}
		else
		{
			// set data pin (2) to 0
			GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);
		}

		// W_CLK pulse, so AD9850 can shift data in register
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);

		// shift one bit...
		frequency>>=1;
  	}

	// all 0 for ad9850
	GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);

	for (n=0; n<8; n++)
	{
  		// W_CLK pulse, so AD9850 can shift data in register
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
	}

	// fq_ud
	GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
	GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
}

#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file , uint32_t line)
{
                                         /* Infinite loop */
                                         /* Use GDB to find out why we're here */
while (1);
}
#endif
 
Last edited by a moderator:

I think you should have defined the function(s) of setting the frequency and initialization function of the board before the main function.Call those functions before the main function and let us know what happens.
 

you appear to be in a continuous loop initialising the DDS and setting a frequency
try putting a delay of a few seconds at the end of the loop
Code:
    while(1)
    {
    	MM_AD9850_Init();
    	MM_AD9850_SetFreq();
           << delay a few seconds
    }
have you checked the DDS signals with an oscilloscope to make sure they look correct
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top