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

Facing a problem to measure peak voltage (ADC) at 50kHz

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



Joined: 12 Feb 2009
Posts: 54

View user's profile Send private message

Facing a problem to measure peak voltage (ADC) at 50kHz
PostPosted: Sun Dec 04, 2011 7:00 pm     Reply with quote

Currently, I have a project which is using PIC16F883 to measure peak voltage through ADC port and ADC input's frequency is at 50kHz. The input to the ADC may varies, sometimes like pulse wave, sawtooth wave or sine wave but it is at fixed 50kHz. My problem is, I always failed to measure a peak voltage ex in-rush current which is occurred only in a few ms.

I have used two method to measure it:

i - when the ADC value is above than certain value, increase a counter.
Running in a while loop.

ii - i take 20 samples where 1 sample is taken at 128us. Then i calculate the
average.

Do you guys have any suggestion to solve this matter. Thanks in advance.

* ADC clock FOSC /32
* Used internal MCU oscillator - 8MHz
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 05, 2011 12:41 am     Reply with quote

Do you mean, the ADC input voltage is a 50 kHz sine wave, or did you rectify the 50 kHz signal before? You can't reliably detect a peak voltage if it lasts shorter than the time between two ADC conversions.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Dec 05, 2011 3:13 pm     Reply with quote

This can be done with a rectifier + peak hold capacitor - and a pic output line
to reset the "peak hold" capacitor. ( metal film capacitor please )

Let me second the previous post - its NOT gonna happen with simple ADC readings. You need some SOLDER programming of external analog components to do this right.

Very Happy
khalis



Joined: 12 Feb 2009
Posts: 54

View user's profile Send private message

PostPosted: Mon Dec 05, 2011 8:48 pm     Reply with quote

Thanks for the response guys...

FVM >> ADC input is not 50kHz sine wave but 50kHz pulse wave. But it also can be a different waveform because it is depending to load (Inductive or Capacitive) which it is connected to. Actually, PIC is used to measure discharge current from a battery (Inverter). As a result, the discharge current some kind like On and Off at 50kHz.

asmboy >> I have read that kind of method in the internet before but still under consideration because if it is possible, i want to sense the peak current by using software method first.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 06, 2011 12:30 am     Reply with quote

Sensing the peak current by software methods isn't feasible, when the waveform has a frequency of 50 kHz and each ADC conversion takes about 50 µs. At best, you can try to sample the peak current if you know the time of it's ocurrence in advance which may be the case when the processor is controlling the inverter. The ADC acquisition time still restricts the accuracy of catching the true peak current.
khalis



Joined: 12 Feb 2009
Posts: 54

View user's profile Send private message

PostPosted: Tue Dec 06, 2011 1:51 am     Reply with quote

Noted that FvM...i knew it before but i still need opinion from others like you guys. Anyway, thanks again for your explanation.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Dec 06, 2011 9:45 am     Reply with quote

you need to understand that software does NOT solve all problems Very Happy

a flexible approach that combines hardware with software skill is
the way to success. as other posters have demonstrated so well -
clear mathematical analysis is the ONLY basis for a good solution.

i actually can imagine a statistical way to get the info you want - with only software - but it is NOT pretty and it would take a LONG time to get that info - when i suspect you need it "FAST" --
you see, this is one of the cases where no amount of software cleverness is going to get the answer you want in the TIME you want it
Cool
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Dec 06, 2011 9:54 am     Reply with quote

asmboy wrote:
you need to understand that software does NOT solve all problems Very Happy


True but if he was using a PIC capable of sampling at 1M samples per second then what he is doing can be done in software.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Dec 06, 2011 10:26 am     Reply with quote

asmallri wrote:

True but if he was using a PIC capable of sampling at 1M samples per second then what he is doing can be done in software.


Even at 1M samples that is only 20 samples per cycle, and he describes the waveform as "pulse wave". Unless you can guarantee the pulse peaks are at least 5% duty cycle the A/D still won't catch them. You have to go much faster than 1M samples...or go the hardware route.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Dec 06, 2011 12:10 pm     Reply with quote

Ok, I'm not a hardware expert but here are some thoughts:

1) What is the definition for peak current? Without a time parameter it seems like a meaningless value to me. I mean, if you are measuring in small enough intervals you can measure an infinite current on the pulse edges but very soon the current will drop down to more normal values. All kind of higher harmonics are present but total energy is low. Wouldn't it make sense to have some kind of low pass filter at, say, 200kHz?

2) What kind of input signal is this? You say it is always 50kHz, that suggests it is a bit special.
If you have a limited number of repeated signal patters, maybe you can do something clever by calculating when the largest current is supposed to occur for this signal pattern? And then take a sample at the calculated time after the zero crossing?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Dec 06, 2011 1:13 pm     Reply with quote

Quote:

What is the definition for peak current?


I deal with this fairly often in BLDC motor control -

to ignore reactive phase issues - I tend to use hi side sampling of a small I-sense resistor and convert the V-drop to an I-drop - and read THAT -
of course the peaks I am recovering are two orders of magnitude lower in frequency than this problem ......

In the case of this post - the frequency is just too high to NOT miss peaks, w/o well defined hardware help.
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