View previous topic :: View next topic |
Author |
Message |
ambivalent Guest
|
square wave input to pic!!! |
Posted: Sat Oct 15, 2005 4:06 am |
|
|
hi everyone.
i want to apply a square wave input (0 -> 12v) to PIC 16f877a. i will then detect the no of waves per second. i have two questions:
1. should i just apply this 12 volts square wave directly to PIC and use A/D to determine when 12volts are present on a pin to keep count of no of pulses per second, or should i reduce the voltage to 5v through a variable resistor and then apply it to the pin and forgo the whole A/D procedure.
2. to count the no of square pulses per second, i will have to use timers, or is there a better way of doing this.
Best regards |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Oct 15, 2005 7:35 am |
|
|
Do not run a 12V signal straight into any PIC pin whether it is an A/D input or not! You run a good chance of damaging the PIC.
If all you want to do is measure the frequency and you don't care about amplitude you do not need to use an A/D. Read Microchip App note AN521 for info on extracting timing data from high voltage waveforms. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Ttelmah Guest
|
|
Posted: Sat Oct 15, 2005 7:37 am |
|
|
Reduce it to 5v. Otherwise, exit one PIC...
The 'best' method of generating the input, is probably to use an external comparator, with some hysteresis present, to give a clean square wave (otherwise you are likely to have problems if there is any noise on the signal), and then feed the signal into a timer or CTC.
How you use this, depends on the frequency involved. if the frequency is high, directly count the signal with a timer module. Otherwise, if you use the CTC in 'capture' mode, to count the clocks on the internal oscillator, between the signal edges, this gives a value directly related to the period (reciprocal of frequency). At low frequencies this will give much better accuracy.
Best Wishes |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sat Oct 15, 2005 7:59 pm |
|
|
If your 0-12V input is just a square wave with a little noise, you might get away without a comparator. I think this topology will work for:
Code: |
12V input ---
|
|
\
/
\ 1k - 10k
/ -----------------
\ |
/ |
| |
| |
|------------------------------------| digital input on a PIC
| |
| |
| -----------------
--- 4.7V 0r 5.1V zener diode |
/\ |
| |
| |
| |
| |
\/ GND \/ GND
|
|
|
|
Guest
|
|
Posted: Sat Oct 15, 2005 9:05 pm |
|
|
kender wrote: | If your 0-12V input is just a square wave with a little noise, you might get away without a comparator. I think this topology will work for:
Code: |
____ +V for PIC
12V input --- |
| |
| _|_ Diode
\ /\
/ |
\ 1k - 10k |
/ | -----------------
\ | |
/ | |
| | |
| | |
|------------------------------------| digital input on a PIC
|
|
-----------------
|
|
|
\/ GND
|
|
Clamp the input to Vdd. using a simple 1N4148 |
|
|
Guest
|
|
Posted: Sun Oct 16, 2005 5:51 am |
|
|
Both the Zener method and diode to VCC are viable solutions.
For the zener method I would use a 4.7volt zener.
The diode to VCC method injects current into the VCC supply of the circuit. This would not normally be a problem however you will need to ensure that this does not compromise the regulation characteristics of the power supply circuitry in your design. |
|
|
|