mega48a 28 pdip adc channels confused

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

Hi!
I think that ADC channels are wrong numbers in real mega48a chip (28pin pdip).
Instead reading adc0 it read 1,
adc1 - read adc 2,
adc2 - read adc 0.
When I program mega8 with same adc initialization for mega48a, mega8 work read ADC right.

Proteus simulating read adc for mega48a right.

Please help.

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

I read many times on this forum that proteus is not reliable. If you have an MCU that's not acting right, you have to post the code.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

There is a problem indeed !

doc8280.pdf (use search on Atmel website) states:

2.3  Analog MUX errata 
In ATmega48A/88A/168A there is an errata affecting the analog MUXes. When 
migrating from ATmega48/88/168 it must be checked if this errata will affect program 
execution and the documented workaround should be applied.  
See the errata section of the ATmega48A/88A/168A data sheet for details. 

... and that says in doc8271.pdf:

34.1 Errata ATmega48A
The revision letter in this section refers to the revision of the ATmega48A device.
34.1.1 Rev. D
• Analog MUX can be turned off when setting ACME bit
1. Analog MUX can be turned off when setting ACME bit
If the ACME (Analog Comparator Multiplexer Enabled) bit in ADCSRB is set while MUX3 in
ADMUX is '1' (ADMUX[3:0]=1xxx), all MUX'es are turned off until the ACME bit is cleared.
Problem Fix/Workaround
Clear the MUX3 bit before setting the ACME bit.
34.2 Errata ATmega48PA
The revision letter in this section refers to the revision of the ATmega48PA device.
34.2.1 Rev. D
• Analog MUX can be turned off when setting ACME bit
1. Analog MUX can be turned off when setting ACME bit
If the ACME (Analog Comparator Multiplexer Enabled) bit in ADCSRB is set while MUX3 in
ADMUX is '1' (ADMUX[3:0]=1xxx), all MUX'es are turned off until the ACME bit is cleared.
Problem Fix/Workaround
Clear the MUX3 bit before setting the ACME bit.

Good catch, code-by !

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

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

I have read this.
Sorry, I not mentioned that I also have all three timers in PWM mode. Whitout timers ADC channels is right.

void main(void)
{

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
State2=T State1=0 State0=T 
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
PORTC=0x00;
DDRC=0x00;

// Port D initialization
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 31,250 kHz
// Mode: Phase correct PWM top=0xFF
// OC0A output: Inverted PWM
// OC0B output: Disconnected
TCCR0A=0xC1;
TCCR0B=0x04;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 125,000 kHz
// Mode: Ph. correct PWM top=0x03FF
// OC1A output: Inverted
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xC3;
TCCR1B=0x03;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 31,250 kHz
// Mode: Phase correct PWM top=0xFF
// OC2A output: Inverted PWM
// OC2B output: Disconnected
ASSR=0x00;
TCCR2A=0xC1;
TCCR2B=0x06;
TCNT2=0x00;
OCR2A=0x00;
OCR2B=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: Off
// Interrupt on any change on pins PCINT16-23: Off
EICRA=0x00;
EIMSK=0x00;
PCICR=0x00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;

// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0x00;

// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=0x00;

// USART disabled
UCSR0B=0x00;

// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR1=0x00;

// ADC initialization
// ADC Clock frequency: 125,000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: ADC Stopped
// Digital input buffers on ADC0: On, ADC1: On, ADC2: On, ADC3: On
// ADC4: On, ADC5: On
DIDR0=0x00;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;

// SPI disabled
SPCR=0x00;

// TWI disabled
TWCR=0x00;

while (1)
      {            
      read_adc(0x00);
      OCR0A=ADCW>>2;;
      delay_ms(1);
      read_adc(0x01);
      OCR2A=ADCW>>8;
      delay_ms(1);
      read_adc(0x02);
      OCR1AH=ADCW>>2; 
      OCR1AL=ADCW&0x00FF; 
      delay_ms(1);
      }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found that this is Codevision problem.
Thank for help :)