/***************************************************************************//** * @brief * Active wait millisecond delay function. Can also be used inside * interrupt handlers. * * @param[in] msec * Number of milliseconds to wait. ******************************************************************************/ void USBTIMER_DelayMs( uint32_t msec ) { uint64_t totalTicks; totalTicks = (uint64_t)ticksPrMs * msec; while ( totalTicks > 20000 ) { DelayTicks( 20000 ); totalTicks -= 20000; } DelayTicks( (uint16_t)totalTicks ); }
/***************************************************************************//** * @brief * Active wait microsecond delay function. Can also be used inside * interrupt handlers. * * @param[in] usec * Number of microseconds to wait. ******************************************************************************/ void USBTIMER_DelayUs( uint32_t usec ) { uint64_t totalTicks; totalTicks = (uint64_t)ticksPr1us * usec; if ( totalTicks == 0 ) { usec /= 10; totalTicks = (uint64_t)ticksPr10us * usec; if ( totalTicks == 0 ) { usec /= 10; totalTicks = (uint64_t)ticksPr100us * usec; } } while ( totalTicks > 60000 ) { DelayTicks( 60000 ); totalTicks -= 60000; } DelayTicks( (uint16_t)totalTicks ); }
void TGT_Revive() { IO_LEDv12 = 1; if(!IS_AT_HPOS) MOTOR_ON; while(!IS_AT_HPOS); MOTOR_OFF; DelayTicks(50); if(!IS_AT_VPOS) MOTOR_ON; while(!IS_AT_VPOS); MOTOR_OFF; IO_LEDv12 = 0; }
// private function to read characters from stream // the constructors allow one and only one of the streams to be initialized boolean WideTextFinder::read(char &recaivedByte) //blocking read, { // char r; startMillis = BASE_VALUE; if (nSerialStream != NULL) { while(0 < (startMillis + timeout)) { if (nSerialStream->read(recaivedByte)) //nonblocking read, { // if(debug) // Serial.print(r); return true; } DelayTicks(10); startMillis--; } } return false; // 0 indicates timeout }
void main() { int dac_mode; float min_volts, max_volts; float phase_shift; int index_shift; int channel; int key; int wave; int i; int length; char display[128]; char tmpbuf[32]; // Initialize controller brdInit(); DispStr(1, 2, "DAC output voltage configuration"); DispStr(1, 3, "Dependant on jumper settings (see Instructions)"); DispStr(1, 4, "--------------------------------"); DispStr(1, 5, "0 = Unipolar 0 to +10v"); DispStr(1, 6, "1 = Bipolar -10 to +10v"); DispStr(1, 8, "Please enter the DAC configuration 0 - 1 = "); do { key = getchar() - '0'; } while (key < 0 || key > 1); printf("%d", key); // Configure the DAC for given configuration dac_mode = (key == 0 ? DAC_UNIPOLAR : DAC_BIPOLAR); anaOutConfig(dac_mode, DAC_SYNC); // set the min and max voltage based on DAC mode. max_volts = 10.0; min_volts = (dac_mode == DAC_BIPOLAR ? -10.0 : 0.0); // Initialize the DAC to output zero volts at the start anaOutVolts(CH0, 0); anaOutVolts(CH1, 0); anaOutStrobe(CH0_AND_CH1); channel_waveform[0] = SQUARE_WAVE; channel_waveform[1] = SINE_WAVE; // initialize waveform variables dac1_index = dac0_index = 0; phase_shift = 0; for (wave = 0; wave < NUM_WAVES; ++wave) { calc_waveform(waveform_signals[wave], ARRAY_SIZE, calc[waveform[wave]], min_volts, max_volts); } // print the menu once here, but it is located below "values table". DispStr(2, 16, "User Options:"); DispStr(2, 17, "-------------"); DispStr(2, 18, "1. Set waveform for DAC0."); DispStr(2, 19, "2. Set waveform for DAC1."); DispStr(2, 20, "3. Set phase shift."); while(1) { costate { // clear lines clearLines(12, 14); // print the current waveforms sprintf(display, "Current Waveforms: at %dHz", (int) WAVE_FREQUENCY); DispStr(2, 10, display); DispStr(2, 11, "----------------------------"); sprintf(display, "DAC0 = %s", waveform_names[channel_waveform[0]]); DispStr(2, 12, display); sprintf(display, "DAC1 = %s", waveform_names[channel_waveform[1]]); DispStr(2, 13, display); sprintf(display, "phase shift = %.2f%%", phase_shift); DispStr(2, 14, display); // NOTE: menu goes here sequentually, it is printed once above. // get response for menu choice do { waitfor(kbhit()); key = getchar() - '0'; } while (key < 0 || key > 3); switch (key) { case 1: // DAC 0: re-assign waveform case 2: // DAC 1: re-assign waveform channel = key - 1; // calculate channel from menu option. do { // display waveform options for (i = 0; i < NUM_WAVES; ++i) { sprintf(display, "%d: %s: ", i+1, waveform_names[i]); DispStr(3, 23+i, display); } sprintf(display, "Enter waveform for channel %d: ", channel); DispStr(3, 27, display); waitfor(kbhit()); wave = getchar() - '1'; } while (wave < 0 || wave >= NUM_WAVES); channel_waveform[channel] = wave; clearLines(23, 27); // clear the optional input line after the menu break; case 3: // re-assign phase shift do { sprintf(display, "Enter phase shift percentage (0 to 100): "); DispStr(3, 23, display); // Note: gets is a blocking function and will stop waveform. phase_shift = atof(gets(tmpbuf)); } while (phase_shift < 0 || phase_shift > 100); index_shift = (int) ((phase_shift * ARRAY_SIZE) / 100.0); dac1_index = (dac0_index + index_shift) % ARRAY_SIZE; clearLines(23, 23); // clear the optional input line after the menu break; } } costate { waitfor(DelayTicks(1)); anaOutStrobe(CH0_AND_CH1); anaOutVolts(CH0, waveform_signals[channel_waveform[CH0]][dac0_index]); anaOutVolts(CH1, waveform_signals[channel_waveform[CH1]][dac1_index]); dac0_index = (dac0_index + 1) % ARRAY_SIZE; dac1_index = (dac1_index + 1) % ARRAY_SIZE; } } // while (1) }