View previous topic :: View next topic |
Author |
Message |
ilker07
Joined: 03 Jun 2022 Posts: 39
|
Reading cycles |
Posted: Fri Dec 27, 2024 10:20 am |
|
|
Hello friends, I am trying to read the number of areas in a signal like the one below. I want to find these areas by reading adc with cccs c, how should I proceed? The peak point in the signals here is sometimes 2 volts, sometimes 3 volts; at the lowest point, sometimes 0v, sometimes 1 v, sometimes 2 volts; so the numbers are variable.
[img][/img] |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9267 Location: Greensville,Ontario
|
|
Posted: Fri Dec 27, 2024 10:39 am |
|
|
maybe do this...
old reading =0
now in a tight loop
read adc
if new reading is greater than old reading, replace old reading with new reading
if new reading is less, save old reading as 'peak reading #1'
start loop again
I'm sure someone will have real, good code.. I just see that you want the max and save it, then reset, do it again for the next 'peak'. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19584
|
|
Posted: Fri Dec 27, 2024 12:45 pm |
|
|
But big key question, is what PIC, and what is the frequency involved?.
The early PIC's can only sample at perhaps 10000 samples/second.
The time taken to actually take the reading, depends on the rate you are
clocking the ADC. |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 62
|
|
Posted: Sat Dec 28, 2024 8:00 am |
|
|
Looks like your signal always returns to 0V after each peak. So, instead of using the ADC why not use a comparator? Set the threshold to a low value and feed the output of the comparator to a counter in the PIC.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9267 Location: Greensville,Ontario
|
|
Posted: Sat Dec 28, 2024 8:27 am |
|
|
hmm, I thought that too but... I re-read his post and 'valley' doesn't always go to zero(ground) so I still think 'peak detector algorithm' is the way to code.
As Mr. T points out, a few 'minor ' details are missing........ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19584
|
|
Posted: Sat Dec 28, 2024 9:06 am |
|
|
I think Jay's approach would be fine. You'd want something like:
(Pseudo code...)
Code: |
int16 v1, v2;
int16 sens = 10; //Change to avoid detecting noise
v1 = read_adc();
while(TRUE)
{
v2 = read_adc();
if (abs(v2 - v1) >= sens)
{
v1 = v2;
value_changed(); //what you want to happen
}
delay_us(gap_between_samples);
}
|
You need some form of sensitivity limit, otherwise if you are near the
top/bottom of the signal, and there is a little noise, you will incorrectly
detect this as a change. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 482 Location: Montenegro
|
|
Posted: Sat Dec 28, 2024 9:53 am |
|
|
A few minor details missing, yes :-). Like frequency of the signal and maybe minimal difference between top and bottom.You don't actually have to measure the top and bottom values, it may be enough to detect the direction of the signal. Going up, it is going to count. Going down, wait until it starts going up again. |
|
|
|