Instructions
226Libraries
© 2013 Conrad Electronic
// Mega32: Input (+) PB2 (PortB.2) bzw. band gap reference 1,22V
// Input (-) PB3 (PortB.3)
// Mega128: Input (+) PE2 (PortE.2) bzw. band gap reference 1,22V
// Input (-) PE3 (PortE.3)
// used Library: IntFunc_Lib.cc
// The function AComp returns the value of the comparator.
// If the voltage on input PB2/PE2 is greater than the input PB3/PE3 the
// function AComp returns the value 1.
// Mode:
// 0x00 external inputs (+)AIN0 and (-)AIN1 are used
// 0x40 external input (-)AIN1 and the internal reference voltage are used
// 0x80 the Analog-Comparator is disabled
// In this example you can call AComp with parameter 0 (both inputs are used)
// or with 0x40 (int. reference voltage on (+) input, external Input PB3/PE3)
//------------------------------------------------------------------------------
// main program
//
void main(void)
{
while (true)
{
if (AComp(0x40)==1) // Input (+) band gap reference 1,22V
{
Msg_WriteChar('1'); // Output: 1
}
else
{
Msg_WriteChar('0'); // Output: 0
}
// the comparator value is read all 500ms
AbsDelay(500);
}
}
5.3.2 AVR32Bit
The Analog Comparator allows to compare two analog signals. The result of this comparison is returned
as either "0" or "1". Voltages of between 0 and 3.3V can be compared at the positive and negative inputs.