Author Topic: ad9850  (Read 5395 times)

0 Members and 1 Guest are viewing this topic.

Offline sfiberTopic starter

  • Regular Contributor
  • *
  • Posts: 107
  • Country: tr
ad9850
« on: August 10, 2014, 08:55:13 am »
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 me
Code: [Select]
#include "stm32f4_discovery.h"

//d8 w_clk
//d9 frequency update
//d10 data
//d11 reset

GPIO_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)
{}
}
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ad9850
« Reply #1 on: August 10, 2014, 10:28:30 am »
Why do you think they never take a value?
================================
https://dannyelectronics.wordpress.com/
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: ad9850
« Reply #2 on: August 10, 2014, 11:15:54 am »
Code: [Select]
Load_Frequency(10.e6);
Efendim, 10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?
« Last Edit: August 10, 2014, 11:21:42 am by bwat »
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline sfiberTopic starter

  • Regular Contributor
  • *
  • Posts: 107
  • Country: tr
Re: ad9850
« Reply #3 on: August 10, 2014, 11:35:01 am »
Code: [Select]
Load_Frequency(10.e6);
Efendim, 10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?

I tried wtih double but nothing changed
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: ad9850
« Reply #4 on: August 10, 2014, 11:49:56 am »
Why would you try with a double? Why not use a long long just like the function is specified to take as an argument?
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline sfiberTopic starter

  • Regular Contributor
  • *
  • Posts: 107
  • Country: tr
Re: ad9850
« Reply #5 on: August 10, 2014, 12:08:27 pm »
Why would you try with a double? Why not use a long long just like the function is specified to take as an argument?
what do you offer me to use
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: ad9850
« Reply #6 on: August 10, 2014, 12:18:15 pm »
Why would you try with a double? Why not use a long long just like the function is specified to take as an argument?
what do you offer me to use
A long long perhaps? Basically, any integer type with at least 25 bits of precision will do since:
Code: [Select]
| ?- X is 1+ceiling(ln(10.0e6)/ln(2)).
X = 25 ?

Edit: My original formula was off by one!!! Fixed.
« Last Edit: August 10, 2014, 12:28:16 pm by bwat »
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline sfiberTopic starter

  • Regular Contributor
  • *
  • Posts: 107
  • Country: tr
Re: ad9850
« Reply #7 on: August 10, 2014, 12:34:41 pm »
Why would you try with a double? Why not use a long long just like the function is specified to take as an argument?
what do you offer me to use
A long long perhaps? Basically, any integer type with at least 25 bits of precision will do since:
Code: [Select]
| ?- X is 1+ceiling(ln(10.0e6)/ln(2)).
X = 25 ?

do you have a source code to use

Edit: My original formula was off by one!!! Fixed.
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: ad9850
« Reply #8 on: August 10, 2014, 12:48:53 pm »
do you have a source code to use

1) 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!

"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ad9850
« Reply #9 on: August 10, 2014, 02:02:31 pm »
Quote
10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?

The 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline sfiberTopic starter

  • Regular Contributor
  • *
  • Posts: 107
  • Country: tr
Re: ad9850
« Reply #10 on: August 10, 2014, 06:32:00 pm »
Quote
10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?

The 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.

yes 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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ad9850
« Reply #11 on: August 10, 2014, 06:51:31 pm »
Quote
I never met problem like this.

We cannot help you if you refuse to help us help you.
================================
https://dannyelectronics.wordpress.com/
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: ad9850
« Reply #12 on: August 11, 2014, 09:41:53 am »
Quote
10.e6 bir "float" ama bir "long long" istiyorsunuz, degil mi?

The 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.
I 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.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: es
Re: ad9850
« Reply #13 on: August 13, 2014, 06:08:12 am »
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().
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf