View previous topic :: View next topic |
Author |
Message |
jjacob
Joined: 08 Mar 2008 Posts: 54 Location: PORTUGAL (PORTO)
|
Current monitoring/logger |
Posted: Sat Apr 26, 2008 6:06 am |
|
|
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
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 |
|
![](templates/subSilver/images/spacer.gif) |
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Sat Apr 26, 2008 8:00 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
jjacob
Joined: 08 Mar 2008 Posts: 54 Location: PORTUGAL (PORTO)
|
|
Posted: Mon Apr 28, 2008 1:48 am |
|
|
Thank you ...
I will try all
Jacob |
|
![](templates/subSilver/images/spacer.gif) |
Matro Guest
|
|
Posted: Mon Apr 28, 2008 4:10 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Mon Apr 28, 2008 5:33 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|