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 CCS Technical Support

Reading cycles

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



Joined: 03 Jun 2022
Posts: 39

View user's profile Send private message

Reading cycles
PostPosted: Fri Dec 27, 2024 10:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 27, 2024 10:39 am     Reply with quote

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: 19585

View user's profile Send private message

PostPosted: Fri Dec 27, 2024 12:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 28, 2024 8:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 28, 2024 8:27 am     Reply with quote

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: 19585

View user's profile Send private message

PostPosted: Sat Dec 28, 2024 9:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 28, 2024 9:53 am     Reply with quote

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.
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