AVR novice needs help in ADC Multiplexing to make a quad thermometer.

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

*DO NOT START ANOTHER THREAD ON THE SAME TOPIC. MODERATOR*

 

I want to make a quad thermometer. It will have four LM35 sensors mounted in four different places of a refrigeration system (Compressor, Condenser, Evaporator and Room Temperature.) Each sensor would have ~1 metre of shielded wire. Sensors will feed the individual inputs to different pins of Port A of an ATMega16 and display all the results on a single 20x4 LCD screen.

 

I'm trying to multiplex two LM35 sensors at first and test the code. If it's successful I'll go from there.

 

 I know the code I've written is wrong in many ways, but am I going the right way? Please guide me. Also, my knowledge of C is too rusty.

 

Compiling this code gives me the following errors:

1. 'tempD' undeclared (first use in this function) 

2. expected declaration specifiers or '...' before '*' token

 

#include <avr/io.h>             // special function registers
#include <stdio.h>              // sprintf()
#define F_CPU 16000000           // 16 MHz clock set
#include <util/delay.h>         // _delay_xx()
#include "lcd.h"                // Fleury LCD library

int main(void)
{
	char display[80], degree = 0xDF;         // special character for degree symbol
	int tempC, tempD
	
	ADCSRA = (1<<ADEN)|(7 << ADPS0);        // Enable, div128, ADC clock at 125 KHz
	ADMUX = (3 << REFS0)|(1<<ADLAR)|(0<<MUX0);  // VREF=2.56V, 8-bit, channel #0 is on PA0 pin

	lcd_init(LCD_DISP_ON);
	lcd_puts("Compressor");          // only print this once
	while (1) {
		ADCSRA |= (1<<ADSC);          // Start Conversion
		while (ADCSRA & (1<<ADSC));   // wait for completion

		tempC = ADCH;                 // 10mV per C.  full-scale is 2.56V i.e. 256C
		

		sprintf(display, "%3d%cC", tempC, degree);
		lcd_gotoxy(2, 1);             // 2nd column, 1st line
		lcd_puts(display);            // string is all printed in one go
		_delay_ms(500);
		
		ADCSRA|=(1<<ADIF);                // Clearing ADC.

		return(ADC);
	}
	
	void Wait()
	{
		uint8_t i;
		for(i=0;i<100;i++)
		_delay_loop_2(0);
	}

	ADCSRA = (1<<ADEN)|(7 << ADPS0);        // Enable, div128, ADC clock at 125 KHz
	ADMUX = (3 << REFS0)|(1<<ADLAR)|(1<<MUX0);  // VREF=2.56V, 8-bit, channel #1 is on PA1 pin

	lcd_puts("Condenser");
	while (1) {
		ADCSRA |= (1<<ADSC);          // Start Conversion
		while (ADCSRA & (1<<ADSC));   // wait for completion

		tempD = ADCH;                 // 10mV per C.  full-scale is 2.56V i.e. 256C
		

		sprintf(display, "%3d%cC", tempD, degree);
		lcd_gotoxy(2, 2);             // 2nd column, 2nd line
		lcd_puts(display);            // string is all printed in one go
		_delay_ms(500);
		
		ADCSRA|=(1<<ADIF);                // Clearing ADC.

		return(ADC);
	}
	
	
	{
		uint8_t i;
		for(i=0;i<100;i++)
		_delay_loop_2(0);
	}
}

 

 

Last Edited: Wed. Apr 29, 2015 - 01:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think a better response method would have been to reply to the OP saying that there's a number of threads discussing this already.  An even better response would have been to include a link to a thread or a link to some search results.  The link I'm providing isn't very specific and I'm sure can be built upon.

 

https://www.avrfreaks.net/search/site/thermometer?f[0]=bundle%3Aforum

Please Read: Code of Conduct

Documentation: Atmel Community User Guide (work-in-progress)

Site Updates: Changelog

Last Edited: Tue. Apr 28, 2015 - 10:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The original thread is here: https://www.avrfreaks.net/forum/i...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Michael,

 

I think that you have misunderstood the situation. The OP, bagho, started 2 threads on the same topic HIMSELF. Referring him to yet another series of topic-related threads would have served little or no purpose when he simply needed to be told to not create multiples of his own threads. I hope that clarifies the situation.

 

Thanks,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

Topic locked