int main(int argc, char *argv[]) { int numBoards; float shape_data0[1024]; // Waveform for the pulse shape float shape_data1[1024]; // Waveform for the pulse shape //float dds_data[1024]; // Waveform for the DDS signal itself (normally a sinewave) //Uncommenting the line below will generate a debug log in your current directory //that can help debug any problems that you may be experiencing //pb_set_debug(1); printf ("Copyright (c) 2010 SpinCore Technologies, Inc.\n\n"); printf("Using SpinAPI library version %s\n", pb_get_version()); if((numBoards = detect_boards()) > 1) { /*If there is more than one board in the system, have the user specify.*/ select_board(numBoards); /*Request the board numbet to use from the user*/ } if (pb_init () != 0) { printf ("Error initializing board: %s\n", pb_get_error ()); system("read -p \"Press enter to continue\""); return -1; } //Use the following functions to create an arbitrary envelope for your RF signal shape_make_ramp (shape_data0); //calculate a ramp shape and store in shape_data0 shape_make_revramp (shape_data1); //create a reveresed ramp shape and store in shape_data1 printf("This program shows how the DDS-II Shape RAM data for the PBDDS-II can be written " "'on-the-fly'.\n\n Simply execute this program while the dds2_awg.exe program is " "running. The envelope shape of the signal on channel 1 will change to a ramp, a " "linear increase in amplitude from 0 to 1, and the envelope shape of the signal on " "channel 2 will change to a reverse ramp, a linear decrease in amplitude from 1 to " "0.\n\n"); pb_core_clock(CLOCK_FREQ); //Set the PB core clock value. system("read -p \"Press enter to continue\""); /****** THIS SECTION PROGRAMS REGISTERS FOR CHANNEL 1 (DDS0) ******/ pb_select_dds(0); //Select DDS0 (this is selected by default.) pb_start_programming(TX_PHASE_REGS); pb_set_phase(75.0); pb_stop_programming(); pb_dds_load (shape_data0, DEVICE_SHAPE); //Th //pb_dds_load (dds_data, DEVICE_DDS); //The shape of the actual DDS signal can be modified as well /**********************************************************************/ /***** THIS SECTION PROGRAMS REGISTERS FOR CHANNEL 2 (DDS1) *****/ pb_select_dds(1); //Select DDS1. pb_dds_load (shape_data1, DEVICE_SHAPE); /************************************************************************/ pb_close(); return 0; }
int pb_init_multi(mp_int *characteristic, pb_poly *pb, ...) { mp_err res = MP_OKAY; /* Assume ok until proven otherwise */ int n = 0; /* Number of ok inits */ pb_poly* cur_arg = pb; va_list args; va_start(args, pb); /* init args to next argument from caller */ while (cur_arg != NULL) { if (pb_init(cur_arg, characteristic) != MP_OKAY) { /* Oops - error! Back-track and mp_clear what we already succeeded in init-ing, then return error. */ va_list clean_args; /* end the current list */ va_end(args); /* now start cleaning up */ cur_arg = pb; va_start(clean_args, pb); while (n--) { pb_clear(cur_arg); cur_arg = va_arg(clean_args, pb_poly*); } va_end(clean_args); res = MP_MEM; break; } n++; cur_arg = va_arg(args, pb_poly*); }
static void jargrep(regex_t *exp, regex_t *nl_exp, const char *jarfile, int options){ int fd; int floop = TRUE; pb_file pbf; ub1 scratch[16]; if((fd = open(jarfile, O_RDONLY)) == -1) { if(!(options & JG_SUPRESS_ERROR)) fprintf(stderr, "Error reading file '%s': %s\n", jarfile, strerror(errno)); } else { pb_init(&pbf, fd); do { if(pb_read(&pbf, scratch, 4) != 4) { perror("read"); floop = FALSE; } else { switch (check_sig(scratch, &pbf)) { case 0: floop = cont_grep(exp, nl_exp, fd, &pbf, options); break; case 1: floop = FALSE; break; case 2: continue; /* fall through continue */ } } } while(floop); } }
int main(int argc, const char ** argv) { int start=0,sub=0; double clock_freq=CLOCK_FREQ; //if argument present if (argc > 1) { clock_freq = atof(argv[1]); } printf ("Using spinapi library version %s\n", pb_get_version()); if (pb_init() != 0) { printf("Error Initializing PulseBlaster: %s\n", pb_get_error()); return -1; } printf("Using clock frequency:%.2fMHz\n\n", clock_freq); printf("BNCs 0-3 will output a train of pulses, each high for 50 ns, followed by ground level for 250 ns. This pattern will then repeat.\n\n"); // Tell driver what clock frequency the board uses pb_set_clock(clock_freq); //Begin pulse program pb_start_programming(PULSE_PROGRAM); //Instruction format //int pb_inst(int flags, int inst, int inst_data, int length) // Instruction 0 - continue to inst 1 in 100ns start = pb_inst(0x0,CONTINUE,0,100.0*ns); // Instruction 1 - Jump to subroutine sub = 3; pb_inst(0, JSR, sub,50.0*ns); // Instruction 2 - Branch back to the beginning of the program // (instruction 0) pb_inst(0x0,BRANCH,start,100.0*ns); // Instruction 3 - This is the start of the subroutine. Turn on // the BNC outputs for 50ns, and then return to the instruction // immediately after the JSR instruction that called this. In this // pulse program, the next instruction that will be executed is // instruction 2. pb_inst(ON|0xF,RTS,0,50.0*ns); // End of programming registers and pulse program pb_stop_programming(); // Trigger the pulse program pb_start(); pb_close(); system("pause"); return 0; }
int configureBoard(SCANPARAMS* myScan) { float shape_data[1024]; double actual_SW; double wait_time; double spectralWidth_MHZ = myScan->spectralWidth / 1000.0; int dec_amount; int cmd = 0; int num_lobes = 3; if(pb_init()) { printf ("Error initializing board: %s\n", pb_get_error()); return -1; } pb_set_defaults(); pb_set_clock(myScan->adcFrequency); pb_zero_ram(); // clear RAM to all zeros pb_overflow(1,0); // reset the overflow counters pb_scan_count(1); // reset scan counter // Load the shape parameters make_shape_data(shape_data, (void*)&num_lobes, shape_sinc); pb_dds_load(shape_data, DEVICE_SHAPE); pb_set_amp(((myScan->enable_tx)?myScan->amplitude:0), 0); // /// Set acquisition parameters /// if (myScan->bypass_fir) { cmd = BYPASS_FIR; } dec_amount = pb_setup_filters(spectralWidth_MHZ, myScan->nScans, cmd); pb_set_num_points(myScan->nPoints); if(dec_amount <= 0) { if(myScan->verbose) printf("Error: Invalid data returned from pb_setup_filters(). Please check your board."); return INVALID_DATA_FROM_BOARD; } actual_SW = (myScan->adcFrequency*1e6)/(double)dec_amount; myScan->actualSpectralWidth = actual_SW; wait_time = 1000.0 * (((double)myScan->nPoints)/actual_SW); // time in ms myScan->wait_time = wait_time; return 0; }
int main(int argc, char **argv) { int start; //uncomment to turn on debug messages //pb_set_debug(1);//turns on debug messages. They will appear in log.txt printf ("Using spinapi library version %s\n", pb_get_version()); if(pb_init()) { printf ("Error initializing board: %s\n", pb_get_error()); system("pause"); return -1; } pb_set_defaults(); pb_set_clock(CLOCK_FREQ); printf("Clock frequency: %.2lfMHz\n\n", CLOCK_FREQ); printf("This example program tests the excitation PulseBlaster DDS 300. This program will produce a 1MHz signal on the oscilloscope that is on for 8 microseconds, cycling through four pahse offsets. It will turn off for 1 milisecond, and will then repeat this pattern.\n\n"); // Program the first 2 frequency registers, there are 16 available for the PBDDS-1-300 pb_start_programming(FREQ_REGS); pb_set_freq(1.0*MHz); // Register 0 pb_set_freq(1.0*MHz); // Register 1 pb_stop_programming(); // Program the first 2 phase registers, there are 16 available for the PBDDS-1-300 pb_start_programming(TX_PHASE_REGS); pb_set_phase(0.0); // Register 0 pb_set_phase(0.0); // Register 1 pb_stop_programming(); // Write the pulse program pb_start_programming(PULSE_PROGRAM); //pb_inst_dds(freq, tx_phase, tx_enable, phase_reset, flags, // inst, inst_data, length) start = pb_inst_dds(1, 1, TX_ENABLE, NO_PHASE_RESET, 0x1FF, CONTINUE, 0, 10.0*us); pb_inst_dds(1, 1, TX_DISABLE, PHASE_RESET, 0x000, BRANCH, start, 1.0*ms); pb_stop_programming(); // Trigger program pb_start(); // Release control of the board pb_close(); system("pause"); return 0; }
int main() { int start, status, i; //pb_select_board(0); // pb_set_debug(1); printf ("Using spinapi library version %s\n", pb_get_version()); if(pb_init() != 0) { printf ("Error initializing board: %s\n", pb_get_error()); return -1; } printf("Clock frequency: 100.00MHz\n\n"); printf("All outputs should now be turning on and off with a period of 400ms and 50 percent duty cycle.\n\n"); // Tell the driver what clock frequency the board has (in MHz) pb_set_clock(100.0); pb_start_programming(PULSE_PROGRAM); // Instruction 0 - Continue to instruction 1 in 100ms // Flags = 0xFFFFFF, OPCODE = CONTINUE start = pb_inst(0xFFFFFF, CONTINUE, 0, 200.0*ms); // Instruction 1 - Continue to instruction 2 in 100ms // Flags = 0x0, OPCODE = CONTINUE pb_inst(0x0, CONTINUE, 0, 100.0*ms); // Instruction 2 - Branch to "start" (Instruction 0) in 100ms // 0x0, OPCODE = BRANCH, Target = start pb_inst(0x0, BRANCH, start, 100.0*ms); pb_stop_programming(); // Trigger the pulse program pb_start(); //Read the status register status = pb_read_status(); printf("status: %d \n", status); pb_close(); system("pause"); return 0; }
int main(int argc, char **argv) { printf ("Using spinapi library version %s\n", pb_get_version()); if(pb_init()) { printf ("Error initializing board: %s\n", pb_get_error()); return -1; } if(pb_start()) { printf("Error occurred trying to trigger board: %s\n\n", pb_get_error()); } else { printf("Board triggered successfully\n\n"); } pb_close(); system("pause"); return 0; }
int read_data() { unsigned char buffer[BUFFER_SIZE]; oem4_header_t header; int result, read_len, rd_cnt; unsigned int crc; pushback_reader_t efd; oem4_bestpos_t bestpos; oem4_bestvel_t bestvel; gps_pos_novatel_t gps_pos; gps_vel_novatel_t gps_vel; struct timespec tloc; static int is_init = 0; //in case of read-errors from ser. device this function will be called several times in case of error from main. // if(is_init) { erret(pb_reset(&efd)); } else { erret(pb_init(fd, BUFFER_SIZE*2, &efd)); is_init = 1; } memset(buffer, 0, sizeof(buffer)); memset(&gps_pos, 0, sizeof(gps_pos)); memset(&gps_vel, 0, sizeof(gps_vel)); rd_cnt = 0; result = 0; while(1) { // read sync erret(pb_read(&efd, buffer, (unsigned int *)&read_len, OEM4_SYNC_SIZE)); if(read_len<=0) fprintf(stderr,"read timeout\r\n"); // read enough (3) sync bytes? if (read_len != OEM4_SYNC_SIZE) { // no, pusback what we had read so far and try again... erret(pb_unread(&efd, buffer, read_len)); continue; } // increment counter of read bytes rd_cnt += read_len; // sync found? if (buffer[0] != OEM4_BIN_SYNC_HEADER[0] || buffer[1] != OEM4_BIN_SYNC_HEADER[1] || buffer[2] != OEM4_BIN_SYNC_HEADER[2]) { // search for sync message or part of sync message result = oem4_search_sync(buffer, rd_cnt); // unread everything from the beginning of the sync message // if no (partial) sync message is found, nothing is unread (rd_cnt - result) == 0 erret(pb_unread(&efd, &buffer[result], rd_cnt - result)); // everything is pushed back, therefore nothing is read rd_cnt = 0; continue; } // read head length erret(pb_read(&efd, &buffer[rd_cnt], (unsigned int *)&read_len, 1)); // nothing was read? if (result == 0) { // search for sync message or part of sync message result = oem4_search_sync(buffer, rd_cnt); // push back and try again erret(pb_unread(&efd, &buffer[result], rd_cnt - result)); rd_cnt = 0; continue; } rd_cnt += read_len; // assign header length header.length = buffer[3]; // header too long for the buffer? if(header.length + OEM4_SYNC_SIZE >= BUFFER_SIZE) { // this is a serious error, search for sync result = oem4_search_sync(buffer, rd_cnt); // unread everything from the beginning of the sync message erret(pb_unread(&efd, &buffer[result], rd_cnt - result)); rd_cnt = 0; continue; } // read header, keep in mind that four bytes of the header are allready read erret(pb_read(&efd, &buffer[rd_cnt], (unsigned int *)&read_len, header.length - 4)); // read less than expected? if (read_len != header.length - 4) { // search for sync message or part of sync message result = oem4_search_sync(buffer, rd_cnt + read_len); // push back what we had and try again erret(pb_unread(&efd, &buffer[result], rd_cnt + read_len - result)); rd_cnt = 0; continue; } rd_cnt += read_len; oem4_fill_header(&header, buffer); // data too long for the buffer? if ((header.message_length + header.length + OEM4_SYNC_SIZE + OEM4_CRC_SIZE) >= BUFFER_SIZE) { // this is a serious error, search for sync result = oem4_search_sync(buffer, rd_cnt); // unread everything from the beginning of the sync message erret(pb_unread(&efd, &buffer[result], rd_cnt - result)); rd_cnt = 0; continue; } // read data and CRC erret(pb_read(&efd, &buffer[rd_cnt], (unsigned int *)&read_len, header.message_length + OEM4_CRC_SIZE)); // read less than expected? if (read_len != header.message_length + OEM4_CRC_SIZE) { // this is a serious error, search for sync result = oem4_search_sync(buffer, rd_cnt + read_len); // push back what we had and try again erret(pb_unread(&efd, &buffer[result], rd_cnt + read_len - result)); rd_cnt = 0; continue; } rd_cnt += read_len; crc32_block(buffer, rd_cnt, &crc); // CRC ok? (crc == 0) if (crc) { // this is a serious error, search for sync result = oem4_search_sync(buffer, rd_cnt); // unread everything from the beginning of the sync message erret(pb_unread(&efd, &buffer[result], rd_cnt - result)); rd_cnt = 0; continue; } // decode message switch(header.message_id) { case OEM4_BESTPOS: if (!oem4_get_best_pos(&bestpos, &buffer[header.length], header.message_length)) { #if AR_VERBOSE==1 oem4_dump_best_pos(&bestpos); #endif memcpy(&bestpos.gps_header, &header, sizeof(header)); create_gps_position(&bestpos, &gps_pos); SHM_WriteSlot(config.ishm_pos_out, &gps_pos, sizeof(gps_pos)); clock_gettime(CLOCK_REALTIME, &tloc); if(abs(tloc.tv_sec - gps_pos.gps_time.tv_sec) > 60*60*4 && gps_pos.solution_type>0) clock_settime(CLOCK_REALTIME, &gps_pos.gps_time); } break; case OEM4_BESTVEL: if (!oem4_get_best_vel(&bestvel, &buffer[header.length], header.message_length)) { memcpy(&bestvel.gps_header, &header, sizeof(header)); create_gps_velocity(&bestvel, &gps_vel); SHM_WriteSlot(config.ishm_vel_out, &gps_vel, sizeof(gps_vel)); } break; } rd_cnt = 0; } return 0; }
int main(int argc, char *argv[]) { modem_config cfg[64]; int modem_count; int port=0; char *ip_addr = NULL; /* gwb */ unsigned char all_busy[255]; pthread_t thread_id; int i; int rc; int sSocket = 0; fd_set readfs; int max_fd=0; int accept_pending=FALSE; int res=0; unsigned char buf[255]; int cSocket; log_init(); LOG_ENTER(); log_set_level(LOG_FATAL); mdm_init(); pb_init(); signal(SIGIO,SIG_IGN); /* Some Linux variant term on SIGIO by default */ modem_count = init(argc, argv, cfg, 64, &ip_addr, &port,all_busy,sizeof(all_busy)); /* gwb */ sSocket = ip_init_server_conn(ip_addr, port); for(i=0;i<modem_count;i++) { if( -1 == pipe(cfg[i].data.mp[0])) { ELOG(LOG_FATAL,"Bridge task incoming IPC pipe could not be created"); exit(-1); } if( -1 == pipe(cfg[i].data.mp[1])) { ELOG(LOG_FATAL,"Bridge task outgoing IPC pipe could not be created"); exit(-1); } if(dce_init_conn(&cfg[i]) < 0) { LOG(LOG_FATAL,"Could not open serial port %s",cfg->dce_data.tty); exit(-1); } cfg[i].line_data.sfd=sSocket; rc=pthread_create(&thread_id,NULL,*run_bridge,(void *)&cfg[i]); if(rc < 0) { ELOG(LOG_FATAL,"IP thread could not be started"); exit(-1); } } for(;;) { FD_ZERO(&readfs); max_fd=0; for(i=0;i<modem_count;i++) { FD_SET(cfg[i].data.mp[0][0], &readfs); max_fd=MAX(max_fd,cfg[i].data.mp[0][0]); } if(accept_pending==FALSE) { max_fd=MAX(max_fd,sSocket); FD_SET(sSocket, &readfs); } LOG(LOG_ALL,"Waiting for incoming connections and/or indicators"); select(max_fd+1, &readfs, NULL, NULL, NULL); for(i=0;i<modem_count;i++) { if (FD_ISSET(cfg[i].data.mp[0][0],&readfs)) { // child pipe res = read(cfg[i].data.mp[0][0],buf,sizeof(buf) -1); if(res > -1) { buf[res]=0; LOG(LOG_DEBUG,"modem core #%d sent response '%c'",i,buf[0]); accept_pending=FALSE; } } } if (FD_ISSET(sSocket,&readfs)) { // IP traffic if(!accept_pending) { LOG(LOG_DEBUG,"Incoming connection pending"); // first try for a modem that is listening. for(i=0;i<modem_count;i++) { if(cfg[i].s[0] != 0 && cfg[i].off_hook == FALSE) { // send signal to pipe saying pick up... LOG(LOG_DEBUG,"Sending incoming connection to listening modem #%d",i); writePipe(cfg[i].data.mp[1][1],MSG_ACCEPT); accept_pending=TRUE; break; } } // now, send to any non-active modem. for(i=0;i<modem_count;i++) { if(cfg[i].off_hook== FALSE) { // send signal to pipe saying pick up... LOG(LOG_DEBUG,"Sending incoming connection to non-connected modem #%d",i); writePipe(cfg[i].data.mp[1][1],MSG_ACCEPT); accept_pending=TRUE; break; } } if(i==modem_count) { LOG(LOG_DEBUG,"No open modem to send to, send notice and close"); // no connections.., accept and print error cSocket=ip_accept(sSocket); if(cSocket > -1) { if(strlen(all_busy) < 1) { ip_write(cSocket,(unsigned char*)MDM_BUSY,strlen(MDM_BUSY)); } else { writeFile(all_busy,cSocket); } close(cSocket); } } } } } LOG_EXIT(); return rc; }
int main(void) { /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface * and the Systick. */ board_Init(); /* Init components */ motor_init(); motor_stop(motor_ch_all); motor_go_forward(); pb_init(); encoder_init(); /* USER CODE BEGIN RTOS_MUTEX */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ muRange = xSemaphoreCreateMutex(); /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* Create the thread(s) */ /* definition and creation of defaultTask */ xTaskCreate(task_blinky, /* Pointer to the function that implements the task */ "Blinky", /* Text name for the task. This is to facilitate debugging only. It is not used in the scheduler */ configMINIMAL_STACK_SIZE, /* Stack depth in words */ NULL, /* Pointer to a task parameters */ 1, /* The task priority */ &xBlinkyHandle); /* Pointer of its task handler, if you don't want to use, you can leave it NULL */ /* xTaskCreate(vRangeFinderTask, "Range", configMINIMAL_STACK_SIZE+500, NULL, configMAX_PRIORITIES-1, &xScanInputHandle); */ /* xTaskCreate(vEncoderTask, "Encoder", configMINIMAL_STACK_SIZE+500, NULL, configMAX_PRIORITIES-1, &xScanInputHandle); */ xTaskCreate(task_main, "Main", configMINIMAL_STACK_SIZE+2500, NULL, configMAX_PRIORITIES-1, &xMainHandle); /* USER CODE BEGIN RTOS_QUEUES */ /* definition and creation of xQueueUARTReceive */ quUARTReceive = xQueueCreate(confUART_RECEIVE_QUEUE_LENGTH, /* length of queue */ sizeof(uint8_t)*confUART_RECEIVE_BUFFER_SIZE); /* size in byte of each item */ /* USER CODE END RTOS_QUEUES */ /* Start scheduler */ vTaskStartScheduler(); /* NOTE: We should never get here as control is now taken by the scheduler */ while (1) { } }
int main(void) { uint32_t sysTickRate; Board_Init(); #ifdef DEBUG // Set up UART for debug init_uart(115200); putLineUART("\n"); #endif // Enable EEPROM clock and reset EEPROM controller Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_EEPROM); Chip_SYSCTL_PeriphReset(RESET_EEPROM); // Set up clocking for SD lib SystemCoreClockUpdate(); DWT_Init(); // Set up the FatFS Object f_mount(fatfs,"",0); // Initialize SD card Board_LED_Color(LED_CYAN); if(sd_reset(&cardinfo) != SD_OK) { error(ERROR_SD_INIT); } sd_state = SD_READY; // Setup config Board_LED_Color(LED_CYAN); configStart(); Board_LED_Color(LED_GREEN); // Allow MSC mode on startup msc_state = MSC_ENABLED; // Log startup log_string("Startup"); // Set up ADC for reading battery voltage read_vBat_setup(); // Initialize ring buffer used to buffer raw data samples rawBuff = RingBuffer_initWithBuffer(RAW_BUFF_SIZE, RAM1_BASE); // Set up MRT used by pb and daq Chip_MRT_Init(); NVIC_ClearPendingIRQ(MRT_IRQn); NVIC_EnableIRQ(MRT_IRQn); NVIC_SetPriority(MRT_IRQn, 0x02); // Set higher than systick, but lower than sampling // Initialize push button pb_init(); // Enable and setup SysTick Timer at a periodic rate Chip_Clock_SetSysTickClockDiv(1); sysTickRate = Chip_Clock_GetSysTickClockRate(); SysTick_Config(sysTickRate / TICKRATE_HZ1); // Idle and run systick loop until triggered or plugged in as a USB device system_state = STATE_IDLE; enterIdleTime = Chip_RTC_GetCount(LPC_RTC); // Wait for interrupts while (1) { __WFI(); } return 0 ; }
int main(int argc, char **argv) { int start, i; //uncomment to turn on debug messages //pb_set_debug(1);//turns on debug messages. They will appear in log.txt printf ("Using spinapi library version %s\n", pb_get_version()); if(pb_init()) { printf ("Error initializing board: %s\n", pb_get_error()); system("pause"); return -1; } pb_set_defaults(); pb_set_clock(CLOCK_FREQ); printf("Clock frequency: %.2lf MHz\n\n", CLOCK_FREQ); printf("This example program demonstrates a frequency sweep using the PBDDS-I-300.\n\nYou have specified %d frequency registers.\nYou should see the DDS sweep frequencies from %.4lf MHz to %.4lf MHz with a\nstep size of %.4lf MHz and a time between steps of %d ms.\nThe frequencies should oscillate back and forth from minimum to maximum, maximum to minimum.\n", NUM_FREQUENCY_REGISTERS,MIN,MAX,STEP,RATE); // Program the frequency registers. pb_start_programming(FREQ_REGS); for(i=0;i<NUM_FREQUENCY_REGISTERS; ++i) pb_set_freq(MIN + STEP*((double)i)); pb_stop_programming(); // Program the first 2 phase registers. pb_start_programming(TX_PHASE_REGS); pb_set_phase(0.0); // Register 0 pb_set_phase(0.0); // Register 1 pb_stop_programming(); // Write the pulse program pb_start_programming(PULSE_PROGRAM); //pb_inst_dds(freq, tx_phase, tx_enable, phase_reset, flags, // inst, inst_data, length) start = pb_inst_dds(0, 0, TX_DISABLE, PHASE_RESET, 0x000, CONTINUE, 0, 1.0 * us); for(i=0; i < NUM_FREQUENCY_REGISTERS; ++i) //Program instructions (increasing) pb_inst_dds(i, 0, TX_ENABLE, NO_PHASE_RESET, 0x1FF, CONTINUE, 0, RATE*ms); for(i= NUM_FREQUENCY_REGISTERS-1; i >= 1; --i) //Program instructions (decreasing) pb_inst_dds(i, 0, TX_ENABLE, NO_PHASE_RESET, 0x1FF, CONTINUE, 0, RATE*ms); pb_inst_dds(0, 0, TX_ENABLE, NO_PHASE_RESET, 0x1FF, BRANCH, start, RATE*ms); pb_stop_programming(); // Trigger program pb_start(); // Release control of the board pb_close(); system("pause"); return 0; }
int main(int argc, char **argv) { int start; pb_set_debug(1); printf ("Using spinapi library version %s\n", pb_get_version()); if(pb_init()) { printf ("Error initializing board: %s\n", pb_get_error()); system("pause"); return -1; } pb_set_defaults(); pb_set_clock(CLOCK_FREQ); printf("Clock frequency: %.2lfMHz\n\n", CLOCK_FREQ); printf("The example program tests the excitation portion of the RadioProcessor. This program will produce a 1MHz signal on the oscilloscope that is on for 10 microseconds, off for 1 milisecond, and will then repeat this pattern.\n\n"); // Write 1 MHz to the first frequency register pb_start_programming(FREQ_REGS); pb_set_freq(1.0*MHz); pb_stop_programming(); // Write 0.0 degrees to the first phase register of all channels pb_start_programming(TX_PHASE_REGS); pb_set_phase(0.0); pb_stop_programming(); pb_start_programming(COS_PHASE_REGS); pb_set_phase(0.0); pb_stop_programming(); pb_start_programming(SIN_PHASE_REGS); pb_set_phase(0.0); pb_stop_programming(); // Write the pulse program pb_start_programming(PULSE_PROGRAM); //pb_inst_radio(freq, cos_phase, sin_phase, tx_phase, tx_enable, phase_reset, trigger_scan, flags, // inst, inst_data, length) // This instruction enables a 1 MHz analog output start = pb_inst_radio(0,0,0,0, TX_ENABLE, NO_PHASE_RESET, NO_TRIGGER, 0x3F, CONTINUE, 0, 10.0*us); // This instruction disables the analog output (and resets the phase in preparation for the next instruction) pb_inst_radio(0,0,0,0, TX_DISABLE, PHASE_RESET, NO_TRIGGER, 0x0, BRANCH, start, 1.0*ms); pb_stop_programming(); // Trigger program pb_start(); // Release control of the board pb_close(); return 0; }
int main(int argc, char *argv[]) { int start, i, isr1; int numBoards; //Uncommenting the line below will generate a debug log in your current directory //that can help debug any problems that you may be experiencing //pb_set_debug(1); printf ("Copyright (c) 2010 SpinCore Technologies, Inc.\n\n"); printf("Using SpinAPI library version %s\n", pb_get_version()); if((numBoards = detect_boards()) > 1) { /*If there is more than one board in the system, have the user specify.*/ select_board(numBoards); /*Request the board numbet to use from the user*/ } if (pb_init () != 0) { printf ("Error initializing board: %s\n", pb_get_error ()); system("read -p \"Press enter to continue\""); return -1; } printf("This example program tests the analog and TTL outputs of the PBDDS-II.\n\n This program will produce a 10.0 MHz signal on both channels that is on for 10 microseconds, off for 200 microseconds, and then repeats this pattern.\n\n"); printf("The RF pulses on Channels 1 and 2 are offset by 90 degrees.\n\n"); printf("A TTL logical high signal on the IRQ0 pin will cause an ISR to be performed \nthat pronduces a 2.0 MHz signal on both channels that is on for 200.0 us, off \nfor 200.0 us and repeats this pattern 10,000 times. It will turn both channels \noff for 100.0 us and then returns to the main pulse program.\n\n"); printf("NOTE: It is important to terminate all signals properly (i.e. with a 50 Ohm\nterminating resistor at the end of your cable). A reconstructing filter must\nalso be used at the RF outputs. When viewing the RF signals on an oscilloscope,the oscilloscope should be triggered using a TTL signal\n\n"); printf("See manual for details at: http://www.spincore.com/\n\n"); system("read -p \"Press enter to continue\""); printf("\n\n"); pb_core_clock(CLOCK_FREQ); //Set the PB core clock value. /****** THIS SECTION PROGRAMS REGISTERS FOR CHANNEL 1 (DDS0) ******/ pb_select_dds(0); //Select DDS0 (this is selected by default.) pb_start_programming(FREQ_REGS); //Program DDS0's frequency registers. NOTE: Each Channel has 16 available Frequency registers pb_set_freq(10.0*MHz); //Program Frequency Register 0. pb_set_freq(4.0*MHz); //Program Frequency Register 1. pb_stop_programming(); pb_start_programming(TX_PHASE_REGS); //Program DDS0's phase registers. NOTE: Each Channel has 8 available Phase registers pb_set_phase(270.0); //Program Phase Register 0. pb_set_phase(70.0); //Program Phase Register 1. // PHASE1 offset is introduced to improve the initial RF pulse response. This phase is used during the "off" time of the RF pulse. pb_stop_programming(); pb_set_amp(1.0,0); //Program DDS0's amplitude registers. // NOTE: Each Channel has 4 available amplitude registers /**********************************************************************/ /***** THIS SECTION PROGRAMS REGISTERS FOR CHANNEL 2 (DDS1) *****/ pb_select_dds(1); //Select DDS1. pb_start_programming(FREQ_REGS); //Program DDS1's frequency registers. pb_set_freq(10.0*MHz); //Program Frequency Register 0. pb_set_freq(2.0*MHz); //Program Frequency Register 1. pb_stop_programming(); pb_start_programming(TX_PHASE_REGS); //Program DDS1's phase registers. pb_set_phase(0.0); //Program Phase Register 0. pb_set_phase(70.0); //Program Phase Register 1. pb_stop_programming(); pb_set_amp(1.0,0); //Program DDS1's amplitude registers. /************************************************************************/ //The next section is where the actual pulse program is written: //The line below shows which parameter corresponds to which register or flag. /***** SPINCORE_API int pb_inst_dds2(int freq0, int phase0, int amp0, int dds_en0, int phase_reset0, int freq1, int phase1, int amp1, int dds_en1, int phase_reset1, int flags, int inst, int inst_data, double length) ****/ pb_start_programming(PULSE_PROGRAM); //This line is used to start programming the pulse program. /******************************************************************************************************** * Each piece of the pulse program is specified by a pb_inst_dds2(...) command * * The first line says for Channel 1 use: * * Frequency register 0 (which was programmed to be 10 MHz) * * Phase register 0 (which was programmed to be 0 degrees * * Amplitude register 0 (which was programmed to be 0.85 * * Enable Channel 1 * * Do not reset the phase of channel 1 * * The first line also says for Channel 2 use: * * Frequency register 0 (which was programmed to be 10 MHz) * * Phase register 0 (which was programmed to be 0) * * Amplitude register 0 (which was programmed to be 1.0) * * Enable Channel * * Do not reset the phase of channel 1 * * 0xfff is a hexadecimal value that corresponds to the TTL flags 0xfff equals 1111 1111 1111 which * * means that all 12 bits are HIGH * * The specific instruction for this line is CONTINUE which does not require a DATA field so it is set * * to zero. * * All of this takes place for 10us * * The second line disables the outputs of both Channel 1 and Channel 2 and also resets the phase. * * Also the TTL flags are set to LOW, and then the instruction branches back to the first line. * * This happens for 200us. * ********************************************************************************************************/ start = pb_inst_dds2(FREQ0, PHASE0, AMP0, TX_ENABLE, NO_PHASE_RESET, FREQ0, PHASE0, AMP0, TX_ENABLE, NO_PHASE_RESET, 0xfff, CONTINUE, 0, 10.0*us); pb_inst_dds2(FREQ0, PHASE1, AMP0, TX_DISABLE, PHASE_RESET, FREQ0, PHASE1, AMP0, TX_DISABLE, PHASE_RESET, 0x000, BRANCH, start, 200.0*us); /********************************************************************************************************* * The section below specifies the interrupt sub routine * * The instructions follow the same general structure except that LOOP, END_LOOP and RTI instructions * * are used. Here you will notice that where Channel 1 uses Frequency register 1, but Channel 2 * * uses Frequency register 0, so they are not the same frequency * *********************************************************************************************************/ isr1 = pb_inst_dds2(FREQ1, PHASE0, AMP0, TX_ENABLE, NO_PHASE_RESET, FREQ1, PHASE0, AMP0, TX_ENABLE, NO_PHASE_RESET, 0xfff, LOOP, 10000, 200.0*us); pb_inst_dds2(FREQ1, PHASE0, AMP0, TX_DISABLE, PHASE_RESET, FREQ0, PHASE0, AMP0, TX_DISABLE, PHASE_RESET, 0x000, END_LOOP, isr1, 200.0*us); pb_inst_dds2(FREQ0, PHASE0, AMP0, TX_DISABLE, PHASE_RESET, FREQ0, PHASE0, AMP0, TX_DISABLE, PHASE_RESET, 0x000, RTI, isr1, 100.0*us); pb_stop_programming(); // This line ends the pulse program pb_write_register (START_LOCATION, 0); pb_write_register (FLAG_STATES, 0); /*** The section below sets the interrupt masks ***/ pb_set_isr(0, isr1); //Program IRQ0 ISR pb_set_irq_enable_mask(0x1); //Interrupt enable mask. 0x1 enables IRQ0. pb_set_irq_immediate_mask(0x0); //Set which IRQs are immediate IRQs (immediately perform ISR) // Send a software trigger (i.e. pb_start()) to the board to begin execution of the program pb_start(); printf("Continuing will stop program exectution\n"); system("read -p \"Press enter to continue.\""); pb_stop(); pb_close(); return 0; }
int main(void) { int i; short data[NUMBER_POINTS], data_imag[NUMBER_POINTS]; int idata[NUMBER_POINTS],idata_imag[NUMBER_POINTS]; printf("Using SpinAPI Version: %s\n",pb_get_version()); printf("Number of boards detected in your system: %d\n", (i=pb_count_boards())); if(i<=0) { printf("No boards were detected in your system. Please check all connections.\n"); system("pause"); return -1; } pb_select_board(BOARD_NUMBER); printf("This program demonstrates the direct ram capture feature of the RadioProcessor.\n"); if(!pb_init()) { printf("Error initializing board #%d. Please check that this is a valid board number and that all connections are correct.\n"); return -1; } pb_set_defaults(); pb_set_clock(ADC_FREQUENCY); //Set the ADC frequency. pb_zero_ram(); // Clear RAM to all zeros (PCI only). pb_overflow(1,0); // Reset the overflow counters. pb_scan_count(1); // Reset scan counter. pb_set_radio_control(RAM_DIRECT); //Enable direct ram capture. pb_set_num_points(NUMBER_POINTS); //This is the number of points that we are going to be capturing. double wait_time = 1000.0 * (NUMBER_POINTS)/(ADC_FREQUENCY*1e6); // Time in ms pb_start_programming(PULSE_PROGRAM); int start = pb_inst_radio_shape(0,0, 0, 0, 0, 0, NO_TRIGGER, 0, 0, 0x02, LOOP , NUMBER_SCANS, 1.0*us); pb_inst_radio_shape(0,0, 0, 0, 0, 0, DO_TRIGGER, 0, 0, 0x01, END_LOOP, start , wait_time * ms); pb_inst_radio_shape(0,0, 0, 0, 0, 0, NO_TRIGGER, 0, 0, 0x02, STOP , 0 , 1.0*us); pb_stop_programming(); printf("Performing direct ram capture...\n"); pb_start(); printf("Waiting for the data acquisition to complete.\n"); while(pb_read_status() != BOARD_STATUS_IDLE) //Wait for the board to complete execution. { pb_sleep_ms(100); } pb_get_data_direct(NUMBER_POINTS,data); pb_unset_radio_control(RAM_DIRECT); //Disable direct ram capture. pb_close(); FILE* fp_ascii = fopen("direct_data.txt","w"); for(i=0;i<NUMBER_POINTS;++i) { fprintf(fp_ascii,"%d\n",data[i]); } fclose(fp_ascii); for(i=0;i<NUMBER_POINTS; ++i) { idata[i] = data[i]; idata_imag[i] = data_imag[i]; } //The spectrometer frequency does not matter in a direct ram capture. Using 1.0 MHz for //proper file format. pb_write_felix("direct_data.fid", NUMBER_POINTS,ADC_FREQUENCY*1e6, 1.0, idata, idata_imag); system("PAUSE"); return 0; }