31 #include "reflow_oven.h"
40 static inline void CONFIG_ZEROCROSS_ENABLE() {
41 CONFIG_RB6_AS_DIG_INPUT();
51 void configTimer2(
void) {
52 T2CON = T2_OFF | T2_IDLE_CON | T2_GATE_OFF
60 #define TRIAC_PW_HIGH 100 //in microseconds, triac gate pulse width high
61 #define HALF_CYCLE 8000 //in microseconds, part of half-cycle to use for triggering
62 #define CYCLE_OFFSET 200 //don't start right at zero crossing
68 void configOutputCapture1(
void) {
75 OC1CON = OC_TIMER2_SRC |
85 static inline void TRIAC_ON() {
90 u32_x = u16_halfCycleTicks;
91 u32_x = (u32_x * u8_currPowerSetting)/MAX_POWER_SETTING;
92 u32_x = u16_halfCycleTicks - u32_x;
93 OC1R = u32_x+u16_cycleOffsetTicks;
94 OC1RS = u32_x+u16_triacPWHighTicks+u16_cycleOffsetTicks;
95 OC1CON = OC_TIMER2_SRC |
101 void configureTriacControl() {
103 configOutputCapture1();
111 void _ISRFAST _INT1Interrupt (
void) {
113 if (u8_currPowerSetting) TRIAC_ON();
117 void configSPI1(
void) {
119 SPI1CON1 = SEC_PRESCAL_1_1 |
121 CLK_POL_ACTIVE_HIGH |
128 CONFIG_SLAVE_ENABLE();
130 SPI1STATbits.SPIEN = 1;
141 float getCelsiusFloatTemp(
void) {
144 u16_x = readMAX6675();
152 int16_t getCelsiusI16Temp(
void) {
156 u16_x = readMAX6675();
157 u16_frac = (u16_x & 0x1F) >> 3;
159 if (u16_frac >= 2) u16_x++;
165 uint16_t volatile u16_tenthSeconds = 0;
167 void _ISRFAST _T3Interrupt (
void) {
172 #define ISR_PERIOD 100 // in ms
173 void configTimer3(
void) {
176 T3CON = T3_OFF |T3_IDLE_CON | T3_GATE_OFF
188 void decrementPower(
void) {
189 if (!u8_currPowerSetting)
return;
190 u8_currPowerSetting--;
193 void incrementPower(
void) {
194 if (u8_currPowerSetting == MAX_POWER_SETTING)
return;
195 u8_currPowerSetting++;
198 void setPower(
uint8_t newPower) {
199 u8_currPowerSetting = newPower;
203 return(u8_currPowerSetting);
207 void doMainMenu(
void) {
209 printf(
"Current profile: %s\n", getProfileDesc(u8_currentProfile));
210 printf(
"Reflow oven menu:\n");
211 printf(
" 'S' - start oven for current profile \n");
212 printf(
" 'p' - reflow profile menu \n");
213 printf(
" 'd' - debug menu\n");
214 printf(
"Enter character: ");
217 if (u8_c ==
'd') doDebugMenu();
218 if (u8_c ==
'p') doProfileMenu();
219 if (u8_c ==
'S') doReflow();
226 configureTriacControl();
227 CONFIG_ZEROCROSS_ENABLE();