void main(void) { LCD_Start(); LCD_Init(); LCD_InitBG(LCD_SOLID_BG ); PWM8_Start(); M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts INT_MSK0 |= 0x20; PRT0IE |= 0x01; PRT0DM0 = 0x01; //DM0[0-3] = 1 PRT0DM1 = 0x01; //DM1[0-3] = 0 PRT0DM2 = 0x00; //DM1[0-3] = 0 PRT0IC1 = 0x01; PRT0IC0 = 0x00; while(1){ if(pulsewidth==255){ pwDir = 1; } PWM8_WritePulseWidth(pulsewidth); LCD_DrawBG(0,0,16,pulsewidth/5); LCD_DrawBG(1,0,16,72); } }
void main(void) { unsigned long temp_ulong; INT temp_int, temp_int2; BYTE temp_byte; AMUX4_0_InputSelect(AMUX4_0_PORT0_1); AMUX4_1_InputSelect(AMUX4_1_PORT0_0); INSAMP_Start(INSAMP_LOWPOWER); ADCINC_Start(ADCINC_HIGHPOWER); DAC9_Ia_Start(DAC9_Ia_HIGHPOWER); DAC6_VGND_Start(DAC6_VGND_MEDPOWER); DAC6_VGND_WriteStall (31); PWM8_Vout_DisableInt(); PWM8_Vout_Start(); PWM8_Heater_DisableInt(); PWM8_Heater_Start(); PWM8_NB_Out_DisableInt(); PWM8_NB_Out_Start(); ADCINC_GetSamples(0); SleepTimer_Start(); SleepTimer_SetInterval(SleepTimer_512_HZ); SleepTimer_EnableInt(); M8C_EnableGInt ; LCD_Start(); // Initialize LCD LCD_InitBG(LCD_SOLID_BG); while(1) { temp_ulong++; if ((ADC_IF & 1) == 1) { ADC_IF = ADC_IF & 254; Ri_Min = IIR_Int(Ri_Min_x1*2,Ri_Min,Ri_Filter_Strength); Ri_Delta = Ri_Max - Ri_Min; Ri_Mid = (Ri_Max + Ri_Min) / 2; } if ((ADC_IF & 2) == 2) { ADC_IF = ADC_IF & 253; Ri_Max = IIR_Int(Ri_Max_x1 * 2, Ri_Max, Ri_Filter_Strength); Ri_Delta = Ri_Max - Ri_Min; Ri_Mid = (Ri_Max + Ri_Min) / 2; } if ((ADC_IF & 4) == 4) { ADC_IF = ADC_IF & 251; ip = IIR_Int(ip_x1 * 2, ip, ip_Filter_Strength); } Ia_PID_Counter += Sleep_Counter; Heater_PID_Counter += Sleep_Counter; Heatup_Counter += Sleep_Counter; Vout_Lookup_Counter += Sleep_Counter; LCD_Counter += Sleep_Counter; Sleep_Counter = 0; if (Ia_PID_Counter > Ia_PID_Counter_Set) { Ia_PID_Counter = 0; Ia_PID(); } if (Heater_PID_Counter > Heater_PID_Counter_Set) { Heater_PID_Counter = 0; Heater_PID(); } if (Vout_Lookup_Counter > Vout_Lookup_Counter_Set) {} Vout_Lookup_Counter = 0; temp_int = ip - ip_to_Vout_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Vout_Lookup_Size - 1)) { temp_int = (ip_to_Vout_Lookup_Size - 1); } PWM8_Vout_WritePulseWidth(ip_to_Vout_Lookup[temp_int]); #ifdef NB_Out temp_byte = 23;//0.45v if (ip < 251) { // 251 =0.9797787392968 temp_byte = 46; //0.9v } else if (ip > 259) { //259 = 1.02295956968912 temp_byte = 0; //0v } PWM8_NB_Out_WritePulseWidth(temp_byte); #endif } if (LCD_Counter > LCD_Counter_Set) { LCD_Counter = 0; #ifdef LCD_Lambda_Text temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) { temp_int=(ip_to_Lambda_Lookup_Size - 1); } Lambda_x100 = ip_to_Lambda_Lookup[temp_int]; temp_int = Lambda_x100; LCD_Position(0,0); temp_int2 = temp_int / 100; Str1[9] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str1[11] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str1[12] = btoa(temp_int); LCD_PrString(Str1); #endif #ifdef LCD_AFR_Text temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) { temp_int = (ip_to_Lambda_Lookup_Size - 1); } Lambda_x100=ip_to_Lambda_Lookup[temp_int]; temp_int = (INT) Lambda_x100 * 147; LCD_Position(0,0); temp_int2 = temp_int / 1000; Str1[6] = btoa(temp_int2); temp_int = temp_int - (1000 * temp_int2); temp_int2 = temp_int / 100; Str1[7] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str1[9] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str1[10] = btoa(temp_int); LCD_PrString(Str1); #endif #ifdef LCD_Lambda_Graph temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size-1)) { temp_int = (ip_to_Lambda_Lookup_Size - 1); } Lambda_x100 = ip_to_Graph_Lookup[temp_int]; LCD_DrawBG(0, 0, 16, Lambda_x100); #endif #ifdef LCD_Temperature_Text temp_int = Ri_Delta-Ri_Delta_to_Temperature_C_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) { temp_int = (Ri_Delta_to_Temperature_C_Size - 1); } LSU_Temperature_C = Ri_Delta_to_Temperature_C[temp_int] + Ri_Delta_to_Temperature_C_Offset; temp_int = LSU_Temperature_C; LCD_Position(1,0); temp_int2 = temp_int / 100; Str2[7] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str2[8] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str2[9] = btoa(temp_int); LCD_PrString(Str2); #endif #ifdef LCD_Temperature_Graph temp_int = Ri_Delta - Ri_Delta_to_Temperature_C_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) { temp_int = (Ri_Delta_to_Temperature_C_Size - 1); } LSU_Temperature_C = Ri_Delta_to_Graph[temp_int]; LCD_DrawBG(1, 0, 16, LSU_Temperature_C); #endif } if (Heatup_Heater_Output < 255) { if (Heatup_Counter > Heatup_Counter_Set) { Heatup_Counter = 0; Heatup_Heater_Output++; } if ((Ri_Min > 50) && (Ri_Max < 475) && (Ri_Delta < Ri_Delta_Target)) { Heatup_Heater_Output = 255; Ri_Delta_Error_Sum = 0; } } }