AVR Analog Comparator Interrupt Problems

Go To Last Post
52 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please let me know that how to use multiple channel interrupt using analog comparator.I make a program but it is reading only Channel 0.

I need to read all seven channels simultaneously.Let assume sevens analog sensors are being connected.

Please refer attached code I made,This program make for only two channels.

#include
#include
int main(void)
{	DDRD|=0x01;			                     
SFIOR  |=  (1<<ACME);                         
ADCSRA &= ~(1<<ADEN);                         
ACSR   &= ~((1<<ACD)
	 |~(1<<ACBG)
         |~(1<<ACIS1)
         |~(1<<ACIS0));
    
	ACSR   |=  (1<<ACIE);
	sei();

	while(1);
}

ISR (ANA_COMP_vect)
{
 
   switch(ADMUX)
   {
   
   case 0x00:
  
   if (ACSR & (1 << ACO)) 	
			PORTD &= ~0x01;	
   else		
			PORTD |= 0x01;	
    
   ADMUX = 0x01;
   break;

  
   
   case 0x01:
  
   if (ACSR & (1 << ACO)) 	
			PORTD &= ~0x01;	
   else		
			PORTD |= 0x01;
    
   ADMUX = 0x00;
   break;

   
   
   default:
   //
   break;
   
   } 
	
	
}

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

Quote:

I need to read all seven channels simultaneously.

You cannot. Only one at a time.

>>If all channels use the same trip level, and >>if<< the application has wide/fast swings on the inputs, >>then<< you could signal-condition the input signals so that the trip point is about the level of a logical high.

Then you could just read the PIN register and process, or use PCINT flags perhaps.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Dear theusch,

Do you mean that I leave ADC channels and but only compare the Vref value with any inputs and set or reset the output?

If,Yes,so this logic is reasonable.

Thank you for giving idea.

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

Vref plays no part if you use logic inputs. Your code only sets/clears the one port bit for both channels. This will give strange results.

Probably what you want is a timer tick that scans the inputs using the analog comparator. You could do this 1000 times a second which for most applications is instantaneous.

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

Kartman wrote:
Vref plays no part if you use logic inputs. Your code only sets/clears the one port bit for both channels. This will give strange results.

Dear I am not using logic input ,the input is now analog but I need to use only multiple channels.

Quote:
Probably what you want is a timer tick that scans the inputs using the analog comparator. You could do this 1000 times a second which for most applications is instantaneous.

Please more clarify above quote.

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

You can only take one analog measurement at a time. It is necessary to wait until one is finished before starting the next. With standard AVR (not XMega), at full 10 bit resolution, you can take 15,000 samples (measurements) per second. Thus, if you measure 5 input channels, you can get 3,000 5-channel measurements per second. This is NOT limited by the MCU clock rate, it is limited by the ADC converter.

You CAN go faster, if you are willing to accept 8-bit resolution or if you can change to XMega (lot faster). Otherwise, you will need an external fast ADC.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

You can only take one analog measurement at a time. It is necessary to wait until one is finished before starting the next. With standard AVR (not XMega), at full 10 bit resolution, you can take 15,000 samples (measurements) per second. Thus, if you measure 5 input channels, you can get 3,000 5-channel measurements per second. This is NOT limited by the MCU clock rate, it is limited by the ADC converter.

You CAN go faster, if you are willing to accept 8-bit resolution or if you can change to XMega (lot faster). Otherwise, you will need an external fast ADC.

But, I am puzzled. The title of this thread is about Comparator Interrupts. Yet, so far, there seems to be nothing about comparators.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Read my tutorial on multitasking.

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

ka7ehk wrote:
But, I am puzzled. The title of this thread is about Comparator Interrupts. Yet, so far, there seems to be nothing about comparators.

Dear ka7ehk,

In reality I need to use comparator with or without interrupt.I have three sensors I want to read all sensors data on LCD.So what should I do for reading three ADC channel but I know that one can read at a time.

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

First it was seven channels simultaneously; now it is apparently three channels sequentially.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
First it was seven channels simultaneously; now it is apparently three channels sequentially.

Dear theusch,

Firstly I was only learning that how channels are handle and now I am applying it, three sensors I have so how to play with them.

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

You say

Quote:
I need to use comparator with or without interrupt
and then you say
Quote:
So what should I do for reading three ADC channel

It does not add up. What is the purpose of "comparator"? Is it that you want to tell if an ADC reading is above or below some set value?

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

No ADC is not necessary,comparator is only concern.

If I set 2.5V on AIN0 and ADC channel 0 reading 2.5V then ACO bit change.This is done very well.But when I select channel 1 then it cannot read anything.Code here.

#include

#include

unsigned char i=0;

void initACOMP (uint8_t multiplex, uint8_t channel) { 
if(multiplex) { 
ADCSRA &= ~(1<<ADEN);
SFIOR |= (1 << ACME); 

ADMUX = channel & 0x07; 
    }
    ACSR = 0x00; 
}




void switchChannel (uint8_t channel) { 

ADMUX = channel & 0x07; 
__asm ("NOP"); 
__asm ("NOP");
}

uint8_t getACOMP (void) {
    return ((ACSR >> ACO) & 1);  

}

int main(void)
{
   
	initACOMP(1,0);  
 
 	DDRD   |= 0x01;			                      

	while(1)
	{
	        
            switchChannel(1);		   
		    i=getACOMP(); 	
		    
			if(i==1)
			  PORTD &= ~0x01;	
            else		
			  PORTD |= 0x01;
       	
	}}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
and then you say,So what should I do for reading three ADC channel

Dear ka7ehk,

It means Comparator uses ADC channel instead of AIN1 pin when set ACME in SFIOR.

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

Quote:

But when I select channel 1 then it cannot read anything.Code here.

Quote:

ADMUX = channel & 0x07;

What do you expect? Tell me how your code will ever switch from an ADMUX value of 1 to an ADMUX value of 0?

What must you do after changing channels? Clear the "hit" flag(s) from the previous configuration perhaps?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

ka7ehk wrote:
It does not add up. What is the purpose of "comparator"? Is it that you want to tell if an ADC reading is above or below some set value?

Actually as you can read in the datasheet:
Quote:
It is possible to select any of the ADC13..0 pins to replace the negative input to the Analog Comparator.

And I this is most likely what the OP is trying to do.
BUT
it also says:
Quote:
Analog Comparator Multiplexed Input

And multiplexed means, only one can be selected at a time. In other words, what you're trying to do is impossible. You can read from only one output because there's only one Analog Comparator.

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

OK, imranahmed needs to be aware of potential interrupt triggers just from changing ADMUX. Best way is to change ADMUX, wait a bit (a few clocks, maybe), then test (poll) the state of the comparator output bit. Interrupts are NOT a good way to go, here.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Quote:
void switchChannel (uint8_t channel) {

ADMUX = channel & 0x07;
__asm ("NOP");
__asm ("NOP");
}

Dear theusch,

When switchChannel function reads channel=0
00000000
00000111
=========&
00000000 = ADMUX

and it reads channel=1

00000001
00000111
=========&
00000001 = ADMUX

and so on.
But he cannot do this.

Last Edited: Sun. Feb 2, 2014 - 09:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear to all ,

Please understand my code what do I want.

I am not being clearly saying....

I know there is one comparator and one task can perform at a time.

But Ok you tell me how to read three or four sensors,
all sensors result shows in the form LED on and off.

If 1st sensors value and Vref value match then LED 1 on and this also for sensor two and three LED 2 and LED 3 should on and off.

Last Edited: Thu. Feb 6, 2014 - 02:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

imranahmed wrote:
But Ok you tell me how to read three or four sensors,
all sensors result shows in the form LED on and off.

// disable ADC
// enable comparator
// set ACME

//  for each MUX you wish to monitor {
//    write MUX to ADMUX
//    select the appropriate +ve source for this MUX
//    wait an interval for comparator to settle
//    if ACO is set {
//      set appropriate LED
//    }
//    else {
//      clear appropriate LED
//    }
//  }

Note that you can only test against at most 2 thresholds, Vbg or the voltage present on AIN0.

This can be driven by a timer interrupt in order to free up main(), but the analog comparator interrupt itself need not be involved.

EDIT: You haven't mentioned which device you're using, but based on your code it could be the ATmega8/16/32/64/128/A or the ATmega8535... /EDIT

The 'wait an interval' need not be very long, or may not be needed at all. The datasheet for the ATmega8A shows that the analog comparator has a propogation delay of 750 ns at Vcc==2.7V. At 16 Mhz that amounts to 12 clock cycles. It would probably be safe to ensure the minum delay between switching MUX and testing ACO with a call to _delay_us(1).

Note that if you switch between AIN0 and Vbg, you need to allow additional time for Vbg to settle, typically 40-70 μs.

Note also that in this setup, ACO will be set when the voltage on the configured MUX is lower than the voltage on AIN0 (or Vbg if ACBG is set).

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Quote:

The datasheet for the ATmega8A

Quote:

Actually as you can read in the datasheet:
Quote:
It is possible to select any of the ADC13..0

I've just gone through the thread again--do we know what AVR model might be involved here?

Is ACO available on all AVR models? Or does one need to e.g. read it "indirectly" via ACI?

Re ACO delay--propagation may be in ns, but the datasheet hints at "a few cycles"...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
I've just gone through the thread again--do we know what AVR model might be involved here?
We do not.

EDIT: but previous threads by the OP spoke of an ATmega8 /EDIT

However, searching the header files for SFR referenced by the OP:

$ cd [toolchain]/avr/include/avr
$ grep -rl SFIOR . | xargs -I "{}" grep -l ACSR "{}" | xargs -I "{}" grep -l ADCSRA "{}" | xargs -I "{}" grep -l DDRD "{}" | sort
./iom128a.h
./iom128.h
./iom16a.h
./iom16.h
./iom32a.h
./iom32.h
./iom64a.h
./iom64.h
./iom8535.h
./iom8a.h
./iom8.h

Quote:
Is ACO available on all AVR models? Or does one need to e.g. read it "indirectly" via ACI?
I don't think there are any such (currently supported?) devices:
$ grep -rl ACI . | xargs -I "{}" grep -L ACO "{}" | sort
./iom16hva2.h
./iom16hvb.h
./iom16hvbrevb.h
./iom32hvb.h
./iom32hvbrevb.h
./iom406.h
./iom64hve2.h
./iom64hve.h
./iomxxhva.h

... but a look at a few datasheets reveals that they don't sport a comparator (the matches were due to other strings like CADACIE). We must wait for his answer :)

Quote:
Re ACO delay--propagation may be in ns, but the datasheet hints at "a few cycles"...
Which datasheet?

Perhaps you're referring to the synchronisation delay for digital I/O? That's usually between 0.5 and 1.5 cycles:

Quote:
As indicated by the two arrows tpd,max and tpd,min, a single signal transition on the pin will be delayed between 1⁄2 and 1-1⁄2 system clock period depending upon the time of assertion.

When reading back a software assigned pin value, a nop instruction must be inserted as indicated in Figure 12-4. The out instruction sets the “SYNC LATCH” signal at the positive edge of the clock. In this case, the delay tpd through the synchronizer is 1 system clock period.

AFAIK this doesn't apply to the analog comparator.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Quote:

Which datasheet?

Description of ACO seems similar in a few current datasheets:
Quote:
• Bit 5 – ACO: Analog Comparator Output
The output of the Analog Comparatoris synchronized and then directly connected to ACO. The synchronization introduces a delay of 1 - 2 clock cycles.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include
#include
unsigned char i;

int main(void)
{
    DDRD   |= 0x01;   

    ADCSRA &= ~(1<<ADEN); // disable ADC 
	ACSR    = 0x00;       // enable comparator 
	SFIOR  |= (1 << ACME);// set ACME 
    i=1;    
 				                      
    
	while(1)
	{
	        
       	
	   	    if(i==1) //  for each MUX you wish to monitor
            {       
            ADMUX = i; //write MUX to ADMUX 

		// ???   select the appropriate +ve source for this MUX 
			
			_delay_us(1);  //wait an interval for comparator to settle
			if(((ACSR >> ACO) & 1))
			  PORTD &= ~0x01;	
            else		
			  PORTD |= 0x01;
        	
	         }
}
}

Please find attached code ,it is not selecting channel 1 but only read channel 0.

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

theusch wrote:
Description of ACO seems similar in a few current datasheets:
[cleans glasses] Ah yes, rah-thah!

The 48/88/168/328 datasheet (haven't checked others) still lists the propagation delay as 750 ns at 2.7 V and 500 ns at 5 V. I imagine one must add both this delay and the synchronisation delay... different for different Fcpu...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

imranahmed wrote:
it is not selecting channel 1 but only read channel 0.
Strange. Your code seems fine. I'm probably missing something obvious.

BTW the delay I proposed would only be necessary when switching MUX, it's not necessary here (though it won't harm).

You still haven't told us what AVR you are using. Is it the ATmega8?

Also, post the .lss

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Quote:

Strange. Your code seems fine. I'm probably missing something obvious.

Well, we don't know the wiring or what levels are connected to what when this repetitive "test" is being made. Is OP pulling ADC1 up and down, and no change on the LED? Is AVcc and (A)Gnd hooked up? What is on AIN0? (or would it be AIN1 in this situation)?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Sorry

ATmega8 at 8MHz internal oscillator.
AVR Studio 4.

EDIT: Please see attached pictures when I connect channel 0 to input the LED on and comparator accurately makes comparison. SEE When ADC0 reads and When ADC1 reads in the pictures.
When i connect channel 1 he cannot reads also I program it with channel 1.

Attachment(s): 

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

Please let me know that what is the purpose of .lss file.


Over-Volt-Protect.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000096  00000000  00000000  00000094  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00800060  00000096  0000012a  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000001  00800060  00800060  0000012a  2**0
                  ALLOC
  3 .stab         000006cc  00000000  00000000  0000012c  2**2
                  CONTENTS, READONLY, DEBUGGING
  4 .stabstr      00000085  00000000  00000000  000007f8  2**0
                  CONTENTS, READONLY, DEBUGGING
  5 .debug_aranges 00000080  00000000  00000000  00000880  2**3
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_info   000003d3  00000000  00000000  00000900  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_abbrev 00000124  00000000  00000000  00000cd3  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_line   000002d9  00000000  00000000  00000df7  2**0
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_frame  00000024  00000000  00000000  000010d0  2**2
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_str    000000f9  00000000  00000000  000010f4  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_loc    00000044  00000000  00000000  000011ed  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_ranges 00000010  00000000  00000000  00001231  2**0
                  CONTENTS, READONLY, DEBUGGING

Disassembly of section .text:

00000000 <__vectors>:
   0:	12 c0       	rjmp	.+36     	; 0x26 <__ctors_end>
   2:	2c c0       	rjmp	.+88     	; 0x5c <__bad_interrupt>
   4:	2b c0       	rjmp	.+86     	; 0x5c <__bad_interrupt>
   6:	2a c0       	rjmp	.+84     	; 0x5c <__bad_interrupt>
   8:	29 c0       	rjmp	.+82     	; 0x5c <__bad_interrupt>
   a:	28 c0       	rjmp	.+80     	; 0x5c <__bad_interrupt>
   c:	27 c0       	rjmp	.+78     	; 0x5c <__bad_interrupt>
   e:	26 c0       	rjmp	.+76     	; 0x5c <__bad_interrupt>
  10:	25 c0       	rjmp	.+74     	; 0x5c <__bad_interrupt>
  12:	24 c0       	rjmp	.+72     	; 0x5c <__bad_interrupt>
  14:	23 c0       	rjmp	.+70     	; 0x5c <__bad_interrupt>
  16:	22 c0       	rjmp	.+68     	; 0x5c <__bad_interrupt>
  18:	21 c0       	rjmp	.+66     	; 0x5c <__bad_interrupt>
  1a:	20 c0       	rjmp	.+64     	; 0x5c <__bad_interrupt>
  1c:	1f c0       	rjmp	.+62     	; 0x5c <__bad_interrupt>
  1e:	1e c0       	rjmp	.+60     	; 0x5c <__bad_interrupt>
  20:	1d c0       	rjmp	.+58     	; 0x5c <__bad_interrupt>
  22:	1c c0       	rjmp	.+56     	; 0x5c <__bad_interrupt>
  24:	1b c0       	rjmp	.+54     	; 0x5c <__bad_interrupt>

00000026 <__ctors_end>:
  26:	11 24       	eor	r1, r1
  28:	1f be       	out	0x3f, r1	; 63
  2a:	cf e5       	ldi	r28, 0x5F	; 95
  2c:	d4 e0       	ldi	r29, 0x04	; 4
  2e:	de bf       	out	0x3e, r29	; 62
  30:	cd bf       	out	0x3d, r28	; 61

00000032 <__do_copy_data>:
  32:	10 e0       	ldi	r17, 0x00	; 0
  34:	a0 e6       	ldi	r26, 0x60	; 96
  36:	b0 e0       	ldi	r27, 0x00	; 0
  38:	e6 e9       	ldi	r30, 0x96	; 150
  3a:	f0 e0       	ldi	r31, 0x00	; 0
  3c:	02 c0       	rjmp	.+4      	; 0x42 <__SREG__+0x3>
  3e:	05 90       	lpm	r0, Z+
  40:	0d 92       	st	X+, r0
  42:	a0 36       	cpi	r26, 0x60	; 96
  44:	b1 07       	cpc	r27, r17
  46:	d9 f7       	brne	.-10     	; 0x3e <__SP_H__>

00000048 <__do_clear_bss>:
  48:	10 e0       	ldi	r17, 0x00	; 0
  4a:	a0 e6       	ldi	r26, 0x60	; 96
  4c:	b0 e0       	ldi	r27, 0x00	; 0
  4e:	01 c0       	rjmp	.+2      	; 0x52 <.do_clear_bss_start>

00000050 <.do_clear_bss_loop>:
  50:	1d 92       	st	X+, r1

00000052 <.do_clear_bss_start>:
  52:	a1 36       	cpi	r26, 0x61	; 97
  54:	b1 07       	cpc	r27, r17
  56:	e1 f7       	brne	.-8      	; 0x50 <.do_clear_bss_loop>
  58:	02 d0       	rcall	.+4      	; 0x5e 
5a: 1b c0 rjmp .+54 ; 0x92 <_exit> 0000005c <__bad_interrupt>: 5c: d1 cf rjmp .-94 ; 0x0 <__vectors> 0000005e
: #include unsigned char i; int main(void) { DDRD |= 0x01; 5e: 88 9a sbi 0x11, 0 ; 17 ADCSRA &= ~(1<<ADEN); // disable ADC 60: 37 98 cbi 0x06, 7 ; 6 ACSR = 0x00; // enable comparator 62: 18 b8 out 0x08, r1 ; 8 SFIOR |= (1 << ACME);// set ACME 64: 80 b7 in r24, 0x30 ; 48 66: 88 60 ori r24, 0x08 ; 8 68: 80 bf out 0x30, r24 ; 48 i=1; 6a: 81 e0 ldi r24, 0x01 ; 1 6c: 80 93 60 00 sts 0x0060, r24 while(1) { if(i==1) // for each MUX you wish to monitor 70: 80 91 60 00 lds r24, 0x0060 74: 81 30 cpi r24, 0x01 ; 1 76: 61 f4 brne .+24 ; 0x90 { ADMUX = i; 78: 87 b9 out 0x07, r24 ; 7 #else //round up by default __ticks_dc = (uint32_t)(ceil(fabs(__tmp))); #endif __builtin_avr_delay_cycles(__ticks_dc); 7a: 82 e0 ldi r24, 0x02 ; 2 7c: 8a 95 dec r24 7e: f1 f7 brne .-4 ; 0x7c 80: 00 c0 rjmp .+0 ; 0x82 _delay_us(1); if(((ACSR >> ACO) & 1)) 82: 88 b1 in r24, 0x08 ; 8 84: 85 ff sbrs r24, 5 86: 02 c0 rjmp .+4 ; 0x8c PORTD &= ~0x01; 88: 90 98 cbi 0x12, 0 ; 18 8a: f2 cf rjmp .-28 ; 0x70 else PORTD |= 0x01; 8c: 90 9a sbi 0x12, 0 ; 18 8e: f0 cf rjmp .-32 ; 0x70 90: ff cf rjmp .-2 ; 0x90 00000092 <_exit>: 92: f8 94 cli 00000094 <__stop_program>: 94: ff cf rjmp .-2 ; 0x94 <__stop_program>
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is this a real device or another simulation?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Well it works for me (tested with a mega8, not simulated).
/Lars

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

Simulation on proteus.

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

imranahmed wrote:
Simulation on proteus.
And what have you been told in all of your other threads where you had problems with proteus? (I linked one above)

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Lajon wrote:
Well it works for me (tested with a mega8, not simulated).
/Lars

Please kindly attach its simulation.

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

I have no problem with proteus now but problem is
ADMUX =0x01; is not selected.

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

Quote:

Please kindly attach its simulation.


lol--why trust a simulation, when it works on real hardware?

Perhaps you should ask Proteus--after all, you paid for support with your license fee.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Ok please provide me link for proteus bugless version.

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

Maybe some missunderstanding, I did NOT simulate it, I have run the program above exactly as it is using a real mega8 and it works fine.
/Lars

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

imranahmed wrote:
Ok please provide me link for proteus bugless version.
It's available for download from the same place you can get a bugless version of Windows.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

imranahmed wrote:
Ok please provide me link for proteus bugless version.

What is a Proteus bugless version? Do you have a license that allows you to use Proteus?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

joeymorin wrote:
imranahmed wrote:
Ok please provide me link for proteus bugless version.
It's available for download from the same place you can get a bugless version of Windows.
Or a bugless version of Linux. lol

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Lajon wrote:
Maybe some missunderstanding, I did NOT simulate it, I have run the program above exactly as it is using a real mega8 and it works fine.
/Lars

Ok,

Please Lajon check one thing that change channels one-by-one and observe that all channels can reads or only channel 0 is working.

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

larryvc wrote:
Or a bugless version of Linux. lol
Indeed ;)

From an article by Andrew S. Tanenbaum (my emphasis):

Quote:
Current operating systems have two characteristics that make them unreliable and insecure: They are huge and they have very poor fault isolation. The Linux kernel has more than 2.5 million lines of code; the Windows XP kernel is more than twice as large.

One study of software reliability showed that code contains between six and 16 bugs per 1,000 lines of executable code, (1) while another study put the fault density at two to 75 bugs per 1,000 lines of executable code, (2) depending on module size. Using a conservative estimate of six bugs per 1,000 lines of code, the Linux kernel probably has something like 15,000 bugs; Windows XP has at least double that.

To make matters worse, typically, about 70 percent of the operating system consists of device drivers, which have error rates three to seven times higher than ordinary code, (3) so the bug counts cited above are probably gross underestimates. Clearly, finding and correcting all these bugs is simply not feasible; furthermore, bug fixes frequently introduce new bugs.

He also presented at FOSDEM 2010.

Another interesting quote (from a Wikipedia entry):

Quote:
NASA's SATC managed to reduce the number of errors to fewer than 0.1 per 1000 lines of code (SLOC) but this was not felt to be feasible for projects in the business world.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

How to buy Proteus?

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

imranahmed wrote:
How to buy Proteus?
[:facepalm:]

http://www.labcenter.com

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

larryvc wrote:
Or a bugless version of Linux. lol
I... I couldn't resist... please forgive me ;)

From Ganssle's jokes archive:

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Just joke I am not worry.

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

Yeah. A long time ago I also trusted simulators... :D

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

imranahmed wrote:

Please Lajon check one thing that change channels one-by-one and observe that all channels can reads or only channel 0 is working.

Yes it worked, i tried channel 0 and 1. One thing to note is you can not expect reasonable results (in the real world) if you have inputs floating (like in your pictures when the switch is not active).

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

Quote:
Yes it worked, i tried channel 0 and 1. One thing to note is you can not expect reasonable results (in the real world) if you have inputs floating (like in your pictures when the switch is not active).

Dear Lajon,

In the picture I connected switch to channel 0 and channel 1 because ,if ADC0 input needed to read,it would active and if ADC1 input needed to read,so it would active.

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

imranahmed wrote:
if ADC0 input needed to read,it would active and if ADC1 input needed to read,so it would active.

That's not the point. I guess what he's talking about is that the noise from unconnected inputs may affect the other inputs. I remember I've had a problem with that the first time I was learning to use ADC.

Pages