myScreen

user Occupation hasn't been added

city Company hasn't been added


  • EmbeddedHW_MX1_pollingComparator

  • Created: Apr 12, 2017

    • view723
    • comment0
    • bookmark0
    • fork0

Description

No description available.

Summary

Program 2:

Description

In this program, use periodic sampling of the Analog Comparator output to sense the input voltage.The comparator takes in an analog voltage and compares it to a reference voltage.If the voltage is higher than the reference it outputs a logic '1' while the inverse results in a logic '0'.Your software should contain a main loop that checks the state of the comparator output to determine the state of the light.This should be done as quickly as possible.The software should count the number of signal edges in one second to determine the input frequency.

The general actions this program should take are shown below.One's program does not need to follow this precise series of actions, and in fact performance improvements may be possible by deviating from them.That said, for this program to be valid it must find its result through periodic sampling (polling) of the Analog Comparator.

General Pseudocode

Main Loop:
Sample the Comparator Output
Increment the counter as applicable to count pulses

1 Second Timer Interrupt Service Routine:
Stop and Reset the Timer
Clear the Timer Interrupt Flag (often handled by MCC generated code)
Calculate and Print the Frequency
Restart the Timer

Hardware Setup and Threshold Setting:The voltage from the sensor can be directly connected to the chosen input pin for the analog comparator.A reference voltage (negative input) is also required.This voltage needs to be variable to set the appropriate threshold for detecting the pulses.A fully automated system could be created using the built-in DAC to set the threshold automatically, but unless one is looking for some extra work, the built-in potentiometer should work well enough.This signal can be routed inside the PIC to one of comparator 2's positive inputs.The negative input can then be used for the sensor signal.

At high frequencies, the potentiometer threshold setting may have a very narrow working range, so use a little patience when setting the threshold.Also note that shielding the sensor from ambient light may widen the working threshold range.

Details


Components:

  • No components added

Tags:

Application:

Type:

Document Support:

- None