By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

Need a sample code to measure rms current in embedded C

P: 5
I am using PIC16f1787 as my main controller. I have a device which is battery operated. to ensure long battery life,I am planning to put the device in sleep mode. The main function of this device is to measure rms current and to set alarm if the measured current exceeds the pickup value.The alarm has to be reset by 3 mechanisms- a reset switch, a reset signal and auto reset time. The second function is to detect low battery volatge of the device and indicate the low volatge by an LED.

I am planning to wake the device by 2 timer interrupts.First timer interrupt of 1.25 msec to measure current only. Second timer interrupt of 10 msec to measure low battery voltage,to set alarm for current overload and to reset alarm.
Please help.
Dec 21 '15 #1
Share this Question
Share on Google+
9 Replies


P: 5
I am planning to take 16 samples every 20 msec for measuring rms current.
Dec 21 '15 #2

Expert 100+
P: 2,398
Sounds like you can measure instantaneous current and are seeking advice on how to convert a series of these current readings into rms current. I'm not sure rms has any meaning for an aperiodic function. Have you looked at the current waveform to see if it is periodic?
Dec 21 '15 #3

P: 5
As per my knowledge, I think current is always periodic. Yes I want to measure rms current. I will have to take 16 samples in every 20 msec,sum these squared samples,divide by number of samples and take a square root of entire total. My question is How to generate a 10 msec interrupt to generate delay of 1 hour?
Dec 22 '15 #4

P: 5
Also would like to know How can I handle multiple time sliced tasks using a single timer interrupt?
Dec 22 '15 #5

Expert 100+
P: 2,398
You referred to a battery-operated device in your first post. Batteries are typically direct-current (dc) voltage and current. If current is ideal dc then it is a fixed value that never varies - in that case, all instantaneous current readings are identical and rms current equals instantaneous current. In a real-world battery, voltage and current will droop as the battery discharges; in that case, current is aperiodic and entire concept of rms becomes uncertain. Also in real-world, current load of a digital circuit varies at the nanosecond time scale - probably a meaningful rms there, but you won't see it if you sample at 1 msec.

I suggest you find out what the current waveform looks like. Ideally, your sampling regime should be influenced by the periodicity of the signal.

Computing rms from samples spread over 20 msec suggests that you expect the current waveform to have a frequency of 50 Hz.
Dec 23 '15 #6

Expert 100+
P: 2,398
You only need one timer interrupt at 1.25 msec. Every 8th interrupt marks 10 msec; every 2,880,000th interrupt marks 1 hour.

Implementing a multi-tasking operating system ("multiple time-sliced tasks") is nontrivial. That's a lot of functionality to ask of a PIC processor.
Dec 23 '15 #7

Expert 100+
P: 2,398
How fast can your hardware capture the instantaneous current? Some A/D chips take longer than 1.25 msec.
(Or at least they used to - my age may be showing.)
Dec 23 '15 #8

P: 5
yes you are right.I am using internal adc of pic16f1787. It takes more than 1.25 msec .
Please provide some alternate solution.
Feb 5 '16 #9

Expert 100+
P: 2,398
If your A/D is too slow to measure the waveform in question, then you either need to get a faster A/D or you need to design some sort of rectifier circuit that derives a second waveform from the first -- where the second waveform is slow enough to be measured. Then you use the known relationship between the two waveforms to compute the rms of the first.

Do you have an electrical engineering background?
Feb 5 '16 #10

Post your reply

Sign in to post your reply or Sign up for a free account.