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.

coding for assigning memory to the pointers

Status
Not open for further replies.

skarthikshines

Member level 5
Joined
Feb 21, 2011
Messages
81
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,060
hi,

in my project am using 5 analog input and i have to take avg of that 5 input.. by means of adc i convert that 5 analog input into digital.. now those digital value stored in following address..

0x200
0x202
0x204
0x206
0x208
in order to take the avg of this 5 input i have read that content of above memory addrees
any body will help me to read this content of memory by means of pointer.. pls send the any sample codes.
 

The question is not clear.
Do you need to read a specific memory location?
Or these positions are in facts ADC registers mapped into memory space? In the second case, if you use C you normally can access peripheral registers via predefined symbolic names.
 

Code:
value1 = *( 0x200 ) ;
value2 = *( 0x202 ) ;
value3 = *( 0x204 ) ;
value4 = *( 0x206 ) ;
value5 = *( 0x208 ) ;
 

hi,

in my project am using 5 analog input and i have to take avg of that 5 input.. by means of adc i convert that 5 analog input into digital.. now those digital value stored in following address..

0x200
0x202
0x204
0x206
0x208
in order to take the avg of this 5 input i have read that content of above memory addrees
any body will help me to read this content of memory by means of pointer.. pls send the any sample codes.

Code:
long value;
int *ptr;
ptr = 0x200;

for(int i=0;i<[I]no of values[/I];i++)
{
value = *ptr;
ptr++;
}

value = value/[I]no of values[/I]

}
 

thank you for your kind reply sir .. i will try and get back to you sir
 

I am not sure about the line

Code:
ptr = 0x200;

and address increment depends on compiler, in some compilers if "int" type is used, the address increments by 4 bytes, in that case try "short" type.
 
Last edited:

I am not sure about the line

Code:
ptr = 0x200;

and address increment depends on compiler, in some compilers if "int" type is used, the address increments by 4 bytes, in that case try "short" type.

I'm afraid you're close srkanthsamaga, but no cigar.

The line in question:

Code:
    ptr = 0x200;

Assigns an integer to a pointer to an integer, this will result in a compiler error. You must explicitly indicate to the compiler that the value 0x200 is an address to an integer type:

Code:
    ptr = (int *)0x200;

This is of course assuming the value at location is indeed of size integer, 10-bit, 12-bit or 16-bit ADC value, and not of size char, 8-bit value.

And I believe you intended this:

value += *ptr;

instead of this:

value = *ptr;

I just glanced at the code, so there maybe other issues.

Hope the info helps.
 

hi,

It has to be like this Value += *ptr;
You won't get the average of 5 if you use Value = *ptr; Because when no of values becomes 5 Ptr will have 208,*208(Value at that address) will be saved in Variable Value..
Hence change the code to be
it has to be Value += *ptr;.

Note: Make sure to use (float) *Ptr or (int) *ptr according to the data which has to be read from memory location,similarly Variable Value has to changed..To get more accurate results....

Best regards
S.Naveen
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top