Analog comparator in Atmega1608

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hi All,

I am trying to use Internal Analog Comparator in ATmega1608 and have been facing some issues in configuring it. I am using PD2 as positive input pin and PD3 as Negative input pin. To configure it, I initialized those pins as input using DIRCLR and disabled digital input buffer for both pins according to the Application note from Microchip? is it the right way to initialize those pins? I am attaching my pin initializing snippet below, please take a look.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does it work? If yes, then it is probably configured operationally if not optimally.  As long as the signals on the input pins are not greater than Vcc, then you should not be able to physically harm the chip.

 

Often one of the comparator inputs is set to a fixed voltage between Vcc and Ground with two resistors and the other input gets a variable voltage.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Does it work?

  It does not work as expected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sanka1p wrote:

It does not work as expected.

 

What did you expect? What did you observe?

 

Post a minimal but compileable piece of code that exhibits the odd behaviour so we can test.

 

Posting images of code will get you less help.

Posting incomplete code will get you less help.

Making the rest of us play 20 questions will get you less help.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

balisong42 wrote:

Sanka1p wrote:

It does not work as expected.

 

What did you expect? What did you observe?

 

Post a minimal but compileable piece of code that exhibits the odd behaviour so we can test.

 

Posting images of code will get you less help.

Posting incomplete code will get you less help.

Making the rest of us play 20 questions will get you less help.

 

 

okay, so here is my Analog comparator initialization program.

 

 

 // ***** PORTA pin 7 as output for  AC  ***** //
  PORTA.DIRSET=  PIN7_bm;

 

  //***** PORTD pin 2 and 3 as input ***** //  
  PORTD.DIRCLR= PIN2_bm | PIN3_bm;
 
  // ****** Positive Input - Disable digital input buffer ****** //
  PORTD.PIN2CTRL=PORT_ISC_INPUT_DISABLE_gc;
 
  // ****** Negative Input - Disable digital input buffer ****** //
  PORTD.PIN3CTRL=PORT_ISC_INPUT_DISABLE_gc;

 

  // ***** selecting AINP0 and AINN0 for comparator inputs ***** //
  AC0.MUXCTRLA=  AC_MUXPOS0_bm | AC_MUXNEG0_bm;   
 
  // ***** starting Analog comparator, small hysterisis and having its output on pin 1***** //
  AC0.CTRLA= AC_OUTEN_bm | AC_HYSMODE0_bm | AC_ENABLE_bm;  
 

Last Edited: Fri. Aug 5, 2022 - 07:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't you think you should say what the two comparator input voltages are (and verified with a meter)...and what you see at the output when you apply them and change them?

Do you know for sure this code is actually running (such as turning on an led after it executes)?

Once in a while you may find some code isn't even being touched for various reasons, and a lot of time was wasted.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Aug 5, 2022 - 07:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Don't you think you should say what the two comparator input voltages are (and verified with a meter)...and what you see at the output when you apply them and reverse them?

I was looking at the output of AC at pin1 of MCU and looked at both the inputs on scope simultaneous . The AC is giving output even though both the input signals are not crossing. And the difference between the input crossing and output is significant i.e. 6us.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

 

Do you know for sure this code is actually running (such as turning on an led after it executes)?

Once in a while you may find some code isn't even being touched for various reasons, and a lot of time was wasted.

  As I said, I can see the output on Pin1 of MCU.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't you think you should say what the two comparator input voltages are

 

4V ?  1.34V?  200V?  why can't you answer questions 

 

The AC is giving output

What does that mean?  Since it is an output pin it will always have some level.  You say it doesn't change, but it has an output??

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Aug 5, 2022 - 07:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Don't you think you should say what the two comparator input voltages are

 

4V ?  1.34V?  200V?  why can't you answer questions 

  The two voltage swing between 4v and 1.3v

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AC is giving output even though both the input signals are not crossing.

What??? it is an output pin, so this statement doesn't make much sense

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

The AC is giving output even though both the input signals are not crossing.

What??? it is an output pin, so this statement doesn't make much sense

By output I mean toggling output.