/* PulseBlasterESR-Pro-II high speed memory output Example program * © 2007 SpinCore Technologies Inc. * http://www.spincore.com * * This sample code is available to SpinCore customers to use and modify for any * purpose, including commercial use. * * For more information visit http://www.pulseblaster.com/CD/PulseBlasterESR-Pro-II/ * * This program loads a custom pulse sequence onto the PulseBlasterESR-Pro-II * board and then triggers it. This is a high-speed output function that will * not work for any other PulseBlaster or RadioProcessor board. */ #include #include #include "spinapi.h" #define CLOCK 300 //Your operating frequency int main(int argc, char **argv) { //Temporary variables used in loops int i; int j; //Set up communication with the board 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; } //Reset the board pb_outp(0,0); //Reset the memory counter pb_outp(4,0); //*** Pulse program loading begins here *** /* This pulse sequence will generate the pulses shown in the * sample timing diagram on page 4 of the PBESR-Pro-II manual. * The leftmost bit is Channel 23, followed by Channel 22, * Channel 21, ... , Channel 1, and the rightmost bit is Channel 0. */ pb_inst_hs("000000000000000000001001",3.34*ns); pb_inst_hs("000000000000000000000001",3.34*ns); pb_inst_hs("000000000000000000000000",6.67*ns); pb_inst_hs("000000000000000000000001",3.34*ns); pb_inst_hs("000000000000000000000011",3.34*ns); pb_inst_hs("000000000000000000000111",3.34*ns); pb_inst_hs("000000000000000000001101",3.34*ns); pb_inst_hs("000000000000000000001000",3.34*ns); pb_inst_hs("000000000000000000000011",3.34*ns); pb_inst_hs("000000000000000000000001",3.34*ns); pb_inst_hs("000000000000000000000011",3.34*ns); pb_inst_hs("000000000000000000000001",6.67*ns); //Nothing for 470ns pb_inst_hs("000000000000000000000000",470*ns); //Trigger the board pb_outp(1,0); //Signal the end of communication pb_close(); //For convenience, pause here and display a message printf("Done sending commands\n"); system("PAUSE"); return 0; } //Flags is a string of 24 1s and 0s (Channel 23, Channel 22, Channel 21, etc.) //Length is a floating point number, representing the desired length in nanoseconds //This function expects standard ASCII input characters ('1' is ASCII 49, '0' is ASCII 48) // > If you have an international version of Windows that uses a character set other // than ASCII, you may need to modify this function. //**NOTE** This function must be added to your own custom C code for access to // the pb_inst_hs function capability ** int pb_inst_hs(char* Flags, double length) { int i; int num_cycles; char hex_flags0, hex_flags1, hex_flags2; //Convert the string of ones and zeros to an 8-bit decimal number hex_flags0 =(Flags[0] - 48)*128 + (Flags[1] - 48)*64 + (Flags[2] - 48)*32 + (Flags[3] - 48)*16 + (Flags[4] - 48)*8 + (Flags[5] - 48)*4 + (Flags[6] - 48)*2 + (Flags[7] - 48)*1; hex_flags1 =(Flags[8] - 48)*128 + (Flags[9] - 48)*64 + (Flags[10] - 48)*32 + (Flags[11] - 48)*16 + (Flags[12] - 48)*8 + (Flags[13] - 48)*4 + (Flags[14] - 48)*2 + (Flags[15] - 48)*1; hex_flags2 =(Flags[16] - 48)*128 + (Flags[17] - 48)*64 + (Flags[18] - 48)*32 + (Flags[19] - 48)*16 + (Flags[20] - 48)*8 + (Flags[21] - 48)*4 + (Flags[22] - 48)*2 + (Flags[23] - 48)*1; //Convert the length from nanoseconds to a number of clock cycles num_cycles = (int) rint(length/(1000.0/CLOCK)); //Each pb_outp instruction controls the output for one clock cycle, // so send this line to the board as many times as it takes to // create the requested instruction length. for (i = 1; i <= num_cycles; i++) { pb_outp(6,hex_flags0); pb_outp(6,hex_flags1); pb_outp(6,hex_flags2); } return 0; }