DSPRelated.com
Forums

simple sampling algo question

Started by danielsan March 4, 2006
Joerg wrote:
> I still think this job just requires a timer, no fancy math. Unless, of > course, all the timers are used up already
He might not even need an explicit timer, as one might be implicit in the sample rate of the ADC. Just count X zero crossings per N samples at R samples per second and do the very simple arithmetic to get the average signal frequency. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. wrote:
> Joerg wrote: > >>I still think this job just requires a timer, no fancy math. Unless, of >>course, all the timers are used up already > > > He might not even need an explicit timer, as one might be implicit > in the sample rate of the ADC. Just count X zero crossings per N > samples at R samples per second and do the very simple arithmetic > to get the average signal frequency.
I don't see the need for an ADC at all. Do you mean to use it as a timer somehow, discarding any samples? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> Ron N. wrote: > > Joerg wrote: > >>I still think this job just requires a timer, no fancy math. Unless, of > >>course, all the timers are used up already > > > > He might not even need an explicit timer, as one might be implicit > > in the sample rate of the ADC. Just count X zero crossings per N > > samples at R samples per second and do the very simple arithmetic > > to get the average signal frequency. > > I don't see the need for an ADC at all. Do you mean to use it as a timer > somehow, discarding any samples?
Why discard the samples when one can use the ADC as both the signal input and the timer? This might be one possible solution if he has an ADC input with programmable or fixed sample rate, and no other extra sytem timers or analog inputs on the system. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. wrote:
> Jerry Avins wrote: > >>Ron N. wrote: >> >>>Joerg wrote: >>> >>>>I still think this job just requires a timer, no fancy math. Unless, of >>>>course, all the timers are used up already >>> >>>He might not even need an explicit timer, as one might be implicit >>>in the sample rate of the ADC. Just count X zero crossings per N >>>samples at R samples per second and do the very simple arithmetic >>>to get the average signal frequency. >> >>I don't see the need for an ADC at all. Do you mean to use it as a timer >>somehow, discarding any samples? > > > Why discard the samples when one can use the ADC as both the > signal input and the timer? This might be one possible solution > if he has an ADC input with programmable or fixed sample rate, > and no other extra sytem timers or analog inputs on the system.
Maybe I'm completely confused. I don't see how to use an ADC as part of a way to count the zero crossings in a specific interval of time. I assume that there will be enough zero crossings in that interval to make interpolating not worth the trouble. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> Ron N. wrote: > > Jerry Avins wrote: > > > >>Ron N. wrote: > >> > >>>Joerg wrote: > >>> > >>>>I still think this job just requires a timer, no fancy math. Unless, of > >>>>course, all the timers are used up already > >>> > >>>He might not even need an explicit timer, as one might be implicit > >>>in the sample rate of the ADC. Just count X zero crossings per N > >>>samples at R samples per second and do the very simple arithmetic > >>>to get the average signal frequency. > >> > >>I don't see the need for an ADC at all. Do you mean to use it as a timer > >>somehow, discarding any samples? > > > > > > Why discard the samples when one can use the ADC as both the > > signal input and the timer? This might be one possible solution > > if he has an ADC input with programmable or fixed sample rate, > > and no other extra sytem timers or analog inputs on the system. > > Maybe I'm completely confused. I don't see how to use an ADC as part of > a way to count the zero crossings in a specific interval of time. I > assume that there will be enough zero crossings in that interval to make > interpolating not worth the trouble.
Sorry. I was assuming a computer was already involved somewhere in the OP's system. Then it's an added dozen lines or less of C code. If there's no CPU, then it will involve more stuff to extract frequency from a sequence of samples, than just the sampling ADC. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. wrote:
> Jerry Avins wrote: > >>Ron N. wrote: >> >>>Jerry Avins wrote: >>> >>> >>>>Ron N. wrote: >>>> >>>> >>>>>Joerg wrote: >>>>> >>>>> >>>>>>I still think this job just requires a timer, no fancy math. Unless, of >>>>>>course, all the timers are used up already >>>>> >>>>>He might not even need an explicit timer, as one might be implicit >>>>>in the sample rate of the ADC. Just count X zero crossings per N >>>>>samples at R samples per second and do the very simple arithmetic >>>>>to get the average signal frequency. >>>> >>>>I don't see the need for an ADC at all. Do you mean to use it as a timer >>>>somehow, discarding any samples? >>> >>> >>>Why discard the samples when one can use the ADC as both the >>>signal input and the timer? This might be one possible solution >>>if he has an ADC input with programmable or fixed sample rate, >>>and no other extra sytem timers or analog inputs on the system. >> >>Maybe I'm completely confused. I don't see how to use an ADC as part of >>a way to count the zero crossings in a specific interval of time. I >>assume that there will be enough zero crossings in that interval to make >>interpolating not worth the trouble. > > > Sorry. I was assuming a computer was already involved somewhere > in the OP's system. Then it's an added dozen lines or less of C code. > > If there's no CPU, then it will involve more stuff to extract frequency > from a sequence of samples, than just the sampling ADC.
I'm still confused. If you want to count zero crossings with a computer, how does an ADC help? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> Ron N. wrote: > > Jerry Avins wrote: > > > >>Ron N. wrote: > >> > >>>Jerry Avins wrote: > >>> > >>> > >>>>Ron N. wrote: > >>>> > >>>> > >>>>>Joerg wrote: > >>>>> > >>>>> > >>>>>>I still think this job just requires a timer, no fancy math. Unless, of > >>>>>>course, all the timers are used up already > >>>>> > >>>>>He might not even need an explicit timer, as one might be implicit > >>>>>in the sample rate of the ADC. Just count X zero crossings per N > >>>>>samples at R samples per second and do the very simple arithmetic > >>>>>to get the average signal frequency. > >>>> > >>>>I don't see the need for an ADC at all. Do you mean to use it as a timer > >>>>somehow, discarding any samples? > >>> > >>> > >>>Why discard the samples when one can use the ADC as both the > >>>signal input and the timer? This might be one possible solution > >>>if he has an ADC input with programmable or fixed sample rate, > >>>and no other extra sytem timers or analog inputs on the system. > >> > >>Maybe I'm completely confused. I don't see how to use an ADC as part of > >>a way to count the zero crossings in a specific interval of time. I > >>assume that there will be enough zero crossings in that interval to make > >>interpolating not worth the trouble. > > > > > > Sorry. I was assuming a computer was already involved somewhere > > in the OP's system. Then it's an added dozen lines or less of C code. > > > > If there's no CPU, then it will involve more stuff to extract frequency > > from a sequence of samples, than just the sampling ADC. > > I'm still confused. If you want to count zero crossings with a computer, > how does an ADC help?
It's the only analog input on many computer systems, other than those involving complex protocols such as USB, Firewire, ethernet, etc. e.g. The microphone jack. -- rhn
Hello Ron,


>>I'm still confused. If you want to count zero crossings with a computer, >>how does an ADC help? > > It's the only analog input on many computer systems, other than > those involving complex protocols such as USB, Firewire, ethernet, > etc. e.g. The microphone jack. > >
But for this stuff you don't need an analog input. All you'd have to do is amplify the heck out of the signal and clip at VCC and GND. For an 8kHz signal a single transistor or LV opamp can do that. If it already arrives at logic level all you'd have to do is feed it into a pin. Via a resistor for ESD protection, of course. The other option is a comparator input if available. Regards, Joerg http://www.analogconsultants.com
Joerg wrote:
> >>I'm still confused. If you want to count zero crossings with a computer, > >>how does an ADC help? > > > > It's the only analog input on many computer systems, other than > > those involving complex protocols such as USB, Firewire, ethernet, > > etc. e.g. The microphone jack. > > > But for this stuff you don't need an analog input.
That may be true. But the last few laptop PC's I looked at in the store didn't have any simple digital inputs (other than the keyboard keys). They did have audio inputs though. Wonder how common that situation is getting to be... Don't know if the OP stated whether the capacitive humidity sensor in question has analog or digital outputs, and at what levels. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. wrote:
> Jerry Avins wrote: > >>Ron N. wrote: >> >>>Jerry Avins wrote: >>> >>> >>>>Ron N. wrote: >>>> >>>> >>>>>Jerry Avins wrote: >>>>> >>>>> >>>>> >>>>>>Ron N. wrote: >>>>>> >>>>>> >>>>>> >>>>>>>Joerg wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>>I still think this job just requires a timer, no fancy math. Unless, of >>>>>>>>course, all the timers are used up already >>>>>>> >>>>>>>He might not even need an explicit timer, as one might be implicit >>>>>>>in the sample rate of the ADC. Just count X zero crossings per N >>>>>>>samples at R samples per second and do the very simple arithmetic >>>>>>>to get the average signal frequency. >>>>>> >>>>>>I don't see the need for an ADC at all. Do you mean to use it as a timer >>>>>>somehow, discarding any samples? >>>>> >>>>> >>>>>Why discard the samples when one can use the ADC as both the >>>>>signal input and the timer? This might be one possible solution >>>>>if he has an ADC input with programmable or fixed sample rate, >>>>>and no other extra sytem timers or analog inputs on the system. >>>> >>>>Maybe I'm completely confused. I don't see how to use an ADC as part of >>>>a way to count the zero crossings in a specific interval of time. I >>>>assume that there will be enough zero crossings in that interval to make >>>>interpolating not worth the trouble. >>> >>> >>>Sorry. I was assuming a computer was already involved somewhere >>>in the OP's system. Then it's an added dozen lines or less of C code. >>> >>>If there's no CPU, then it will involve more stuff to extract frequency >>>from a sequence of samples, than just the sampling ADC. >> >>I'm still confused. If you want to count zero crossings with a computer, >>how does an ADC help? > > > It's the only analog input on many computer systems, other than > those involving complex protocols such as USB, Firewire, ethernet, > etc. e.g. The microphone jack.
Then use the ADC as a comparator. Sample as rapidly as practical, and XOR each sample's sign bit with the sign bit from the one before. 1 means a zero crossing happened, 0 not. Count 1s and divide by two because you count both positive- and negative-going crossings that way. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������