View previous topic :: View next topic |
Author |
Message |
Frank-Y
Joined: 16 Jun 2021 Posts: 3
|
Sample and Hold |
Posted: Wed Jun 16, 2021 2:34 am |
|
|
Hi everyone, I'm new to C programing and embedded systems. I have a task that I would like help with if anyone can help please!
I want to know how to sample and hold an analogue 43khz signal, 7.6 pk-pk, 2.8 amplitude and monitor it until it changes, maybe store the A/D reading in an array. If it goes out of range to change the signal back into the 43khz signal. Also, be able to display this on a lcd screen.
I'm using a PIC16f1519 at 40MHZ clock frequency.
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Jun 16, 2021 4:05 am |
|
|
It is going to be very hard to do this with the PIC you are suggesting.
In fact impossible.
A signal at 43KHz, would require sampling at least at 86000 times per
second. So sampling at just 12uSec. The ADC in the PIC you are talking
about cannot do this. It takes 12uSec minimum for a complete conversion,
and then requires just on 4.5uSec acquisition time to reload the internal
sample and hold. So a fastest possible sample rate of about 60KHz.
So this ADC cannot do the sampling at the rate you would need. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jun 16, 2021 4:44 am |
|
|
re: Quote: | If it goes out of range... |
Hmm, what goes 'out of range' ? The frequency (43KHz) or the amplitude (2.8). Amplitude is always changing....though the frequency should be stable.
You can measure the frequency, once you have a 0-5V DC wave.
There's the 'analog' problem. You've got an AC signal but the PIC (generally all PICs) ONLY measure a DC signal, 0 to almost Vdd. You'll have to convert the AC signal into a DC signal but as Mr T points out, there's no time for that to happen.
More information of what you're trying to do may allow us to decide a possible solution.
Jay |
|
|
Frank-Y
Joined: 16 Jun 2021 Posts: 3
|
|
Posted: Wed Jun 30, 2021 8:08 am |
|
|
Thank you all for your replies, being new on here I did not even receive any notification on both of your replies. My apologies
What I'm trying to do is monitor an input ac signal of 43khz frequency and use the PIC to store this value, and if the frequency changes to recognise this change and restore the signal back to 43khz. However, I do understand that I need to convert the AC signal before going any further with anything else. That is why I thought to use the Pic's A/D converter along with the Sample and Hold option would be the best approach to tackle this issue. Convert the AC into a DC value and store it and start the monitoring process.
I guess where I should've started is by asking how and what is the best approach to solve this issue.
If I have understood it properly, do I need to review the ADC acquisition section on the data sheet and find a PIC with a sampling rate of 86000 per second?
Thanks again. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jun 30, 2021 8:19 am |
|
|
I would not use the ADC section of the PIC, way too slow...
I'd convert the 43KHz signal (I'm assuming sine wave ?) to digital with good clean edges. Then use CCP/timer as a 'period counter'. PICs can easily measure the 'time high, time low' of a square wave (think 'frequency counter' or 'tachometer'. Which PIC depends upon other 'things' you need it to do, but nearly all PICs can do this. It's probably easier to calculate 'period', others will know and can help with 'details'.
Once you have the # of bits to represent 43KHz, any deviation (+ or -) can then be used to 'adjust' the 43KHz generator. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Jun 30, 2021 3:36 pm |
|
|
As Jay has said, "rail" the signal with a comparator or similar and use the CCP to measure its frequency. At 43kHz, with a 64MHz clock, an 8 bit PIC will achieve a 16MHz master clock frequency. That's about 372 instructions per cycle - there's very little chance that the PIC would manage using an analog approach. Much better to let a peripheral such as the CCP manage the task with a little signal conditioning to help things along. |
|
|
Frank-Y
Joined: 16 Jun 2021 Posts: 3
|
Sample and Hold |
Posted: Tue Jul 06, 2021 1:45 am |
|
|
Thank you all, for some real constructive advice everyone! |
|
|
|