| Author |
Message |
|
|
Posted: Dec 25, 2008 - 08:19 AM |
|

Joined: Nov 12, 2004
Posts: 5
|
|
Hi every
Can somebody show me the simplest way to use adc and print the result to the uart or the LCD
I use code vision with an atmega32
thx
merry christmas ! |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 09:58 AM |
|

Joined: Dec 25, 2008
Posts: 6
|
|
| is the LCD alreday working, do u have a connection, according to the one from the code wizard? |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 11:05 AM |
|

Joined: Feb 12, 2005
Posts: 16547
Location: Wormshill, England
|
|
go to the examples directory of CVAVR. Use the code from there. Read the Help section for how to use the ADC.
David. |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 01:14 PM |
|

Joined: Nov 12, 2004
Posts: 5
|
|
|
mbuchman wrote:
is the LCD alreday working, do u have a connection, according to the one from the code wizard?
Yes LCD is working an Uart too , but i can't send the result of adc to them... probably a bad variable declaration .... |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 01:46 PM |
|

Joined: Dec 25, 2008
Posts: 6
|
|
| ok if u got a connection to the uc, it should not be a big issue - can u post your sourcecode here? and schematics? |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 02:43 PM |
|

Joined: Nov 12, 2004
Posts: 5
|
|
|
mbuchman wrote:
ok if u got a connection to the uc, it should not be a big issue - can u post your sourcecode here? and schematics?
Here is the code
(Don't make fun of me i'm beginner in C lol )
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.8a Evaluation
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 24/12/2008
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega32
Program type : Application
Clock frequency : 8,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#include <mega32.h>
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
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: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
while (1)
{
printf(read_adc(0));// It doesn't Works !!
};
}
|
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 03:16 PM |
|

Joined: Jun 08, 2002
Posts: 1249
Location: Champaign, IL USA
|
|
| Try printf("%d\r\n", read_adc(0)); |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 03:26 PM |
|

Joined: Dec 25, 2008
Posts: 6
|
|
what terminal are u using on the pc?
i think it should work, but like the program works now, only the raw bytes are transmitted, so its only depending on how your terminal is interpreting the incoming bytes |
|
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 04:17 PM |
|

Joined: Nov 12, 2004
Posts: 5
|
|
|
rstahlhu wrote:
Try printf("%d\r\n", read_adc(0));
It works ! indeed it displays Numerical value so to display the "real value" i have to use this formula ?
Real value= Numeric * Vref/1023
thx a lot |
Last edited by zanzeoo on Dec 26, 2008 - 08:58 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Dec 25, 2008 - 05:45 PM |
|

Joined: Dec 25, 2008
Posts: 6
|
|
| y, but i guess it must be 1024 or not? |
|
|
| |
|
|
|
|
|
Posted: Dec 31, 2008 - 02:19 AM |
|

Joined: Oct 25, 2008
Posts: 8
|
|
|
zanzeoo wrote:
rstahlhu wrote:
Try printf("%d\r\n", read_adc(0));
It works ! indeed it displays Numerical value so to display the "real value" i have to use this formula ?
Real value= Numeric * Vref/1023
thx a lot
|
|
|
| |
|
|
|
|
|
Posted: Dec 31, 2008 - 02:29 AM |
|

Joined: Oct 25, 2008
Posts: 8
|
|
Please, I need your help. I have to do something similar to this but I don't understand how this really works (I'm sorry but I'm a begginer). For example, I don't know if you have to push the joystick to start the ADC conversion and in what programme in your PC you see the result of the ADC conversion and in what frequency the result appears on the PC.
Thanks a lot! |
|
|
| |
|
|
|
|
|
Posted: Dec 31, 2008 - 03:10 AM |
|


Joined: Sep 04, 2002
Posts: 21391
Location: Orlando Florida
|
|
| You write a program in c to read the a/d channel and send it out the avr uart in ascii, and burn this program into the avr. Then you can use any pc terminal program like hyperterminal to see the ascii characters. There are examples of how to do this, usually in the c compiler examples directory. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jan 02, 2009 - 01:45 AM |
|

Joined: Oct 25, 2008
Posts: 8
|
|
Hi! I also have to do something similar to this. I have to put the signal that I want to analyse in the ADC and make de conversions for 30 seconds. Then, I have to make some threatments on the digital signals that result of the ADC conversion (make the average of the signal and some other things).
Please, someone could help me with a code example? (I'm using ATmega169).
Thank you very much! |
|
|
| |
|
|
|
|
|
Posted: Jan 04, 2009 - 04:53 PM |
|

Joined: Nov 29, 2007
Posts: 3219
|
|
|
mustang'a wrote:
Hi! I also have to do something similar to this. I have to put the signal that I want to analyse in the ADC and make de conversions for 30 seconds.
Stop posting the same question again and again!
You have now posted the same question at least four times, and at least two times by hijacking threads. Stop that! The more you misbehave, the smaller will be your chance to get help.
Stick to one thread. Do your homework (show us what you have done, instead of asking us to do the work for you). |
_________________ Stealing Proteus doesn't make you an engineer.
|
| |
|
|
|
|
|
Posted: Nov 08, 2010 - 06:01 PM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
Good day avrFreaks,
In the code posted by Zanzeoo, which ADC input is he utilizing for reading his analog value? Is it ADC channel 0? And if so, where did he declare it as such?
Regards,
Ulysses L.
zanzeoo wrote:
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.8a Evaluation
Automatic Program Generator
� Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 24/12/2008
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega32
Program type : Application
Clock frequency : 8,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#include <mega32.h>
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
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: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
while (1)
{
printf(read_adc(0));// It doesn't Works !!
};
}
|
|
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 01:40 AM |
|

Joined: Nov 17, 2004
Posts: 13956
Location: Vancouver, BC
|
|
|
Quote:
In the code posted by Zanzeoo, which ADC input is he utilizing for reading his analog value? Is it ADC channel 0? And if so, where did he declare it as such?
All three questions are answered with this:
Code:
read_adc(0)
|
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 05:34 AM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
|
Koshchi wrote:
Quote:
In the code posted by Zanzeoo, which ADC input is he utilizing for reading his analog value? Is it ADC channel 0? And if so, where did he declare it as such?
All three questions are answered with this:
Code:
read_adc(0)
Thank you very much for your fast response Koshchi,
I have an Atmega128 and I'm currently using Codevision to program my uC. I have successfully used the USART0 to transmit data over my Xbee's to the PC. Mainly Text, such as "Hello world".
The problem comes when I try to read data on my ADC. I tried plugging in my analog voltage to my channel 0, even channel 1 and 7. But the Tx keeps sending the same data over and over: .255
What am I missing? Is there a special way I need to plug my analog voltage? (like a Capacitor)
Regards,
Ulysses L.
Edit 1 - I'm using the same Code as the one shown above in CodeVision. |
|
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 01:55 PM |
|


Joined: Feb 19, 2001
Posts: 26102
Location: Wisconsin USA
|
|
|
Quote:
I'm using the same Code as the one shown above in CodeVision.
Quote:
Chip type : ATmega32
Quote:
I have an Atmega128
You are using Mega32 code for a Mega128?
In particular, examine the ADMUX bits for reference selection. Are they the same in both datasheets? What do you have connected to the AVCC, AGND, and AREF pins? Do you have the M103 fuse turned off? |
|
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 07:17 PM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
|
Quote:
You are using Mega32 code for a Mega128?
Of course not, I'm using code for the Atmega 128 which is 99% the same code as the one shown above. (The Codevision generates it)
Quote:
In particular, examine the ADMUX bits for reference selection.
ADC channels 0-7, PF0-PF7.
Quote:
What do you have connected to the AVCC, AGND, and AREF pins?
I'm using the ET-AVR Stamp Module - Upgraded with the ET-AVR Stamp Board, in which I think AREF is already connected.
Quote:
Do you have the M103 fuse turned off?
I'm not familiar with this instruction, is it something you place in the code? or you just do it with the AVRStudio?
Here's my actual code:
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.9 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 11/8/2010
Author : WarezBB
Company : ORG
Comments:
Chip type : ATmega128
Program type : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 1024
*****************************************************/
#include <mega128.h>
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x60
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;
// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;
// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
ETIMSK=0x00;
// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
UCSR0A=0x00;
UCSR0B=0x18;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
while (1)
{
printf("%.d\r\n", read_adc(0));
};
}
Note: the '.' (dot) in the printf line is not in the code, apparently it wouldn't let me post the code here in the forums if I didn't alter that instruction, probably because its html. |
|
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 08:37 PM |
|


Joined: Jul 18, 2005
Posts: 62934
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
I'm not familiar with this instruction, is it something you place in the code? or you just do it with the AVRStudio?
When ATmega128's ship from Atmel they actually have the M103C fuse enabled (set to 0) so behave functionally like an ATmega103 not an ATmega128 which means a different memory map and limited functionality. |
_________________
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 09:03 PM |
|

Joined: Feb 12, 2005
Posts: 16547
Location: Wormshill, England
|
|
1. I would guess your commercial board will already have the correct fuses.
2. I copy-pasted your program and compiled it. It works just fine. I vary a potentiometer on PORTF.0. The display varies from 1 to 255.
Your first job is to say what programmer you are using.
CodeVision is lovely for Edit-Compile-Burn-Run cycles.
However the 'Fuse Selection' requires a better brain than I possess.
I recommend that you go to http://www.engbedded.com/fusecalc/
Choose your fuses carefully, and then tick the CodeVision boxes exactly the same.
Personally, I always choose to NOT touch fuses with CodeVision. If I want to change fuses, I do it with Studio or avrdude.
After all, you normally set the fuses once, and this stays for 99% of projects with that AVR.
David. |
|
|
| |
|
|
|
|
|
Posted: Nov 09, 2010 - 09:18 PM |
|


Joined: Feb 19, 2001
Posts: 26102
Location: Wisconsin USA
|
|
|
Quote:
Quote:
In particular, examine the ADMUX bits for reference selection.
ADC channels 0-7, PF0-PF7.
That only deals with channel selection. How about the reference selection?
But than you did post your code, and we find:
Quote:
#define ADC_VREF_TYPE 0x60
...which is why I said earlier...
Quote:
In particular, examine the ADMUX bits for reference selection. Are they the same in both datasheets? What do you have connected to the AVCC, AGND, and AREF pins?
... and which seems to be indeed AVCC reference and ADLAR. Now, what else does the datasheet say about this?
Quote:
0 1 AVCC with external capacitor at AREF pin
If you do indeed have an input on your board to the AREF pin, then you selections have made AVCC fight with the voltage being applied to the AREF pin. Look at the diagram in the datasheet (notice how many times that word is mentioned?) and in some cases you can quickly fry your AVR with fighting voltages.
So get the schematic of the board you are using, determine what reference selection it is wired to use, and make code accordingly.
Lee |
|
|
| |
|
|
|
|
|
Posted: Nov 10, 2010 - 06:45 AM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
|
Quote:
2. I copy-pasted your program and compiled it. It works just fine. I vary a potentiometer on PORTF.0. The display varies from 1 to 255.
Nice, did you modify anything in the code? or do you have an Atmega128 as well? What did you plug physically to your uC.
Quote:
Your first job is to say what programmer you are using.
I use Codevision to generate my code, and then use the HEX file and program it in the AVRStudio 4.
Quote:
After all, you normally set the fuses once, and this stays for 99% of projects with that AVR.
Could you explain which fuses I would be needing for this project only? And maybe why?
Today at school, I was talking to a friend who's uC arrived at the same time as mine since we ordered it together (same brand, same uC, same store) and she was telling me how she had the same problem when utilizing the ADC channel, she said that the value it returned was always at the highest, in my case "255".
And that she tried the code with a uC of a professor that is 1 or 2 years older (in version), and that it worked perfectly.
I'm starting to think that some or the whole shipment of uC's from were I got mine, are defective. Has this happened in the forums before? And if so, what do people do, other than cry?
Regards,
Ulysses L. |
|
|
| |
|
|
|
|
|
Posted: Nov 10, 2010 - 10:18 AM |
|


Joined: Jul 18, 2005
Posts: 62934
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
I use Codevision to generate my code, and then use the HEX file and program it in the AVRStudio 4.
The "programmer" in this context is the block of electronics that sits between the PC and the AVR board. As you say you use Studio it sounds like it could be AVRISPmkII, STK500, Dragon or something similar? |
_________________
|
| |
|
|
|
|
|
Posted: Nov 10, 2010 - 07:17 PM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
|
clawson wrote:
Quote:
The "programmer" in this context is the block of electronics that sits between the PC and the AVR board. As you say you use Studio it sounds like it could be
AVRISPmkII, STK500, Dragon or something similar?
I'm sorry, I'm using a ET-AVR JTAG (RS232) V1.0
As I stated before, every other proyect has worked perfectly such as the blinking LED, USART0 communication, etc. Except for the ADC channel.
Regards,
Ulysses L. |
|
|
| |
|
|
|
|
|
Posted: Nov 10, 2010 - 07:36 PM |
|


Joined: Feb 19, 2001
Posts: 26102
Location: Wisconsin USA
|
|
|
Quote:
are defective. Has this happened in the forums before?
No. Unless you have counterfeit chips.
http://www.sparkfun.com/commerce/news.php?id=364
You are now bemoaning bad chips, without ever exploring the AREF connection/level situation. It can explain your results. And also can explain how your chip might have been blown. |
|
|
| |
|
|
|
|
|
Posted: Nov 10, 2010 - 10:57 PM |
|

Joined: Oct 11, 2010
Posts: 6
|
|
|
theusch wrote:
You are now bemoaning bad chips, without ever exploring the AREF connection/level situation. It can explain your results. And also can explain how your chip might have been blown.
Here's the part of the schematic that shows how AVCC and AREF are connected to my atmega128.
What should I look for? I have tried twice to code it with a voltage reference AVCC and AREF. But still nothing seems to work. |
|
|
| |
|
|
|
|
|
Posted: Nov 11, 2010 - 03:25 AM |
|


Joined: Feb 19, 2001
Posts: 26102
Location: Wisconsin USA
|
|
|
Quote:
I have tried twice to code it with a voltage reference AVCC
Yes, indeed. have you looked at the ADC diagram in the datasheet? when you make that selection, what voltage is the AVR presenting on the AREF pin? Answer: AVcc. What other voltage is being presented to that pin? Answer: Look at your schematic. You have fighting voltages. Who knows which one will win, or whether you AVR remains undamaged.
No, they aren't "bad chips".
Didja ever look at the levels on the pins as I suggested?
BTW, why are you asking about getting bad >>chips<< when apparently you are using a purchased module/dev board? I'm getting way confused. If you bought a board and it doesn't work, why aren't you asking questions of your vendor? |
|
|
| |
|
|
|
|
|
Posted: Nov 06, 2011 - 03:04 PM |
|

Joined: Nov 06, 2011
Posts: 1
|
|
thx for ...
Code:
read_adc(0)
|
|
|
| |
|
|
|
|
|