Hey Freaks.
I've build a temp display using an Atmega8. I read the temp from an LM35 (going to change as soon as I get hold of another temp sensor that can give negative temps but with single rail supply only) via the ADC (where else would you read it from? lol). I then display the temp on 7 segments via 1 x 74HCT47 decoder using transistors to switch the displays. The displays flashes between two readings. For example, 16 and 17 then the displays will alternate between 6 & 7 and then it looks like an 8. When the temp gets close to 20 the 2nd display also starts alternating between a 1 and a 2.
How can I solve this problem? I'm thinking changing the ADC reading intervals but I've tried that and it's still to fast.
Here is the code;
#include#include /**************************************************************************************** Delay Routine ****************************************************************************************/ void Delay(unsigned long value) { unsigned long cnt; for(cnt = value; cnt > 0; cnt--); } /*********************************************************************************** ADC Init ***********************************************************************************/ void ADC_Init() { ADCSR |= (1<<ADPS1) | (1<<ADPS2); // Prescale 64 -> ADC clock is 125kHz // Leave MUX3-0 in ADMUX = 0 for ADC0 ADMUX |= ( (1<<REFS0) | (1<<ADLAR) ); // AVCC with external capacitor // at AREF pin, Left justify ADCSR |= (1<<ADEN); // Enable the ADC } /*********************************************************************************** Read Temp ***********************************************************************************/ void Read_Temp() { ADCSR |= (1<<ADSC); // Start conversion while(! (ADCSR & (1<<ADIF)) ); // Wait for ADC conversion complete ADCSR |= (1 << ADIF); } /**************************************************************************************** Write Shift Clock Pulse ****************************************************************************************/ void clockpulse(void) { PORTC |= (1<<PC5); //Serial Clock = 1 PORTC &= ~(1<<PC5); //Serial Clock = 0 } /**************************************************************************************** Write Shift Data ****************************************************************************************/ void Write_shift(unsigned int shift_Data) { unsigned char BitCntr; for(BitCntr = 0; BitCntr < 9; BitCntr ++) { if(BitCntr) { shift_Data = shift_Data << 1; } if(shift_Data & 0x80) { PORTC |= (1<<PC4); //Serial Data = 1 } else { PORTC &= ~(1<<PC4); //Serial Data = 0 } clockpulse(); } } /*********************************************************************************** Test Displays ***********************************************************************************/ void Test_Disp(void) { //PORTB |= (1<<PB5); //LT = 1 PORTB &= ~(1<<PB5); //LT = 0 PORTB |= (1<<PB4); //BI = 1 //PORTB &= ~(1<<PB4); //BI = 0 - Blank Displays //PORTB |= (1<<PB3); //RBI= 1 PORTB &= ~(1<<PB3); //RBI = 0 PORTD |= (1<<PD5); //Transistor 1 = 1 Delay(50); PORTD |= (1<<PD6); //Transistor 2 = 1 Delay(50); PORTD |= (1<<PD7); //Transistor 3 = 1 Delay(50000); PORTD &= ~(1<<PD5); //Transistor 1 = 0 Delay(50); PORTD &= ~(1<<PD6); //Transistor 2 = 0 Delay(50); PORTD &= ~(1<<PD7); //Transistor 3 = 0 Delay(50); PORTB |= (1<<PB5); //LT = 1 } /*********************************************************************************** Main Routine ***********************************************************************************/ int main(void) { unsigned long Disp_Delay; DDRB|=(1 << PB5)|(1 << PB4)|(1 << PB3); // PB 3,4,5 digital outputs DDRD|=(1 << PD5)|(1 << PD6)|(1 << PD7); // PD 5,6,7 digital outputs DDRC|=(1 << PC5)|(1 << PC4)|(1 << PC3); // PC 3,4,5 digital outputs PORTC &= ~(1 << 0); // PC 0 input ADC_Init(); Test_Disp(); PORTC &= ~(1<<PC3); //Master Reset=0 - Reset 74HCT595 PORTC |= (1<<PC3); //Master Reset = 1 Read_Temp(); while (1) { Read_Temp(); uint8_t Temp1 = ADCH % 10; uint8_t Temp10 = ADCH / 10; for(Disp_Delay = 0; Disp_Delay > 0; Disp_Delay--); { Write_shift(Temp1); PORTD |= (1<<PD5); //Transistor 1 = 1 Delay(50); PORTD &= ~(1<<PD5); //Transistor 1 = 0 if(Temp10<1) { PORTD &= ~(1<<PD6); //Transistor 2 = 0 } if(Temp10>=1) { Write_shift(Temp10); PORTD |= (1<<PD6); //Transistor 2 = 1 Delay(50); PORTD &= ~(1<<PD6); //Transistor 2 = 0 } PORTD &= ~(1<<PD7); //Transistor 3 = 0 } Disp_Delay = 65000; } } /*********************************************************************************** ************************************************************************************ ***********************************************************************************/
Any additional tips on the code will also be appreciated.
Regards,