char Bot_Init(void) { // Initialize modules AD_Init(); PWM_Init(); // Configure digital pins IO_PortsSetPortOutputs(MUX_PINS_PORT, MUX_PINS_OR); IO_PortsSetPortOutputs(MOTOR_PINS_PORT, MOTOR_PINS_LEFT_DIR | MOTOR_PINS_RIGHT_DIR | MOTOR_PINS_LIFT_DIR | MOTOR_PINS_LIFT_EN); IO_PortsSetPortOutputs(SENSOR_PINS_PORT, SENSOR_PINS_LEDS); IO_PortsSetPortInputs(SENSOR_PINS_PORT, SENSOR_PINS_BUMP | SENSOR_PINS_TRACK); // Init lift motor to off IO_PortsClearPortBits(MOTOR_PINS_PORT, MOTOR_PINS_LIFT_EN); // Configure PWM pins // PWM_SetFrequency(PWM_BOT_FREQUENCY); // PWM_AddPins(MOTOR_PINS_LEFT_EN | MOTOR_PINS_RIGHT_EN); // Configure AD pins AD_AddPins(SENSOR_PINS_BEACON | SENSOR_PINS_TAPE); return SUCCESS; }
void EMG_Init() { AD_Init(); AD_AddPins(AD_PORTW4); // AD1 for EMG signal EMG_DIGIPOT_CS_OUT; EMG_DIGIPOT_CS_SET_LOW; EMG_DIGIPOT_INC_OUT; EMG_DIGIPOT_UD_OUT; EMG_reset(); return; }
int main(void) { unsigned int wait = 0; int readcount = 0; unsigned int CurPin = 0; unsigned int PinListing = 0; char FunctionResponse = 0; char TestFailed = FALSE; //SERIAL_Init(); //INTEnableSystemMultiVectoredInt(); BOARD_Init(); mJTAGPortEnable(0); printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times\r\n", TIMES_TO_READ); //printf("Value of pcfg before test: %X\r\n", AD1PCFG); // while(!IsTransmitEmpty()); //AD_Init(BAT_VOLTAGE); //AD_Init(); printf("Testing functionality before initialization\r\n"); /*adding pins individually */ printf("AD_AddPins on each pin indvidually which results in failure: "); for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) { FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != ERROR) { TestFailed = TRUE; break; } } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } TestFailed = FALSE; /*removing pins individually*/ printf("AD_RemovePins on each pin indvidually which results in failure: "); for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) { FunctionResponse = AD_RemovePins(CurPin); if (FunctionResponse != ERROR) { TestFailed = TRUE; break; } } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } TestFailed = FALSE; /*listing pins while inactive*/ printf("AD_ActivePins which should return 0: "); PinListing = AD_ActivePins(); if (PinListing != 0x0) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } // /*calling ned when inactive*/ // printf("AD_End which should fail: "); // FunctionResponse = AD_End(); // if (FunctionResponse != ERROR) { // printf("FAILED\r\n"); // } else { // printf("PASSED\r\n"); // } /*activating module*/ printf("initializing using AD_Init: "); FunctionResponse = AD_Init(); if (FunctionResponse != SUCCESS) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } /*attempting to reactivate*/ printf("initializing using AD_Init again returns error: "); FunctionResponse = AD_Init(); if (FunctionResponse != ERROR) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } printf("Testing Functionality after initialization\r\n"); /*active pins after activation only has battery*/ printf("Ad_ActivePins should only return BAT_VOLTAGE: "); PinListing = AD_ActivePins(); if (PinListing == BAT_VOLTAGE) { printf("PASSED\r\n"); } else { printf("FAILED\r\n"); } /*each pin added should succeed*/ printf("Adding each pin using AD_AddPins indivdually: "); for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) { PinListing = AD_ActivePins(); FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != SUCCESS) { TestFailed = TRUE; break; } while (AD_ActivePins() != (PinListing | CurPin)); } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } /*removing each pin should succeed */ printf("Removing each pin using AD_RemovePins indivdually: "); for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) { PinListing = AD_ActivePins(); FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != SUCCESS) { TestFailed = TRUE; break; } while (AD_ActivePins() != (PinListing | CurPin)); } if (TestFailed) { printf("FAIL: %X\r\n", 0xFEED); } else { printf("PASSED\r\n"); } while (1); printf("We will now add the odd pins and wait for them to be activated"); AD_AddPins(ODD_ACTIVE); while (!(AD_ActivePins() & ODD_ACTIVE)) { if (IsTransmitEmpty()) { printf("%X\r\n", AD_ActivePins()); } } printf("The Odd pins are now active as shown by Active pins: %X\r\n", AD_ActivePins()); printf("We will now enable the even pins and wait for them to be activated"); AD_AddPins(EVEN_ACTIVE); while (!(AD_ActivePins() & EVEN_ACTIVE)); printf("The Even pins are now active as shown by Active pins: %X\r\n", AD_ActivePins()); char numtoread = NUM_AD_PINS; unsigned char cur = 0; DELAY(400000) while (readcount <= TIMES_TO_READ) { DELAY(100000); printf("\r\n"); for (cur = 0; cur < numtoread; cur++) { printf("%d\t", AD_ReadADPin(1 << cur)); } printf("\r\n"); readcount++; } printf("Done Reading Them\r\n"); AD_End(); printf("Value of pcfg after test: %X", AD1PCFG); return 0; }