'차량용 인두기'에 해당되는 글 1건


DC 인두기 

- HAKKO 인두기 제어기


예전에 제작해서

블로그에 올린

DC 인두기


아래 링크에 있다.



차량용 인두기 자작 

(DC / 12V 인두)


Temp controlled Iron HAKKO 907 

(atmega8)

- 온도조절 하코 인두기


꺼내서 사용하다가 보니
온도 세팅 저장이 안되는 문제점 발견

소스를 살펴보니 Cross 컴파일러 소스를 WinAVR로 변경하면서 
실수한 곳 발견. 
EEMEM 관련 루틴에 오류.

펌웨어 

수정한 소스를 다시 올려 놓는다.
오늘 확인 끝!!

Makefile

// ----------------------------------------------------------------------------
// Chip type           : ATmega8 - CodeVision to WinAVR GCC
// Program type        : Application
// Clock frequency     : 8,0000 MHz - internal RC clock
// ----------------------------------------------------------------------------
// Converted to AVRGCC
// LED type CC
// 2011.07.2x : Initial version
// 2014.12.23 : Bug fix not saving into EEMEM
// ----------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include 
// ----------------------------------------------------------------------------
#define ADC_VREF_TYPE 0x40
// ----------------------------------------------------------------------------
#define	KEY1_DOWN	!(PINB & 0x40)	//(PINB.6 == 0)
#define	KEY2_DOWN	!(PINB & 0x80)	//(PINB.7 == 0)
#define	KEY3_DOWN	!(PINB & 0x20)	//(PINB.5 == 0)
#define	KEY4_DOWN	!(PINB & 0x10)	//(PINB.4 == 0)
#define	KEY5_DOWN	!(PINB & 0x08)	//(PINB.3 == 0)
//#define EEPROM  __attribute__ ((section (".eeprom")))
// ----------------------------------------------------------------------------
/* 0,1,2,3,4,5,6,7,8,9 */
unsigned char digit[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char off[] = {0x3f,0x71,0x71}; // text "OFF"
// ----------------------------------------------------------------------------
// FND_SND-630ASK (Common Cathode)
// PortD 0 1 2 3 4 5 6 7 (Port D assignment)
// FND  11 7 4 2 1 5 10  = pin (dp = 3) : dig1=12, dig2=9, dig3=8
// -----------------------------------------------------------------
//   0|  a b c d e f - - | 00111111 | 3f
//   1|  - b c - - - - - | 00000110 | 06
//   2|  a b - d e - g - | 01011011 | 5b
//   3|  a b c d - - g - | 01001111 | 4f
//   4|  - b c - - f g - | 01100110 | 66
//   5|  a - c d - f g - | 01101101 | 6d
//   6|  a - c d e f g - | 01111101 | 7d
//   7|  a b c - - f - - | 00100111 | 07
//   8|  a b c d e f g - | 01111111 | 7f
//   9|  a b c d - f g - | 01101111 | 6f
// digit to seven segment LED mapping:
// ----------------------------------------------------------------------------
volatile unsigned int i = 1, j, Read_Key, T_digit[3], n;
volatile unsigned int adc_data, T, T_alldigit, T_disp, Mem[3];
unsigned int Time, Time_m, beep_i, set_time = 2000;
unsigned char Keybit1, Keybit2, Keybit3, Keybit4, Keybit5, stop, blink;
unsigned char set, c_beep, beep_bit, t;
volatile long pwm_val, ee_tmprSet, K_pwm = 30;
volatile int i2 = 500;
// ----------------------------------------------------------------------------
//unsigned int adcX[]={200,238,273,305,334,361,386,410,431,451,470,488,504};
//unsigned int adcX[]={390,465,533,596,653,706,755,800,842,881,918,952,985};
//unsigned int adcTemp[]={18,60,102,144,186,228,270,312,354,396,438,480,522};
unsigned int adcX[]={238,320,334,348,361,372,374,398,410,421,429,451,488};
unsigned int adcTemp[]={40,128,162,194,225,249,255,273,309,330,358,420,490};
// ----------------------------------------------------------------------------
// eeprom unsigned int T_prog[3] = { 200, 250, 300 };
uint16_t T_prog[3] EEMEM ={ 250, 300, 350 };
// ----------------------------------------------------------------------------
static void avr_init(void);
void ReadKey (void);
void green (void);
void red (void);
void my_beep (void);
void One_Digit (void);
void Display (void);
void xdelay_us(unsigned char time_us);
void xdelay_ms(unsigned char time_ms);
// ----------------------------------------------------------------------------
void xdelay_us(unsigned char time_us) // time delay(us)
{
    register unsigned char i;
    for(i = 0; i < time_us; i++) // 4 cycle +
    {
        asm("PUSH R0"); // 2 cycle +
        asm("POP R0"); // 2 cycle +
        // 8 cycly @ 8MHz = 1us : Max 250us
    }
}
// ----------------------------------------------------------------------------
void xdelay_ms(unsigned char time_ms) // time delay(us)
{
    register unsigned char i;
    for(i = 0; i < time_ms; i++)
    {
        xdelay_us(250);
        xdelay_us(250);
        xdelay_us(250);
        xdelay_us(250);
    }
}
// ----------------------------------------------------------------------------
// ADC interrupt service routine
ISR(ADC_vect){
// Read the AD conversion result
	adc_data=ADCW;
}
// ----------------------------------------------------------------------------
// Read the AD conversion result
// with noise canceling
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
	xdelay_us(10);
	MCUCR = 0x80 | 0x10;	// Sleep enable & noise reduction
	asm("sleep");
	MCUCR &= ~0x80;
	return adc_data;
}
// ----------------------------------------------------------------------------
// Timer 0 overflow interrupt service routine
ISR(TIMER0_OVF_vect) {
	TCNT0=0xb2; // 1

	i--;
	if (!i) {
		if(t == 0)	t = 1;	// replace for BIT t++;
		else		t = 0;
		i = 20;
		T_disp = T;
	}
	// Timer
	if (stop == 0) {
		Time++;
		if (Time == 6000) {
			Time_m++;
			Time = 0;
		}
		if ((T >= 400 && Time_m == 15) || (T < 400 && Time_m == 60)) {
			stop = 1;
			Time = 0;
			Time_m = 0;
			c_beep = 1;
		}
	}
	// "beep   350 *10=3,5
	if ((T > (ee_tmprSet - 3)) && (T < (ee_tmprSet + 3))) {
		beep_i--;
		if (!beep_i && beep_bit==0 && stop==0) {
			my_beep();
			beep_bit = 1;
		}
	}else {
		beep_bit = 0;
		beep_i = 350;
	}
	i2--;
}
// ----------------------------------------------------------------------------
// Timer 2 overflow interrupt service routine
ISR(TIMER2_OVF_vect) {
	TCNT2=0x83; //
	if (set == 1) {
		T_alldigit = ee_tmprSet;
		set_time--;
		if (t == 0){	// blink = (blink++)%2;
			if(blink == 0)	blink = 1;
			else			blink = 0;
		}
		if (!set_time) set = blink = 0;
	}
	else
		T_alldigit = T_disp;
	One_Digit();
	Display();
	j++;
	if (j > 2) j = 0;
}
// ----------------------------------------------------------------------------
unsigned int BInterp(unsigned int *xaxis, unsigned int *yaxis, unsigned int num, unsigned int xval){
    // when call the num means the last index value : 0...9 num=9
    // Binary interpolation routine
    unsigned char left, right, mid;
    unsigned int yval;
		
    if(xval <= xaxis[0])		return(yaxis[0]);
    else if(xval >= xaxis[num])	return(yaxis[num]);
    else{
        left = 0;
        right = num;
    }
    while((left+1) < right){
        mid = (left + right) / 2;
        if(xval < xaxis[mid])
            right = mid;
        else if(xval > xaxis[mid])
            left = mid;
        else
            return(yaxis[mid]);
    }
    // incline = (yaxis[right]-yaxis[left]) / (xaxis[right]-xaxis[left])
    // yval = y[left] + (incline * offset)
    // rearrange formula to avoid float
    yval = (yaxis[right]-yaxis[left]);
    yval = yval * (xval-xaxis[left]);
    yval = yval / (xaxis[right]-xaxis[left]);
    yval = yval + yaxis[left];
    return yval;
}
// ----------------------------------------------------------------------------
int main(void){
	avr_init();
	while (1){
		adc_data = read_adc(0);
		// HAKKO with 100 ohm to VCC with 2.5 ref
		T = BInterp(adcX, adcTemp, 12, adc_data);
		// T = (unsigned int) adc_data * 0.83 - 348;	
		//T = adc_data;
		if (i2 <= 0) {
			if ((T > (ee_tmprSet - 8)) && (T < (ee_tmprSet + 4))) {
				if (T < ee_tmprSet) 	K_pwm++;
				if (T > ee_tmprSet) 	K_pwm--;
				if (K_pwm < 0) 		K_pwm = 0;
				if (K_pwm > 511) 	K_pwm = 511;
			}else {                  //
				if (ee_tmprSet > 150 && T > (ee_tmprSet - 36) && T < (ee_tmprSet + 36))
					K_pwm = 30 + ((ee_tmprSet - 150) / 2);
				else
					K_pwm = 30; //
			}
			i2 = 25; //
		}            //
		if (stop==0) {
			pwm_val = K_pwm * (ee_tmprSet - T + 2);
			if (T > (ee_tmprSet - 6) && T < (ee_tmprSet + 6))
				green();
			else
				red();
		}else {
			pwm_val = 0;
			PORTC |= _BV(1);
			PORTC |= _BV(2);
		}
		if (pwm_val > 1023)	pwm_val = 1023;
		if (pwm_val < 0) 		pwm_val = 0;
		ReadKey();
		if (Read_Key == 1) {
			ee_tmprSet = ee_tmprSet + 5;
			if (ee_tmprSet > 480) ee_tmprSet = 480;
			Read_Key = 0;
		}
		if (Read_Key == 2) {
			ee_tmprSet = ee_tmprSet - 5;
			if (ee_tmprSet < 50) ee_tmprSet = 50;
			Read_Key = 0;
		}
		if (Read_Key > 2 && Read_Key < 6) {
			ee_tmprSet = Mem[Read_Key - 3];
			set = 1;
			Read_Key = 0;
		}
		// if long press, then save new value in EEMEM
		if (Read_Key > 5 && Read_Key < 9) {
			asm("cli");
			Mem[Read_Key - 6] = ee_tmprSet;
			//T_prog[Read_Key - 6] =  Mem[Read_Key - 6];
			eeprom_write_word(&T_prog[Read_Key - 6], Mem[Read_Key - 6]);
			asm("sei");
			my_beep();
			xdelay_ms(50);
			my_beep();
			xdelay_ms(50);
			my_beep();
			set = 1;
			Read_Key = 0;
		}
     	if (c_beep==1) {
			my_beep();
			xdelay_ms(50);
			my_beep();
			xdelay_ms(50);
			my_beep();
			xdelay_ms(50);
			my_beep();
			c_beep = 0;
     	}
     	OCR1AH = (unsigned char)(pwm_val>>8); //   OCR1A -
     	OCR1AL = (unsigned char)pwm_val;
	}
}
// ----------------------------------------------------------------------------
void ReadKey (void) {
	if (!Read_Key) {
		if (!KEY1_DOWN && Keybit1) Keybit1 = 0;
		if (!KEY2_DOWN && Keybit2) Keybit2 = 0;
		if (!KEY3_DOWN && Keybit3) Keybit3 = 0;
		if (!KEY4_DOWN && Keybit4) Keybit4 = 0;
		if (!KEY5_DOWN && Keybit5) Keybit5 = 0;

		if (KEY1_DOWN)	{
            if (!Keybit1) my_beep();
				xdelay_ms(100); //
            Read_Key = 1;
            Keybit1 = 1;
		}

		if (KEY2_DOWN)	{
            if (!Keybit2) my_beep();
            xdelay_ms(100); //
            Read_Key = 2;
            Keybit2 = 1;
		}

		if (KEY3_DOWN && !Keybit3)	{
            my_beep();
            for (n = 0; (KEY3_DOWN && n < 40); n++) {
                xdelay_ms(50);
                set = 1;
                set_time = 2000;
            }
            if (KEY3_DOWN) {      	// (n40 * 50ms)
                Read_Key = 6;  		//
                Keybit3 = 1;
            }
            else Read_Key = 3;    	//
		}

		if (KEY4_DOWN && !Keybit4)	{
            my_beep();
            for (n = 0; (KEY4_DOWN && n < 40); n++) {
                xdelay_ms(50);
                set = 1;
                set_time = 2000; 	// set_time -
            }
            if (KEY4_DOWN) {
                Read_Key = 7;
                Keybit4 = 1;
            }
            else Read_Key = 4;
		}

		if (KEY5_DOWN && !Keybit5)	{
            my_beep();
            for (n = 0; (KEY5_DOWN && n < 40); n++) {
                xdelay_ms(50);
                set = 1;
                set_time = 2000;
            }
            if (KEY5_DOWN) {
                Read_Key = 8;
                Keybit5 = 1;
            }
            else Read_Key = 5;
		}

		if (Read_Key) {
			set_time = 2000;
         set = 1;
         Time = Time_m = 0;
         if (stop==1 && Read_Key == 2)
         	stop = 0;
		}
	}
}
// ----------------------------------------------------------------------------
void green (void) {
    PORTC &= ~(_BV(PC1));
    PORTC |= _BV(PC2);
}
// ----------------------------------------------------------------------------
void red (void) {
    PORTC |= _BV(PC1);
    PORTC &= ~(_BV(PC2));
}
// ----------------------------------------------------------------------------
void my_beep (void) {
    PORTB |= _BV(1);
    xdelay_ms(80); //
    PORTB &= ~(_BV(1));
}
// ----------------------------------------------------------------------------
// Distribute digit value to 3 lED 
// ----------------------------------------------------------------------------
void One_Digit (void) {
    T_digit[0] = T_digit[1] = 0;
    while (T_alldigit >= 100) {
        T_alldigit -= 100;
        T_digit[0]++; //
    }
    while (T_alldigit >= 10) {
        T_alldigit -= 10;
        T_digit[1]++; //
    }
    T_digit[2] = T_alldigit; //
}
// ----------------------------------------------------------------------------
void Display (void) {	// Common Cathod : set low = ON
    /*
	PORTC &= ~(7<<3); 	// 00000111 shift left 3, for PC345 set low - OFF
    if (stop) PORTD = ~off[j];
    else PORTD = ~digit[T_digit[j]]; // Display text "OFF"
    if (!blink) PORTC |= 1<<(5-j);   // Turn ON
	*/
	// Common Cathod type = PORTC low = Turn ON
	PORTD = 0x00;
	PORTC |= (7<<3); 					// 00000111 shift left 3, for PC345
    if (stop==1) PORTD = off[j];
    else PORTD = digit[T_digit[j]]; 	// Display text "OFF"
    if (!blink) PORTC &= ~(1<<(5-j)); 	// Turn ON
}
// ----------------------------------------------------------------------------
static void avr_init() {
	// Input/Output Ports initialization
	// Port B initialization
	// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=Out
	// State7=P State6=P State5=P State4=P State3=P State2=P State1=0 State0=0
	PORTB=0xFC;
	DDRB=0x03;

	// Port C initialization
	// Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
	// State6=P State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
	PORTC=0x40;
	DDRC=0x3E;

	// Port D initialization
	// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
	// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
	PORTD=0xFF;
	DDRD=0xFF;

	// Timer/Counter 0 initialization
	// Clock source: System Clock
	// Clock value: 7,813 kHz
	TCCR0=0x05;
	TCNT0=0xB2;

	// Timer/Counter 1 initialization
	// Clock source: System Clock
	// Clock value: 125,000 kHz
	// Mode: Ph. correct PWM top=03FFh
	// OC1A output: Non-Inv.
	// 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=0x83;
	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: 125,000 kHz
	// Mode: Normal top=FFh
	// OC2 output: Disconnected
	ASSR=0x00;
	TCCR2=0x04;
	TCNT2=0x83;
	OCR2=0x00;

	// External Interrupt(s) initialization
	// INT0: Off
	// INT1: Off
	MCUCR=0x00;
	
	// Timer(s)/Counter(s) Interrupt(s) initialization
	TIMSK=0x41;

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

	// ADC initialization
	// ADC Clock frequency: 125,000 kHz
	// ADC Voltage Reference: AREF pin
	ADMUX=ADC_VREF_TYPE & 0xff;
	ADCSRA=0x8E;
	// if NOT initialized or wrong temp set, reset to default
	if (eeprom_read_word(&T_prog[0]) < 50 || eeprom_read_word(&T_prog[0]) > 480) {
		eeprom_write_word(&T_prog[0], 250);
		eeprom_write_word(&T_prog[1], 300);
		eeprom_write_word(&T_prog[2], 350);
	}
	Mem[0] = eeprom_read_word(&T_prog[0]);
	Mem[1] = eeprom_read_word(&T_prog[1]);
	Mem[2] = eeprom_read_word(&T_prog[2]);
	ee_tmprSet = Mem[0];
	stop = 1;
	// Global enable interrupts
	asm("sei") ;
}
// ----------------------------------------------------------------------------


SolderGunCC_V2.c





블로그 이미지

DIYworld

,