Maker Pro
Maker Pro

Square wave to DC level

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi
Thanks for your help.
I forgot to mention thst i only have one pin of the pic available which is the A/D.
I could as you say detect a high and then a low. However would i not need a edge trigger such as capture compare or similar?
I will look into this.
 

Frankchie

Nov 14, 2017
149
Joined
Nov 14, 2017
Messages
149
Hi
Thanks for your help.
I forgot to mention thst i only have one pin of the pic available which is the A/D.
I could as you say detect a high and then a low. However would i not need a edge trigger such as capture compare or similar?
I will look into this.
I don't know much about the PIC, but I don't think you need an external "edge trigger" of any kind. Perhaps you are referring to the PIC's interrupt processing capability, which probably operates on it's own internal edge trigger. However interrupt processing should not be necessary unless the processor is real busy doing other things.

I would think that the A/D pin could be used in a similar way to an input pin. Instead of detecting a simple transition of "1" or "0" you would detect a similar transition by the presence or absence of voltage.

Although the A/D function does have a longer acquisition time than a simple I/O port it should be fast enough to accommodate a 4 khz signal. Again, I don't know much about the PIC so you need to verify this.

Lastly, some processors allow you to reconfigure the A/D port into a simple I/O port. You might check if the PIC can do this.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi
As promised I have attached my schematic and simulation. The simulation is exactly what I am seeing. This gives me a voltage of about 1.45V roughly, which I intend to use to the input of the PIC A/D.

My question was
1. Do I need a voltage follower or will this setup be ok as I have a 220nF capacitor across the output. My concern was that the input impedance of the PIC A/D is 10K source.
2. This is an experiment set-up, is there any way I can reduce the component count. The voltage divider is used to bring the 7V down to an acceptable level to be used for the PIC A/D. The 1N4148 diode has been changed to a schotkky diode, the 220nF and 43K give a sharp enough rise time so that the A/D can be measured after about 10ms.
Any help would be appreciated. I was recommended a LPF low pass filter using a simple RC circuit. I presume I can then remove the diode and 43K and 220nF.

Thanks again.
 

Attachments

  • Peak Detector Circuit.pdf
    10.1 KB · Views: 31
  • simulation.pdf
    17.3 KB · Views: 27

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Why did you open a new thread for this topic?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
  • Is the input high, low, or indeterminate when the input signal is absent?
  • How long from the first edge do you need to know that the signal has returned?
  • How long after the last edge do you need to know that the signal has stopped?
Assuming the answers are something like low, about 10ms, about 10ms, then the following circuit should do the trick:

upload_2018-1-12_21-29-28.png

R2 should be about 100k. It is a "cheap" method of protecting the gate from voltages outside the supply.

D1 can be any diode, a 1N4148 is perfectly suitable.

The circuit will produce a high output as soon as the input goes high, and remain high for 1.1RC seconds. For about 10ms response, use R1 = 1MΩ and C1 = 10nF.

U1 and U2 can be obtained in a single SOT-23-6 package, which along with everything else should be pretty small, especially if you use 0603 or smaller resistors.

edit: oh, and the input impedance of the microcontroller is almost certainly high enough that a buffer should not be required for the circuit you posted above (The 10k figure you quoted is probably a recommended source impedance, not the impedance of the A/D itself). The problem is that it responds quite slowly. If that's OK, then that's OK :)
 
Last edited:

Frankchie

Nov 14, 2017
149
Joined
Nov 14, 2017
Messages
149
Hi
As promised I have attached my schematic and simulation. The simulation is exactly what I am seeing. This gives me a voltage of about 1.45V roughly, which I intend to use to the input of the PIC A/D.

My question was
1. Do I need a voltage follower or will this setup be ok as I have a 220nF capacitor across the output. My concern was that the input impedance of the PIC A/D is 10K source.
2. This is an experiment set-up, is there any way I can reduce the component count. The voltage divider is used to bring the 7V down to an acceptable level to be used for the PIC A/D. The 1N4148 diode has been changed to a schotkky diode, the 220nF and 43K give a sharp enough rise time so that the A/D can be measured after about 10ms.
Any help would be appreciated. I was recommended a LPF low pass filter using a simple RC circuit. I presume I can then remove the diode and 43K and 220nF.

Thanks again.
Relative to my last post where I said the only components required were those to construct a simple voltage divider because the PIC was fast enough to detect the square wave directly with some fairly simple software.

Overnight I realized that you probably should put a diode in series with my proposed simple resistor voltage divider because if your square wave is AC and not pulsating DC (as I assumed) it's probably advisable to protect the A/D input from a negative voltage.

Again, with my solution no low pass filters, peak detection or other fancy circuits are necessary.. Your software simply needs to continuously sample the input for a period of time of at-least than 250 us (micro secs), If a significant voltage is detected on any of those samples the 4 KHZ signal must be present. If you write fairly efficient code the PIC should be fast enough to sample the input many times within 250 us, You should insert some temporary code to verify that you are sampling multiple times during that 250 us period, Simple time-stamped counter logic should be adequate.

I
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi all
I have connected the peak detector circuit (see pdf above) to the PIC A/D.
I monitored the A/D pin but i am not seeing anything. If i disconnect from the PIC i can see the waveform (1.35V pulse signal).
Any ideas why this shoukd be the case.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi all,
I have connected the circuit shown below to the PIC A/D. However instead of seeing a square wave coming in , I get a flat line i.e. 0V
1. Could this be due to impedance of the A/D.
2. If the A/D is not set up correctly (I think it defaults as an input on the PIC) would that cause what I am seeing?
Thanks in advance
 

Attachments

  • Peak Detector Circuit.pdf
    10.1 KB · Views: 38
Top