void idle_control(void) { uint16_t target_rpm; int16_t duty; target_rpm = table1d_lookup( ecu.sensors.ect, IDLE_TEMP_SCALE_SIZE, (int16_t*)ecu.config.idle_temp_scale, (int16_t*)ecu.config.idle_rpm ); pid_set_target(&idle_pid, target_rpm); duty = pid_do(&idle_pid, ecu.sensors.rpm); pwm_set_duty(PWM_IDLE, (512 + (duty >> 6))); }
static void run_reflow(uint8_t mode) { uint16_t temp = 0; int16_t target = 30; uint16_t pid_out; uint8_t done = 0; char buf[9]; pid_init(); _delay_ms(200); wdt_enable(WDTO_2S); global_time = 0; pwm_set2(255); while(done == 0) { if (max6675_ready) { max6675_ready = 0; wdt_reset(); if ((max6675_data == 0) || (max6675_data & MAX6675_TC_OPEN)) { halt_tc_open(); break; } // convert data to temp in degrees temp = MAX6675_TEMP(max6675_data); temp = temp / 4; if (mode == 0) { target = ramp_get(global_time); if (target == -1000) { done = 1; LCD_cursor(1, 0); LCD_text(" "); LCD_cursor(0, 0); LCD_text("DONE !!!"); break; } } pid_out = pid_do(temp, target); // apply new pwm, pidout limit is 4096 scale to 256 pwm_set1(pid_out >> 4); serial_write('0'); serial_write('x'); serial_write_hex(global_time >> 8); serial_write_hex(global_time& 0xff); /* serial_write(' '); serial_write('0'); serial_write('x'); serial_write_hex(max6675_data >> 8); serial_write_hex(max6675_data & 0xff);*/ serial_write(' '); serial_write('0'); serial_write('x'); serial_write_hex(temp >> 8); serial_write_hex(temp & 0xff); serial_write(' '); serial_write('0'); serial_write('x'); serial_write_hex(target >> 8); serial_write_hex(target & 0xff); serial_write(' '); serial_write('0'); serial_write('x'); serial_write_hex(pid_out >> 8); serial_write_hex(pid_out & 0xff); serial_write('\n'); } if (mode == 1) { uint8_t tmp = enc_read(); if (tmp == ENC_UP) { if (target != 0xffff) target ++; } else if (tmp == ENC_DOWN) { if (target > 20) target --; } } if (!(BUTTONS & _BV(BUT))) { LCD_cursor(0, 0); LCD_text(" USER "); LCD_cursor(1, 0); LCD_text("ABORT !!"); break; } LCD_cursor(0, 0); snprintf(buf, 9, "C: %04d", temp); LCD_text(buf); LCD_cursor(1, 0); snprintf(buf, 9, "T: %04d", target); LCD_text(buf); } // pwm to zero pwm_set1(0); pwm_set2(0); wdt_disable(); wait_blink(); }