void main(void) { // Insert your main routine code here. unsigned char c = 0; M8C_EnableGInt; UART_EnableInt(); UART_Start(UART_PARITY_NONE); PGA_1_Start(PGA_1_HIGHPOWER); ADCINC_Start(ADCINC_HIGHPOWER); // Apply power to the SC Block ADCINC_GetSamples(0); DAC6_Start(DAC6_HIGHPOWER); PWM8_DisableInt(); PWM8_Start(); for(;;) { PWM8_WritePulseWidth(m_to_s_mem[0]); DAC6_WriteBlind(m_to_s_mem[1]); //if ( DELSIG8_bfStatus ) { // DELSIG8_bfStatus = 0; // s_to_m_mem[0] = DELSIG8_cResult; //} //ADCINC_GetSamples(1); //while(ADCINC_fIsDataAvailable() == 0); //s_to_m_mem[0] = ADCINC_bClearFlagGetData(); } //mainloop: // UART_SendData(temp++); //while( ++temp2 ); //goto mainloop; }
// AMUX4_PORT0_0 => 0x00 // AMUX4_PORT0_2 => 0x01 // AMUX4_PORT0_4 => 0x02 // AMUX4_PORT0_6 => 0x03 int get_adc(BYTE amux_channel){ AMUX4_InputSelect(amux_channel); wait(10); ADCINC_GetSamples(0); while(!ADCINC_fIsDataAvailable()); return ADCINC_iClearFlagGetData(); }
/************************************************************************ * MeasureTemperature read temperature sensor voltage * * Parameters: none * Returns: none ************************************************************************/ void MeasureTemperature(void) { if (ADCINC_fIsDataAvailable()) { Temperature = ADCINC_iClearFlagGetData(); // Clear ADC flag and get data ADCINC_GetSamples(1); // start the next sample } }
void main(void) { int result; float voltage; int status; M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts // Insert your main routine code here. //Start PGA in high power mode PGA_Start(PGA_HIGHPOWER); //Start ADCINC in high power mode ADCINC_Start(ADCINC_HIGHPOWER); //Start LCD LCD_Start(); //Run the ADC continuously ADCINC_GetSamples(0); SleepTimer_Start(); SleepTimer_SetInterval(SleepTimer_1_HZ); SleepTimer_EnableInt(); while (1) { SleepTimer_SyncWait(1, SleepTimer_WAIT_RELOAD); // Wait for data to be ready while (ADCINC_fIsDataAvailable() == 0); // Get Data and clear flag result=ADCINC_iClearFlagGetData(); voltage = result * SCALE_FACTOR; LCD_Position(0, 0); LCD_PrCString(" "); LCD_Position(0, 0); LCD_PrHexInt(result); LCD_Position(1, 0); LCD_PrCString(" "); LCD_Position(1, 0); LCD_PrString(ftoa(voltage, &status)); } }
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; } } }
void main(void) { // Initialize Pull Up/Down ressistors //Port_0_Data_SHADE = 0x80; // Enable distance input pull-up P0.7 //PRT0DR = Port_0_Data_SHADE; Port_2_Data_SHADE = 0x04; // Enable pull-down resistor on LED P2.2 PRT2DR = Port_2_Data_SHADE; Port_3_Data_SHADE = 0x20; // Enable pull-up on button bit P3.5 PRT3DR = Port_3_Data_SHADE; Port_4_Data_SHADE = 0x44; // Enable pull-down LED P4.2, P4.6 PRT4DR = Port_4_Data_SHADE; Timer8_WritePeriod(50); // 12MHz/15/16/50 = 1KHz => 1ms main timer interrupt Timer8_WriteCompareValue(0); Timer8_EnableInt(); Timer8_Start(); PRS8_WritePolynomial(0x78); // load the PRS polynomial PRS8_WriteSeed(0xFF); // load the PRS seed PRS8_Start(); // start the PRS8 RED_Start(); GREEN_Start(); BLUE_Start(); PWM8_WritePeriod(100); // set period to eight clocks PWM8_WritePulseWidth(0); // set pulse width to generate a % duty cycle PWM8_EnableInt(); // ensure interrupt is enabled PWM8_Start(); // start PWM //DAC_CR &= ~0x80; // turn off SplitMUX bit 7 (P0[7] on right, others on left) PGA_Start(PGA_HIGHPOWER); // Start PGA ADCINC_Start(ADCINC_HIGHPOWER); // Start ADC ADCINC_GetSamples(1); // initiate the first sample M8C_EnableGInt; // Global interrupt enable ReadFlash(); // read on/off times and LED dutycyle from FLASH if(!(RamFlashBlock.Dummy == 0x55)) { SetFlashDefaults(); // clear flash first time } LedPowerTog = 1; // flag change LedPower = RamFlashBlock.PowerState; RedDutyMax = RamFlashBlock.RedDuty; BlueDutyMax = RamFlashBlock.BlueDuty; GreenDutyMax = RamFlashBlock.GreenDuty; the_state = RamFlashBlock.the_state; ledChangeRate = RamFlashBlock.ledChangeRate; Events.press = 0; Events.hold = 0; Events.release = 0; MenuFsm(&Events, &the_state); // initlaize the state machine USB_Start(0, USB_3V_OPERATION); // Start USB //while (!USB_bGetConfiguration()); // Wait to be enumerated USB_INT_REG |= USB_INT_SOF_MASK; USB_EnableOutEP(1); // Post a buffer to wait for a command while(1) // cycle the puck here { MeasureTemperature(); // sample input temperature sensor voltage ThermalProtection(); // decrease LED power if temperature rises above limit ButtonStates(); // button driver CommunicateUSB(); // USB driver LedStates(); // LED Cadence state machine DelayedSaveFlash(); // Save power state and RGB dutycycle 10 seconds after last button event } }