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

HELP - ADC (10 bits, 8 ports) + RS232 trouble.

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



Joined: 01 Sep 2007
Posts: 3

View user's profile Send private message

HELP - ADC (10 bits, 8 ports) + RS232 trouble.
PostPosted: Wed Sep 05, 2007 8:04 am     Reply with quote

For you information:
Compiler: CCS Compiler version 4.038
PIC: PIC16F877
Clock Frequency 10 MHz
Baud Rate Setting: 9600

First of all, I started as a beginner 7 days ago with no clue. Took me hard work to get up to this point.

What I am doing?
I'm building a virtual glove that has 5 Flexible sensors and 3 accelerometers. Sensor readings are to be sent to the PC for processing at a constant rate.

- Sampling 8 analog ports at 10 BIT resolution (#device ADC = 10) of various sensors then filtering it with an average of 6 samples + exponetial moving window. I managed to use the REAL TIME code provided by Mark R Hahn (http://www.ccsinfo.com/forum/viewtopic.php?t=21407) and get a final throughput of 20 HZ of sensor sampling rate per analog port (after filtering).

However, together with the ADC, I need to consistently send data by RS232 as fast as possible. However, doing that SLOWS everything by a factor of 100. So now I'm getting a sensor reading updated once every second. That's terrible for measuring an accelerometer.

I'm also running a 20X4 LCD task updating at every 200ms.


My Question:
So what is the approach for this? Should I remove all filtering and exponential moving average window and send RAW samplings through the RS232 for the computer to process later?

Or am I using an inncorrect baud rate? Should I increase it?

What about real-time, should I remove it altogether? Interrupts?




Sorry to throw so many questions, but my knowledge of MCU processing is very limited. I can only do the brute force approach.
Ttelmah
Guest







PostPosted: Wed Sep 05, 2007 8:56 am     Reply with quote

Use interrupt driver RS232 transmit code with a buffer (look at EX_STISR.C). The probelm is that the RS232 transmit, only has two characters of hardware buffering, so if you send three characters, the code has to _wait_ for one to transmit, before the last character can be sent. If you send ten characters, the code will have to wait for eight character times...
This is leading to huge waits in your transmit code, which is slowing everything else down. Using the buffer and interrupt, characters will be transferred from the buffer, _when_ the hardware has space to take them.

Best Wishes
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: HELP - ADC (10 bits, 8 ports) + RS232 trouble.
PostPosted: Wed Sep 05, 2007 11:31 am     Reply with quote

So you have to send 8 int16 readings per sample interval. Have you decide what kind of packet you are going to use? I suggest you start with something simple. For example start the packet with 0xFF,0xFF and then send the data. As long as you analog values are less than 65535 this will be able to work. This would be easy to decode from a PC. Once you have it working add in as much error correction as you require. This can easily be done from an interrupt.

The LCD has to be removed or setup to multiplex time with reading the ADC. this would not be trivial task.
Steele404



Joined: 01 Sep 2007
Posts: 3

View user's profile Send private message

PostPosted: Sat Sep 08, 2007 3:26 am     Reply with quote

Thanks you two, I'm trying that out.... Smile
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