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

square wave input to pic!!!

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







square wave input to pic!!!
PostPosted: Sat Oct 15, 2005 4:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 15, 2005 7:35 am     Reply with quote

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







PostPosted: Sat Oct 15, 2005 7:37 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sat Oct 15, 2005 7:59 pm     Reply with quote

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








PostPosted: Sat Oct 15, 2005 9:05 pm     Reply with quote

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








PostPosted: Sun Oct 16, 2005 5:51 am     Reply with quote

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