// // File: arduinoTestVector.cpp // // Code generated for Simulink model 'arduinoTestVector'. // // Model version : 1.229 // Simulink Coder version : 8.6 (R2014a) 27-Dec-2013 // C/C++ source code generated on : Thu May 22 14:47:55 2014 // // Target selection: arduino_ec.tlc // Embedded hardware selection: Atmel->AVR // Code generation objectives: // 1. Execution efficiency // 2. ROM efficiency // 3. RAM efficiency // Validation result: Not run // #include "arduinoTestVector.h" // Constant parameters (auto storage) const ConstParam_arduinoTestVector arduinoTestVector_ConstP = { // Expression: myData // Referenced by: '<S1>/Constant1' { 0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51, 52, 54, 55, 56, 57, 59, 60, 61, 62, 0, -1, -3, -4, -5, -6, -8, -9, -10, -11, -13, -14, -15, -17, -18, -19, -20, -22, -23, -24, -26, -27, -28, -29, -31, -32, -33, -34, -36, -37, -38, -40, -41, -42, -43, -45, -46, -47, -48, -50, -51, -52, -54, -55, -56, -57, -59, -60, -61, -62, 0, 3, 5, 8, 10, 13, 15, 18, 20, 23, 26, 28, 31, 33, 36, 38, 41, 43, 46, 48, 51, 54, 56, 59, 61, 64, 66, 69, 71, 74, 77, 79, 82, 84, 87, 89, 92, 94, 97, 99, 102, 105, 107, 110, 112, 115, 117, 120, 122, 125, 0, -3, -5, -8, -10, -13, -15, -18, -20, -23, -26, -28, -31, -33, -36, -38, -41, -43, -46, -48, -51, -54, -56, -59, -61, -64, -66, -69, -71, -74, -77, -79, -82, -84, -87, -89, -92, -94, -97, -99, -102, -105, -107, -110, -112, -115, -117, -120, -122, -125, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; // Block signals (auto storage) BlockIO_arduinoTestVector arduinoTestVector_B; // Block states (auto storage) D_Work_arduinoTestVector arduinoTestVector_DWork; // Model step function void arduinoTestVector_step(void) { // local block i/o variables uint8_T rtb_MOTORSHIELD_IN1; uint8_T rtb_MOTORSHIELD_IN2; uint8_T rtb_Abs; boolean_T aVarTruthTableCondition_1; boolean_T aVarTruthTableCondition_2; boolean_T aVarTruthTableCondition_3; uint16_T rtb_Init; // Outputs for Enabled SubSystem: '<Root>/ENABLE_TEST' incorporates: // EnablePort: '<S1>/Enable' // S-Function (sfunar_digitalInput): '<Root>/RUN_TEST' if (((uint8_T)digitalRead(((uint8_T)2U))) > 0) { if (!arduinoTestVector_DWork.ENABLE_TEST_MODE) { // InitializeConditions for UnitDelay: '<S1>/Unit Delay' arduinoTestVector_DWork.UnitDelay_DSTATE = false; // InitializeConditions for UnitDelay: '<S4>/FixPt Unit Delay2' arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 1U; // InitializeConditions for UnitDelay: '<S4>/FixPt Unit Delay1' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U; arduinoTestVector_DWork.ENABLE_TEST_MODE = true; } // Switch: '<S4>/Init' incorporates: // Constant: '<S4>/Initial Condition' // Logic: '<S4>/FixPt Logical Operator' // UnitDelay: '<S1>/Unit Delay' // UnitDelay: '<S4>/FixPt Unit Delay1' // UnitDelay: '<S4>/FixPt Unit Delay2' if (arduinoTestVector_DWork.UnitDelay_DSTATE || (arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE != 0)) { rtb_Init = 0U; } else { rtb_Init = arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE; } // End of Switch: '<S4>/Init' // Selector: '<S1>/Selector' incorporates: // Constant: '<S1>/Constant1' arduinoTestVector_B.Selector = arduinoTestVector_ConstP.Constant1_Value [(int16_T)rtb_Init]; // Switch: '<S4>/Reset' incorporates: // UnitDelay: '<S1>/Unit Delay' if (arduinoTestVector_DWork.UnitDelay_DSTATE) { // Update for UnitDelay: '<S4>/FixPt Unit Delay1' incorporates: // Constant: '<S4>/Initial Condition' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U; } else { // Update for UnitDelay: '<S4>/FixPt Unit Delay1' incorporates: // Constant: '<S1>/Constant' // Sum: '<S1>/Add' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = rtb_Init + 1U; } // End of Switch: '<S4>/Reset' // Update for UnitDelay: '<S1>/Unit Delay' incorporates: // Constant: '<S3>/Constant' // RelationalOperator: '<S3>/Compare' arduinoTestVector_DWork.UnitDelay_DSTATE = (rtb_Init == 500U); // Update for UnitDelay: '<S4>/FixPt Unit Delay2' incorporates: // Constant: '<S4>/FixPt Constant' arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 0U; } else { if (arduinoTestVector_DWork.ENABLE_TEST_MODE) { // Disable for Outport: '<S1>/TEST_OUT' arduinoTestVector_B.Selector = 0; arduinoTestVector_DWork.ENABLE_TEST_MODE = false; } } // End of S-Function (sfunar_digitalInput): '<Root>/RUN_TEST' // End of Outputs for SubSystem: '<Root>/ENABLE_TEST' // Truth Table: '<Root>/Truth Table' // Truth Table Function 'Truth Table': '<S2>:1' // ClockWise // Condition '#1': '<S2>:1:10' aVarTruthTableCondition_1 = (arduinoTestVector_B.Selector > 0); // CounterClockWise // Condition '#2': '<S2>:1:14' aVarTruthTableCondition_2 = (arduinoTestVector_B.Selector < 0); // Stop // Condition '#3': '<S2>:1:18' aVarTruthTableCondition_3 = (arduinoTestVector_B.Selector == 0); if ((!aVarTruthTableCondition_1) && (!aVarTruthTableCondition_2) && aVarTruthTableCondition_3) { // Decision 'D1': '<S2>:1:20' // Stop // Action '3': '<S2>:1:48' rtb_MOTORSHIELD_IN1 = 0U; // Action '3': '<S2>:1:49' rtb_MOTORSHIELD_IN2 = 0U; } else { // Decision 'D2': '<S2>:1:20' if (aVarTruthTableCondition_1 && (!aVarTruthTableCondition_2) && (!aVarTruthTableCondition_3)) { // Decision 'D2': '<S2>:1:22' // ClockWise // Action '1': '<S2>:1:34' rtb_MOTORSHIELD_IN1 = 1U; // Action '1': '<S2>:1:35' rtb_MOTORSHIELD_IN2 = 0U; } else { // Decision 'D3': '<S2>:1:22' if ((!aVarTruthTableCondition_1) && aVarTruthTableCondition_2 && (!aVarTruthTableCondition_3)) { // Decision 'D3': '<S2>:1:24' // CounterClockWise // Action '2': '<S2>:1:41' rtb_MOTORSHIELD_IN1 = 0U; // Action '2': '<S2>:1:42' rtb_MOTORSHIELD_IN2 = 1U; } else { // Decision 'D4': '<S2>:1:24' // Decision 'D4': '<S2>:1:26' // Default // None // Action '4': '<S2>:1:55' rtb_MOTORSHIELD_IN1 = 0U; // Action '4': '<S2>:1:56' rtb_MOTORSHIELD_IN2 = 0U; } } } // End of Truth Table: '<Root>/Truth Table' // S-Function (sfunar_digitalOutput): '<Root>/MOTORSHIELD_IN1' digitalWrite(((uint8_T)8U), rtb_MOTORSHIELD_IN1); // S-Function (sfunar_digitalOutput): '<Root>/MOTORSHIELD_IN2' digitalWrite(((uint8_T)11U), rtb_MOTORSHIELD_IN2); // Abs: '<Root>/Abs' if (arduinoTestVector_B.Selector < 0) { rtb_Abs = (uint8_T)-arduinoTestVector_B.Selector; } else { rtb_Abs = (uint8_T)arduinoTestVector_B.Selector; } // End of Abs: '<Root>/Abs' // S-Function (sfunar_analogOutput): '<Root>/SPEEDPIN_A' analogWrite(((uint8_T)9U), rtb_Abs); } // Model initialize function void arduinoTestVector_initialize(void) { // Registration code // block I/O (void) memset(((void *) &arduinoTestVector_B), 0, sizeof(BlockIO_arduinoTestVector)); // states (dwork) (void) memset((void *)&arduinoTestVector_DWork, 0, sizeof(D_Work_arduinoTestVector)); // S-Function (sfunar_digitalInput): <Root>/RUN_TEST pinMode(((uint8_T)2U), INPUT); // InitializeConditions for Enabled SubSystem: '<Root>/ENABLE_TEST' // InitializeConditions for UnitDelay: '<S1>/Unit Delay' arduinoTestVector_DWork.UnitDelay_DSTATE = false; // InitializeConditions for UnitDelay: '<S4>/FixPt Unit Delay2' arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 1U; // InitializeConditions for UnitDelay: '<S4>/FixPt Unit Delay1' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U; // End of InitializeConditions for SubSystem: '<Root>/ENABLE_TEST' // S-Function (sfunar_digitalOutput): <Root>/MOTORSHIELD_IN1 pinMode(((uint8_T)8U), OUTPUT); // S-Function (sfunar_digitalOutput): <Root>/MOTORSHIELD_IN2 pinMode(((uint8_T)11U), OUTPUT); // S-Function (sfunar_analogOutput): <Root>/SPEEDPIN_A pinMode(((uint8_T)9U), OUTPUT); } // // File trailer for generated code. // // [EOF] //