I am currently having problems coding with Matlab. I am suppose to send/sweep a series of wavelengths through a photonic chip and scan it on the other end. Everything is fine but it is taking longer than I want it to. Please look at the code below and tell me if I should change something in order to make it run faster.
PS~~i did not implement this code, I am suppose to edit it to make it run faster. Ive run test and figured that the wave part of the loop takes the longest time.
for i=1:floor(num_pts)+1 % query the power fprintf(laser,'fetch3:chan2:pow?') power(i) = str2double(fscanf(laser));
% record time time(i) = etime(clock,t0);
% get celsius temp fprintf(tc, 'TTRD?') temp(i) = str2double(fscanf(tc));
% increase the wavelength wav = wav+step; --------> takes about 0.35s while the whole loop is around 0.535s fprintf(laser,cat(2,'source0:wav ',num2str(wav),'nm')) fprintf(laser,'source0:wav?')
% poll the instrument for completion of this command % because adjusting a new wavelength takes some time % errStatus = viQueryf(vi,"*OPC?\n","%d",&cmdDone); resp=0; while resp==0 fprintf(laser,'*OPC?') resp = fscanf(laser); pause(1e-3) % [s] end end
Hi Ralph, You didn't mention which laser you are using. Some models are capable of making continuously swept measurements while the power meter (which you seem to have in slot 3) is trigger to log the data. If your laser can do this, that would be much faster and you might not need to measure temperature for each point (possibly every 100us). For continuous sweeping, it is most convenient to use the lambdascan routines of the 816x PnP driver.
If you need to make the stepped measurements, you can still set the laser up to make a stepped sweep and then trigger the power meter with these steps. I think this should be faster than separately reading and uploading each power value.
There was some discussion of this stepped sweeping in this previous topic. view
I hope one of these options works well for your application.
I am using these devices: mainframe -->8164a sensor--->81635a source--->81682a also, laser source is from--->source0 sensor is from--->source3, channel 2
here are my parameters: function sweep(min,max,num_pts,ug1_num) step = (max-min)/num_pts;
min--->determines the minimum value for my wavelength when sweeping max--->determines the max " num_pts--->can range from 100-6000 (so i will have ALOT of values, thats why i need to run the code faster, 6000 points takes around 40-50+ minutes) ug1_num--->used to name the file after its been plotted
not sure if these info help, but i guess it wont hurt while im waiting for your reply. I will also read the link that you sent me.
Hi Ralph, With these instruments you will be able to make continuous sweep measurements, rather than stepped sweep. That can go much faster and is really the best way when you want thousands of points. In this mode the laser runs over the chosen wavelength range at a constant speed and triggers the power meter at the chosen step interval. At the same trigger times the laser measures the actual wavelengths. That laser can sweep at up to 40nm/s (current models do 80nm/s), and the power meter can use averaging times down to 100us and log up to 20k points. So you could even sample every 4pm over 40nm for example with a 1s sweep. There will still be time involved in setting up the sweep and uploading the data but it will be a very much faster process.
The quickest way to try this out is with the IL engine of the N7700A software package. The IL engine is free and you can download the necessary elements from here: http://www.agilent.com/find/n7700. You will need the main package, the IL engine and the 816x PnP driver. The IL engine is really working as a GUI for the measurement functions of the driver and the same driver can be used by your own program. I don't have any experience with Matlab, but that should work too. The IL engine will run the sweep and read the power and wavelengths, and the compare the power levels to a previous reference sweep (usually made with the laser connected directly to the power meter) or simply compared to the nominal laser power if no reference is made.
The PnP driver has functions for the application "multiframe lambda scan" which automatically set the number of points and averaging times and other details like trigger configurations, when given the desired sweep parameters, so it can take over some of what your current program is doing. The most important functions would be; hp816x_prepareMfLambdaScan hp816x_executeMfLambdaScan hp816x_getLambdaScanResult
Thanks for your help. I tried to use IL engine, but it seems like I will try and stick with Matlab because I have a second parameter to consider, temperature. Do I just use these with functions fprintf?? hp816x_prepareMfLambdaScan hp816x_executeMfLambdaScan hp816x_getLambdaScanResult
I am trying to have a different approach because i dont really know how to use the hp816x_ functions and I think they're only for multiple frame. I could be wrong though, you'd probably know better..so I am doing this instead:
% set laser output power fprintf(laser,cat(2,'source0:pow ',num2str(output_power),'mW')) %look at pg124
% change the power unit of the power meter to dbm fprintf(laser,'sens3:chan2:pow:unit dbm')
%sets the sweep mode----p141 fprintf(laser,'source0:wav:sweep:mode CONT')
% sets the number of cycles----p137 fprintf(laser,cat(2,'source0:wav:sweep:cycl ',numb2str(num_pts)))
%sets the speed for continuous sweeping fprintf(laser,'source0:wav:sweep:speed 40nm/s')
% sets the start point of the sweep fprintf(laser,cat(2,'source0:wav:sweep:start ',numb2str(min),'nm'))
% sets the end point of the sweep fprintf(laser,cat(2,'source0:wav:sweep:stop ',numb2str(max),'nm'))
% disables amplitude modulation/prerequisite for sweep logging----p117 fprintf(laser,'source0:am:state 0')
%sets the width of the sweep step fprintf(laser,cat(2,'source0:wav:sweep:step',numb2str(step),'nm'))
%specifies when output trigger is generated and arms the module/prerequisite for log---p176 fprintf(laser,'trigger0:output:STFinished')
% turn auto range on fprintf(laser,'sens3:chan2:pow:range:auto 1')
% turns sweep logging on fprintf(laser,cat(2,'source0:wav:sweep:llog 1'))
% turn laser on fprintf(laser,'source0:pow:state 1')
Your program looks to be on the right track, but I think it would still be worth setting it up to use the hp816x functions, since they will do some of this coordination of timing and triggers for you. The 816x PnP driver follows the VXI Plug&Play standard for instrument automation. This can be used in a program like linking functions from a library. I haven't used Matlab, but this web page seems to point out how to use the drivers. http://www.mathworks.com/products/instrument/hardware/vxi-plug-and-play.html
The "multiframe" lambdascan functions are generalized from the simple lambdascan functions to allow using instruments in more than one mainframe, but can also be used with a single mainframe including both laser and power meters. You could use either one, but the multiframe set does provide more flexibility for choosing your parameters.
Regarding your program with the direct SCPI commands, the main point that needs to be included now is to set up the power logging on the power meter. This needs this command to choose the number of points and the averaging time, which should be less than or equal the TLS step time: :SENSe[n][:CHANnelm]:FUNCtion:PARameter:LOGGing
the triggering should be set so that each trigger from the laser starts a single measurement :TRIGger[n][:CHANnelm]:INPut SME
The mainframe also needs to be configured to loop the laser output triggers back to the input plane for the power meters: :TRIGger:CONFiguration LOOP
The logging results will be in linear units of W, not dBm. They are output as a binary block. One of the advantages of the PnP driver is the automatic conversion to a real array. Also the power meter cannot change ranges fast enough to be in autorange during logging, so the correct power range should be selected before starting the logging.
When everything is configured, then the logging is activated to wait for the triggers with: :SENSe[n][:CHANnelm]:FUNCtion:STATe LOGG,STAR
As you can see, there are quite a few things to set up and keep coordinated. I'm not sure I've remembered them all here either. All of this can be done with the direct SCPI, but the PnP functions are really much more convenient.
my question is, do i just need to call for these functions after this?? I understand that the driver alraedy has all the functions needed so i dont have to worry about direct SCPI commands. Please correct me if Im wrong. hp816x_prepareMfLambdaScan hp816x_executeMfLambdaScan hp816x_getLambdaScanResult
I have to leave the lab soon and will try and figure it out tomorrow in case you dont have an answer yet. im just a little confused at how i should use the driver.
Hi Ralph, Thanks for trying the driver with Matlab and posting your details. Yes all of the necessary commands can be sent using the driver functions.
The 3 functions mentioned earlier do most of the work. You also need to register and unregister the mainframe at the start and end of the program. Some other functions are available for optionally controlling some details like sweep speed, power ranges and whether the default interpolation of the measured lambda values to equidistant points is used.
Details to the functions and parameters are in the help file installed with the driver and probably linked in your start menu in the folder "vxipnp". The file is here: C:\Programme\IVI Foundation\VISA\WinNT\hp816x
The example programs installed with the driver might also be useful, although unfortunately not for Matlab. In particular the text in llmain.cpp can help as it implements lambdascan. C:\Programme\IVI Foundation\VISA\WinNT\hp816x\Examples\VC
The Sample 5 for the VEE examples is also a lambdascan program.
Thanks a lot for your help. Now the only problem I have is how to use matlab properly....when i first tried to use the functions in the driver, it didnt really work. i need to read more about this or do more testing to figure out how to used the driver. I havent had time to do it since ive been really busy with my other subjects so for now its not yet resolved. I might need to ask you more questions in the very near future.
Hopefully you see this right away. I wanted to know how you would register the mainframe (regardless of the fact that you dont use matlab). Ive googled it and used help for matlab and I cant find it. Also, do I only need these 3 functions to plot the power(db) vs lambda (1500-1550nm)?? So far I havent really tested which functions I need because I havent really used the driver, knowing which ones I need should make things faster.
Hi Ralph, Sorry, not right away and I can just get out a quick answer now. The mainframe registration is at function within the PnP driver, so I think you can call this like the other commands. If it is still hard to see how to use the driver with Matlab, you may want to start with a few simple commands like setting and querying instrument settings, to see how it works. The help file for the driver is the best place to get the function details.
Thanks for your questions; a few inputs from here. I have attached a Matlab example along with the 'hp816x_matlab.mdd'. All that is required to run the example would be IO Library installation and the 816x_PNP driver. The *.mdd file was created with Matlab2008A, hopefully this will be able to run on your system. Let me know if you have any questions and we can determine the next steps.