Go Back   Home > Forums > Design & Build > Equipment & Tools
Home Forums Rules Articles Store Gallery Blogs Register Donations FAQ Calendar Search Today's Posts Mark Forums Read

Equipment & Tools From test equipment to hand tools

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 12th January 2008, 05:02 PM   #1
Tolik is offline Tolik  Israel
diyAudio Member
 
Tolik's Avatar
 
Join Date: Mar 2007
Send a message via MSN to Tolik
Question Digital soldering station project need help

Hi,
I`m building digital soldering station based on atmega 8 chip.
The code was redy, but I wont to use rotary encoder to control temperature. Now the problem that I can`t to write an interface routine. I tried some trics but It still not working.
If somebody familiar with C & AVR stuff help me please.
Encoder connected to PINC1,PINB4 & to ground, MCU pins set to 1.

here is the the part of code:

/************************************************** ***
Chip type : ATmega8
Program type : Application
Clock frequency : 8,0000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
************************************************** ***/

#include <mega8.h>
#include <stdio.h>
#include <math.h>
#include <delay.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>

#define ADC_VREF_TYPE 0xC0

#define KEY1_DOWN (encoder == 2)
#define ENC_A (PINC.1 == 0)
#define KEY2_DOWN (PINC.2 == 0)
#define KEY3_DOWN (PINC.3 == 0)
#define KEY4_DOWN (PINB.5 == 0)
#define KEY5_DOWN (encoder == 0)
#define ENC_B (PINB.4 == 0)
#define KEY6_DOWN (PINB.3 == 0)

#define BEEP PORTB.0

//unsigned char KEY1_DOWN;
//unsigned char KEY5_DOWN;
unsigned char lcd_buffer1[17] = " ";
unsigned char lcd_buffer2[17] = " ";
unsigned char lcd_buffer12[4] = " ";
unsigned char lcd_buffer21[5] = " ";

/* [0] " Heating..." */
flash unsigned char Mes0[]={23,23,23,72,101,97,116,105,110,103,46,46,46,23,2 3,0};

/* [1] " REDY " */
flash unsigned char Mes1[]={23,23,23,23,23,23,82,69,68,89,23,23,23,23,23,0};

/* [2] "Setup" */
flash unsigned char Mes2[]={23,23,23,23,83,101,116,117,112,23,23,0};

/* [3] "Temperature:" */
flash unsigned char Mes3[]={23,84,101,109,112,101,114,97,116,117,114,101,23, 23,23,0};


volatile unsigned int adc_data = 0, T, ee_tmprSet = 0, T_disp = 0;
volatile int ReadKey = 0, KeyDelay = 0, Mode = 0, program = 1;

unsigned int i=1, T0 = 3, Kp = 70; //

volatile int pwm_val = 0; // store PWM data in 1/1024


eeprom unsigned int T_prog[3] = { 150, 250, 400 }; // themperature presets in EEPROM
unsigned int T_set[3];

static void avr_init();
void green(void);
void red(void);
void my_beep(void);
unsigned int read_adc(unsigned char adc_input);

// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
// 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;
#asm
in r30,mcucr
cbr r30,__sm_mask
sbr r30,__se_bit | __sm_adc_noise_red
out mcucr,r30
sleep
cbr r30,__se_bit
out mcucr,r30
#endasm
return adc_data;
}

signed char
encoder(void)
{
static unsigned char a, b;
if (!a & !b) {
if (ENC_A) {
a = ENC_A;
return (2);
}
if (ENC_B) {
b = ENC_B;
return (1);
}
}
if (a & !b) {
if (!ENC_A) {
a = ENC_A;
return (1);
}
if (ENC_B) {
b = ENC_B;
return (2);
}
}
if (a & b) {
if (!ENC_A) {
a = ENC_A;
return (2);
}
if (!ENC_B) {
b = ENC_B;
return (1);
}
}
if (!a & b) {
if (ENC_A) {
a = ENC_A;
return (1);
}
if (!ENC_B) {
b = ENC_B;
return (2);
}
}
return (0);
}


// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=0x00;
if (ReadKey == 0) {
if (KeyDelay == 0) { // If KeyDelay == 0, possible to repeat
KeyDelay = 0;

if (KEY1_DOWN) {
ReadKey = 1;
my_beep();
}
if (KEY2_DOWN) {
ReadKey = 2;
my_beep();
}
if (KEY3_DOWN) {

ReadKey = 3;
my_beep();
}
if (KEY4_DOWN) {
ReadKey = 4;
my_beep();
}
if (KEY5_DOWN) {
ReadKey = 5;
my_beep();
}
if (KEY6_DOWN) {

ReadKey = 6;
my_beep();
}

if (ReadKey) {
KeyDelay = 10;
}
} else {
KeyDelay--;
}
} // if
i--;

if (i==0) {
T_disp = T; // display temp calculation !!!!!!!!!!!!
i=15;
}
}

void main(void)
{
avr_init();

while (1)
{
adc_data=read_adc(0);
T = adc_data / 2 ; // ADC conversion setup !!!!!!!!!!!!!!!!

pwm_val = Kp * (ee_tmprSet - T + T0);

if (pwm_val > 1023) pwm_val = 1023;
if (pwm_val < 0) pwm_val = 0;

if ((T > (ee_tmprSet - 6)) && (T < (ee_tmprSet + 6))) {
green();
} else {
red();
}

if (ReadKey == 5)
{
if (Mode == 1 || Mode == 2 || Mode == 3) {
T_set[Mode - 1] = T_set[Mode - 1] + 1;
// } else {
}
if (ee_tmprSet >= 420){ // themperature limit max.
ee_tmprSet = ee_tmprSet + 0; // themperature step +
} else {
ee_tmprSet = ee_tmprSet + 5;
}
ReadKey = 0;
}
if (ReadKey == 1)
{
if (Mode == 1 || Mode == 2 || Mode == 3) {
T_set[Mode - 1] = T_set[Mode - 1] - 1;
//} else {
}
if (ee_tmprSet <= 0){
ee_tmprSet = ee_tmprSet - 0; // // temperature step -
}else{
ee_tmprSet = ee_tmprSet - 5;
}
ReadKey = 0;
}
if (ReadKey == 3)
{
lcd_clear();
Mode++;
if (Mode == 4) {
#asm("cli")
T_prog[0] = T_set[0];
T_prog[1] = T_set[1];
T_prog[2] = T_set[2];
#asm("sei")
Mode = 0;
}
ReadKey = 0;
}

if (Mode == 1 || Mode == 2 || Mode == 3)
{
sprintf(lcd_buffer1, Mes2);
sprintf(lcd_buffer12, "P%i:", Mode);
sprintf(lcd_buffer2, Mes3);
sprintf(lcd_buffer21, "%03i", T_set[Mode - 1]);

lcd_gotoxy(12, 0);
lcd_puts(lcd_buffer12);
lcd_gotoxy(13, 1);
lcd_puts(lcd_buffer21);
}


if (ReadKey == 6)
{
ee_tmprSet = T_set[0];
program = 1;
ReadKey = 0;
}
if (ReadKey == 4)
{
ee_tmprSet = T_set[1];
program = 2;
ReadKey = 0;
}
if (ReadKey == 2)
{
ee_tmprSet = T_set[2];
program = 3;
ReadKey = 0;
}

if (Mode == 0)
{

sprintf(lcd_buffer1, "Tc=%03i Ts=%03i P%i", T_disp, ee_tmprSet, program);


if (T_disp >= ee_tmprSet)
{

sprintf(lcd_buffer2, Mes1);

}
else
{
sprintf(lcd_buffer2, Mes0);
}

}




lcd_gotoxy(0, 0);
lcd_puts(lcd_buffer1);
lcd_gotoxy(0, 1);
lcd_puts(lcd_buffer2);



OCR1AH = (unsigned char)(pwm_val>>8);
OCR1AL = (unsigned char)pwm_val;

};
}

void green(void) {
PORTC.4 = 0;
PORTC.5 = 1;
}

void red(void) {
PORTC.4 = 1;
PORTC.5 = 0;
}
void my_beep(void) {
BEEP = 1;
delay_ms(25); // beep lenth -------------------------
BEEP = 0;
}
  Reply With Quote

Reply


Hide this!Advertise here!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
850 degree digital soldering station(weller wanted?) mclsound Parts 0 30th November 2008 03:46 PM
WTB soldering station prezden Swap Meet 6 28th November 2008 08:45 PM
SMD soldering station hbarki Parts 10 27th October 2008 07:17 PM
This soldering station OK for smd? johnthedoctor Parts 16 9th May 2006 11:30 PM
which soldering station? David B Parts 11 15th May 2005 03:59 AM


New To Site? Need Help?

All times are GMT. The time now is 03:15 AM.

Page generated in 0.11136 seconds (81.44% PHP - 18.56% MySQL) with 10 queries

Copyright ©1999-2012 diyAudio