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

Current monitoring/logger

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



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

Current monitoring/logger
PostPosted: Sat Apr 26, 2008 6:06 am     Reply with quote

Hi,

i'm trying to make a current logger. I need to monitor a strange thing that is happening in an electric system.

I have a current sensor that is connected direct to the 12F675 ADC.
Here is my code :

Code:
#include <12F675.h>

#device adc=10
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_A1, rcv=PIN_A2)

// OUTPUTs
#define led PIN_A5   

void main() {
      
      long value;
      
      setup_comparator(NC_NC);
      setup_adc_ports(sAN0|VSS_VDD);
      setup_adc(adc_clock_internal);          // Built-in A/D setup function
     delay_us(10);               // A small delay is necessary


   while(TRUE){
      output_low(led);
           value = read_adc();                    // Built-in A/D read function
                delay_us(100);
           output_high(led);
                 printf("%Lu|",value);
       }
}


This code works Smile

My problem is that i want to sample the current with a rate as maximum as possible. Say it 100us... or less if possible.
When i see the 'printf' in my Hyperterminal, i see the same cadency of samples, even if i change the BaudRate.
Is there any limitation in 'printf' function ?

How can i speed up my sampling rate ?

Thank you in advance.
Jacob
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Sat Apr 26, 2008 8:00 am     Reply with quote

Fill an array/buffer/ external/internal memory with your data and once your done, printf the results, printf slows down your code execution allot in your case.
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 1:48 am     Reply with quote

Thank you ...

I will try all Smile
Jacob
Matro
Guest







PostPosted: Mon Apr 28, 2008 4:10 am     Reply with quote

Your "delay_us(100)" isn't useful because the read_adc() will wait for the result. You can remove it.
And as already said, just store the results in RAM and print them once you have all the results you want.

Matro
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 5:33 am     Reply with quote

crystal_lattice wrote:
Fill an array/buffer/ external/internal memory with your data and once your done, printf the results, printf slows down your code execution allot in your case.


Filling a buffer and then sending it later will work only if your buffer is large enough to hold the entire set of data that you want to monitor. But if you want to monitor continuously for arbitrarily long periods of time, then this will not help. In that case you have some hard decisions to make.

1. If possible, do the some of the analysis on the PIC and report only when the "strange thing that is happening in an electric system" happens.

2. Condense the data and avoid using printf at all. For example, if you want to convey only a single 8-bit analog reading, then just send out those 8 bits as a single character using putc(). It won't be ASCII and it will require special software on the other end, probably something more than hyperterminal, to receive these general bytes. But if you did that, then you could send about one character per msec. Still 10 times longer than your goal of 100 usec, but that is the best you can do using continuous data acquisition.

Robert Scott
Real-Time Specialties
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