int main (void) { HW_Init(); // enquanto a tensão de entrada estiver abaixo de 8V e acima de 16V, não faz nada do { ADCSRA |= (1<<ADSC); while (ADCSRA & (1<<ADSC)); } while ((ADC < MIN_VI_COUNT) || (ADC > MAX_VI_COUNT)); VoltInp = ADC; ADMUX = ((1<<REFS0) | (1<<REFS1)) + VOUT_CH; // feedback do conversor boost ADCSRA |= (1<<ADIF) | (1<<ADIE); // limpa o flag e habilita interrupção do ADC tPIsat_params.w_kp_pu = eeprom_read_word(&ee_PI_kp); tPIsat_params.w_ki_pu = eeprom_read_word(&ee_PI_ki); tPIsat_params.sp = eeprom_read_word(&ee_PI_SP); ADCSRA |= (1<<ADSC); // Inicia primeira leitura do ADC sei(); uart_puts_P(PSTR("Inicio VFD\r")); vfd_setstring("Felipe Maimon"); for(;;) { State_Machine(); } }
/************************************************************** * Name : SchM_12p5ms_Task * Description : * Parameters : [Input, Output, Input / output] * Return : * Critical/explanation : [yes / No] **************************************************************/ void SchM_5ms_Task(void) { State_Machine(); }
/**Program Entry Point*/ int main() { JOINT joints[2]; STATE_FLAGS flags; OBJECT_LOCATION objLoc; DATA_PACK dataPack; char state = 0; char input; //initialize pointers in mlMessage dataPack.flags = &flags; dataPack.joint = &joints[0]; dataPack.location = &objLoc; //Set initial values for the state flags flags._FLAGS = 0; //Set initial values for the joints joints[0].linkLength = 200; joints[0].targetVal = 0; joints[0].currentVal = 0; joints[0].LMDVal = 0; joints[0].correctionVal = 0; joints[1].linkLength = 195; joints[1].targetVal = 0; joints[1].currentVal = 0; joints[1].LMDVal = 0; joints[1].correctionVal = 0; //Set direction registers for debugging use DDRD = 0xFF; DDRC = 0x00; //Initialize serial communications, the ADC, the DAC and PID control Init_Serial_P(BAUD576, FRM8, STOP1, NOPAR); ADC_Init_P(); DAC_Initilize(); PID_Initialize(); Serial_Print_String("\r\nMag Pickup Test\r\n"); /*while(1) { Serial_Print_String("\r\nIR_X: "); Serial_Print_Int(ReadIR(IR_X), 10); Serial_Print_String("\r\nIR_Y: "); Serial_Print_Int(ReadIR(IR_Y), 10); _delay_ms(200); }*/ //Calibrate joint pots Add_Pot_Angle(542, 90, 175, 0, "Joint 1", JOINT1); Add_Pot_Angle(504, 90, 849, 0, "Joint 2", JOINT2); //Add PID channels to control the two joints PID_Add_Channel(&joints[0].targetVal, &joints[0].currentVal, &joints[0].correctionVal, &joints[0].LMDVal, 450, 50, 300, 250); PID_Add_Channel(&joints[1].targetVal, &joints[1].currentVal, &joints[1].correctionVal, &joints[1].LMDVal, 375, 10, 350, 150); while(1) { joints[0].currentVal = ADC_Get_Value(JOINT1); joints[1].currentVal = ADC_Get_Value(JOINT2); joints[0].targetVal = Degrees_To_Pot(30, JOINT1); joints[1].targetVal = Degrees_To_Pot(60, JOINT2); State_Machine(&state, &dataPack); /*Serial_Print_String("\r\nTarget: "); Serial_Print_Int(Pot_To_Degrees(joints[1].targetVal, JOINT2), 10); Serial_Print_String("\r\nCurrent: "); Serial_Print_Int(Pot_To_Degrees(joints[1].currentVal, JOINT2), 10);*/ _delay_ms(100); } }
void SchM_Task_3p125ms(void) { State_Machine(); }