ad9850  - Page 1
Forum section: electronics / general

author: sfiber
author_rank: Regular Contributor
timestamp: August 10, 2014, 08:55:13 am
content: hi friends I use stm32f4 and I try this code with ad9850 module.but there is a problem I think.Because when I debug data_to_load and frequency_to_load parameters never take a value.can you check this and if you have a sample code can you share with meCode:#include "stm32f4_discovery.h"//d8 w_clk//d9 frequency update//d10 data//d11 resetGPIO_InitTypeDef GPIO_InitStructure;int i,b;void delay(uint32_t count);void Load_Frequency(long long frequency_to_load);void load_bytes(uint16_t data_to_load);void PIN_Initing(void){RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_15;GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;GPIO_Init(GPIOD,&GPIO_InitStructure);}void load_bytes(uint16_t data_to_load){for(i=0;i<8;i++,data_to_load>>=1){GPIO_WriteBit(GPIOD,GPIO_Pin_10,(data_to_load & 0x01));GPIO_SetBits(GPIOD,GPIO_Pin_8);delay(0x00000010);GPIO_ResetBits(GPIOD,GPIO_Pin_8);}}void Load_Frequency(long long frequency_to_load){long long freq=frequency_to_load*4294967295/125000000;for(b=0;b<4;b++,freq>>=8){load_bytes(freq & 0xFF);}delay(0x0000050);load_bytes(0x0000);GPIO_SetBits(GPIOD,GPIO_Pin_9);}void delay(uint32_t count){while(count--){}}int main(void){PIN_Initing();GPIO_SetBits(GPIOD,GPIO_Pin_15);GPIO_SetBits(GPIOD,GPIO_Pin_11);GPIO_SetBits(GPIOD,GPIO_Pin_8);GPIO_SetBits(GPIOD,GPIO_Pin_9);delay(0x0000F00);Load_Frequency(10.e6);while(1){}}

author: dannyf
author_rank: Super Contributor
timestamp: August 10, 2014, 10:28:30 am
content: Why do you think they never take a value?

author: bwat
author_rank: Frequent Contributor
timestamp: August 10, 2014, 11:15:54 am
content: Quote from: sfiber on August 10, 2014, 08:55:13 amEfendim, 10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?

author: sfiber
author_rank: Regular Contributor
timestamp: August 10, 2014, 11:35:01 am
content: Quote from: bwat on August 10, 2014, 11:15:54 amI tried wtih double but nothing changed

author: bwat
author_rank: Frequent Contributor
timestamp: August 10, 2014, 11:49:56 am
content: Why would you try with a double? Why not use a long long just like the function is specified to take as an argument?

author: sfiber
author_rank: Regular Contributor
timestamp: August 10, 2014, 12:08:27 pm
content: Quote from: bwat on August 10, 2014, 11:49:56 amwhat do you offer me to use

author: bwat
author_rank: Frequent Contributor
timestamp: August 10, 2014, 12:18:15 pm
content: Quote from: sfiber on August 10, 2014, 12:08:27 pmA long long perhaps? Basically, any integer type with at least 25 bits of precision will do since:Code:| ?- X is 1+ceiling(ln(10.0e6)/ln(2)).X = 25 ?Edit: My original formula was off by one!!! Fixed.

author: sfiber
author_rank: Regular Contributor
timestamp: August 10, 2014, 12:34:41 pm
content: Quote from: bwat on August 10, 2014, 12:18:15 pm

author: bwat
author_rank: Frequent Contributor
timestamp: August 10, 2014, 12:48:53 pm
content: Quote from: sfiber on August 10, 2014, 12:34:41 pm1) You've misunderstood what I'm saying. Just use 10000000 instead of 10.0e6.2) I should have used floor and not ceiling. I managed to mess up that simple formula twice!

author: dannyf
author_rank: Super Contributor
timestamp: August 10, 2014, 02:02:31 pm
content: QuoteThe compiler, assuming that it is reasonably competent, would have done that conversion.So it is not the problem - well, it shouldn't be the problem.The OP never established why s/he thought the variables were not taking the values s/he expected them to.

author: sfiber
author_rank: Regular Contributor
timestamp: August 10, 2014, 06:32:00 pm
content: Quote from: dannyf on August 10, 2014, 02:02:31 pmyes completely true.variables dont take value.when I added them to watch window I can only see "not in scope".I never met problem like this.

author: dannyf
author_rank: Super Contributor
timestamp: August 10, 2014, 06:51:31 pm
content: QuoteWe cannot help you if you refuse to help us help you.

author: bwat
author_rank: Frequent Contributor
timestamp: August 11, 2014, 09:41:53 am
content: Quote from: dannyf on August 10, 2014, 02:02:31 pmI agree it's probably not the source of his problem. I pointed it out as the conversion from a float to an int can be a source of undefined behaviour according to K&R 2nd edition. It was something he needed to sort out.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 13, 2014, 06:08:12 am
content: Looks like you are trying to watch local variables outside of functions they belong to. Set a breakpoint INSIDE the Load_frequency() function - there you should see the frequency_to_load var w/o any problems. Same for data_to_load - it does exist only inside the load_data() function.Note: you may need a second delay - after gpio_resetbits in load_data().