Actually I am generating square wave using PIC12f675 from one GPIO port, but want to detect that square wave using other pin on GPIO port, how can we do that? I have succeeded by using TMR0 to use as a counter. My application is to develop water level controller so generating square wave to avoid corrosion of sensors.
-
1Why are you trying to detect it from within the same processor? Is it for some kind of self-test purpose? Will the output be looped back? – user57037 Jan 29 '15 at 04:47
-
Actually I a trying to make water level controller, and I have heard that if we apply high frequency pulse then the corrosion to sensors is avoided. So I am generating square wave from one pin and then detect it from different sensors. So I am having problem regarding detection using GPIO port pin. its easy to detect single logic level using input pin by using pull/down resistor or detect using TMR0 as a counter. But as there are multiple sensors, detecting it with only one TMR0 is hard. So basically I want to simulate software TMR0. – MrAlpha_SU Jan 29 '15 at 09:28
-
You may find [this answer](http://electronics.stackexchange.com/a/77005/25328) useful. – Tut Jan 29 '15 at 12:59
1 Answers
To detect the waveform you need to use the feedback copy of the square wave to enable a timer channel to count. The timer channel would need to be setup to clock on some internal frequency that is properly selected to give a reasonable number of counts per square wave but not so many that the counter overflows. Most MCU timer channels have a selectable pre-scaler that can be used to get the clocking into the correct range.
There are several styles of timer mechanisms that can be used based upon the type of MCU in use.
One style uses the input square wave as an enable gate to the timer so it can count while the gate is open. When the gate closes the software checks if number of counts in the counter matches with expected gate pulse width. This scheme is generally used to capture the count for a half cycle of the input square wave.
The other style has the timer free running all the time. Then the edge of the square wave signal is used (often referred to as an Input Capture) to latch the current count of the free running timer into a holding register. Software saves away the capture register value just after the capture time. The software then gets ready for the next capture event. This may consist of enabling the input capture to operate on the opposite edge of the input square wave signal. After the next capture the software subtracts the two capture values to deduce how many time ticks happened between the input edges. If the input edge is toggled each time then you are measuring alternately the high period of the input waveform and then the low period. If the same edge is used each capture then you are measuring the period of the square wave.

- 56,889
- 3
- 70
- 138
-
Thank you for your solution. But using above solution I can only measure single signal. I wanted to make automatic water level controller so in it there are various sensors. So how can I detect with one register? And I don't want to count just need to detect. – MrAlpha_SU Jan 29 '15 at 09:39
-
Thank you for help! I have succeeded. I have completed it. I have implemented one software counter in program and incremented that counter on every falling edge of signal and done. Thank you for your help. – MrAlpha_SU Jan 29 '15 at 11:49