View previous topic :: View next topic |
Author |
Message |
RaulHuertas
Joined: 31 May 2008 Posts: 7
|
10 bit ADC conversion, how to send it to PC as u short? |
Posted: Sat May 31, 2008 5:54 pm |
|
|
Hello!
I'm happy playing with the demo of this compiler, especially because is very easy to use.
I'm trying to use my PIC as an oscilloscope but I have some troubles sending the ADC conversion Data to the PC.
I'm configuring the AD module for a 10 bit conversion (1023). My PIC is a 16F877A and supports this resolution. I'm catching the results with a int16 this way:
Code: |
#include <16F877A.h>
#device adc=10 //main.h
...
unsigned int16 analogV;
char* pointer = &analogV;
...
analogV = read_adc(); |
And then I send the data to the PC like this:
Code: |
putc( pointer[0] );
putc( pointer[1] ); |
Now in the PC I want this two bytes be interpreted as unsigned shorts( 2 bytes). But I have results over 2560 or 7000 :S.
Code: |
port.Read( buffer, 2 );
data[0] = buffer[0];
data[1] = buffer[1];
cout<<dato<<endl;
|
How to fix it?, this is more than an endianness stuff beacuse I've tried both, little and big endian format, and I get the same results :(. Please some help.
I'm using CCS under Windows. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat May 31, 2008 8:27 pm |
|
|
Note that for this compiler a "short" is 1 bit. A default "int" is 8 bits unsigned, though many use int8 to avoid confusion. A "long" is 16 bits unsigned or int16. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Guest
|
Ttelmah |
Posted: Sun Jun 01, 2008 3:19 am |
|
|
The problem is not with short/long, since he is not using this notation in the PIC code.
It is impossible to actually work out what the PC code is 'meant' to do, since he doesn't show count, dato, endl etc....
The simple way to recombine at the PC end, is just:
val = buffer[0]+buffer[1]*256;
There is though a large potential problem. Unless the serial is being used in 'binary' mode, since in 'text' mode, the PC itself, may filter some characters. This is always the 'caveat' of sending binary values.
Best Wishes |
|
|
RaulHuertas
Joined: 31 May 2008 Posts: 7
|
Hi, and thanks! |
Posted: Sun Jun 01, 2008 7:44 am |
|
|
Hi. It was a dummy error of mine. I was usijng an old connection configuration with a different speed.
Thanks for your atention, bye! |
|
|
|