![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Software for custom SMD-Soldering Station for Weller RT tips. This was made for a school project.
Diff: main.cpp
- Revision:
- 0:c9c80e03823a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 12 17:35:05 2015 +0000 @@ -0,0 +1,102 @@ +/* Libraries */ +#include "mbed.h" +#include "TextLCD.h" + +/* */ +#define DELAY_M 50 //Delay before Measuring Voltage at ADC-Pin (TempNow) +#define TEMP_BASEGAIN 0.137931 //Temp which should equal 1mV - changed by TEMP_FACTOR +#define TEMP_OFFSET 0 //Offset of Temperature +#define CTRL_GAIN 10 //TempDifference to PWM-Value Gain +#define TEMP_FACTOR 1.5 //TEMP_BASEGAIN * TEMP_FACTOR = TEMP_GAIN + +/* */ +Ticker dispRefresh; +TextLCD lcd (p18, p16, p11, p10, p9, p8); // rs, e, d4-d7 +DigitalOut db5(p10); //Data Pin 5 on LCD, used for Initialization +DigitalOut rw(p17); //Read-Write Pin on LCD: LOW-->WRITE +PwmOut pHeat(p26); //Heater-Pin +AnalogIn adc(p20); //ADC-Pin 10Bit +PwmOut pSpeaker(p25); //Piezo-Speaker Pin +InterruptIn rotSw1(p35); //Pin 1 of Rotary Encoder +DigitalIn rotSw2(p33); //Pin 2 of Rotary Encoder +InterruptIn rotSwB(p30); //Button of Rotary Encoder +DigitalOut tempCtrlLED(LED1); + +/* */ +float TempNow = 0; //Current Temperature Reading +float TempSet = 200; //Set Temperature +float pwmVal = 0; //PWM-Value for Heater-Pin +float adcVal = 0; //Value of ADC-Reading + +/* */ +void writeLCD(); +void init4BitLCD(); +void readTemp(); +void calcPWM(); +void RotEnc(); +void RotBut(); + +int ticker = 500; +Ticker t; +void tick_1(){ + if(ticker > 0) ticker--; +} + +int main() { + //Initialize + init4BitLCD(); //Set Display to 4 Bit-Mode + rw = 0; // Set Read/Write Pin to Write + rotSw1.rise(&RotEnc); + rotSwB.rise(&RotBut); + pSpeaker.period_ms(2); //Set Speaker Frequency to 500Hz + //pHeat = 0.1; + + t.attach(&tick_1, 0.001); + while(1) { + readTemp(); //Read Temperature - Done + calcPWM(); //Calculate PWM-Value - Done + pHeat = pwmVal; //Write PWM-Value to Heater - Done + if(ticker == 0){ + writeLCD(); //Write To LCD - Done + ticker = 500; + } + //Repeat + } +} + +void RotBut() +{tempCtrlLED = !tempCtrlLED; + if (pSpeaker == 0){pSpeaker = 0.5;} + else {pSpeaker = 0;}} + +void RotEnc() +{ + if (rotSw2 == 0){TempSet++;} + else if (rotSw2 == 1){TempSet--;} + wait_ms(1); + } + +void calcPWM() +{ + pwmVal = ((TempSet - TempNow) * CTRL_GAIN) / 255; //Calculate PWM-Val. + if (pwmVal > 1) pwmVal = 1; + else if (pwmVal < 0) pwmVal = 0; + } + +void readTemp() +{ pHeat = 0; //Switching Off Heater || Thermoelement --> No VoltageSupply + wait_ms(DELAY_M); //Waiting for a bit|| Low-Pass Filter --> Ready State + adcVal = adc.read(); //Read ADC + TempNow = adcVal*3300*(TEMP_BASEGAIN * TEMP_FACTOR) + TEMP_OFFSET; //Calculate current Temperature + pHeat = pwmVal; //Re-Activate Heater Pin + } + +void writeLCD() +{ char cHeat; + if(pwmVal > 0.5){cHeat = 'H';} + else{cHeat = ' ';} + lcd.cls(); + lcd.printf("Set: %.0f C %c\nNow: %.0f C", TempSet, cHeat, TempNow);} + +void init4BitLCD() +{ db5 = 1; wait_ms(1); lcd.cls();} \ No newline at end of file