CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

10 bit ADC conversion, how to send it to PC as u short?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RaulHuertas



Joined: 31 May 2008
Posts: 7

View user's profile Send private message

10 bit ADC conversion, how to send it to PC as u short?
PostPosted: Sat May 31, 2008 5:54 pm     Reply with quote

Hello! Very Happy

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

View user's profile Send private message

PostPosted: Sat May 31, 2008 8:27 pm     Reply with quote

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
PostPosted: Sun Jun 01, 2008 3:19 am     Reply with quote

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

View user's profile Send private message

Hi, and thanks!
PostPosted: Sun Jun 01, 2008 7:44 am     Reply with quote

Hi. It was a dummy error of mine. I was usijng an old connection configuration with a different speed. Embarassed

Thanks for your atention, bye! Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group