diff --git a/Makefile b/Makefile index 6cf6d8a..6647f11 100644 --- a/Makefile +++ b/Makefile @@ -50,15 +50,6 @@ BSP = bsp ############################################################################### # Objects and Paths -# main -OBJECTS += main.o - -# drivers -OBJECTS += drivers/max11300/max11300.o -OBJECTS += drivers/ad9959/ad9959.o -OBJECTS += util/dds_config.o -OBJECTS += minig.o - #### Protobuf Build # Include the nanopb provided Makefile rules include $(VPATH)/nanopb/extra/nanopb.mk @@ -69,6 +60,16 @@ OBJECTS += pb_decode.o # The nanopb decoder OBJECTS += pb_common.o # The nanopb common parts OBJECTS += gravity.pb.o # The compiled protocol definition +# drivers +OBJECTS += drivers/max11300/max11300.o +OBJECTS += drivers/ad9959/ad9959.o +OBJECTS += util/dds_config.o +OBJECTS += minig.o +OBJECTS += auto_g.o + +# main +OBJECTS += main.o + SYS_OBJECTS += $(MBED)/drivers/AnalogIn.o SYS_OBJECTS += $(MBED)/drivers/BusIn.o SYS_OBJECTS += $(MBED)/drivers/BusInOut.o @@ -438,6 +439,7 @@ all: $(PROJECT).bin $(PROJECT).hex size # Build rule for the protocol gravity.pb.c: gravity.proto $(PROTOC) $(PROTOC_OPTS) --nanopb_out=. --proto_path=$(VPATH) gravity.proto + $(PROTOC) --python_out=/mnt/c/Users/Bola/Python\ Notebooks/AutoG/ --proto_path=$(VPATH) gravity.proto .s.o: +@$(call MAKEDIR,$(dir $@)) diff --git a/backups/120.cpp b/backups/120.cpp deleted file mode 100644 index d85dc96..0000000 --- a/backups/120.cpp +++ /dev/null @@ -1,579 +0,0 @@ -#include "bsm_delay.h" -#include "minig.h" -#include "pinmap.h" - -using drivers::ad9959::AD9959; -using drivers::max11300::MAX11300; - -#define WRITE_IO(PORT, ON_BITS, OFF_BITS) \ - PORT->ODR = ((PORT->ODR & ~(OFF_BITS)) | (ON_BITS)) -#define BITS_NONE (0) - -#define ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -#define STOP \ - while (1) \ - ; - -#define SPECTROSCOPY 0 -#define RAMAN_RABI 0 -#define MW_RABI 0 -#define INTER 1 -#define DEBUG_PD 0 -#define USE_CAMERA 0 -#define CENTER_PD 0 -#define TUNE 0 - -namespace { - -constexpr AD9959::Pins dds_pins = { - PA_4, /* CS */ - D7, /* reset */ - D8, /* update */ - PE_9, /* p0 */ - PE_11 /* p1 */ -}; - -constexpr int16_t to_dac(double volts) { - return static_cast(volts / 10.0 * 0x0fff); -} - -constexpr size_t num_samples = 1200; -uint16_t samples[num_samples]; - -#define USE_20e6_CLK 0 -#if USE_20e6_CLK -#include "declare_20e6_fringes.h" -#else -// #include "declare_T_80_fringes.h" -// #include "declare_T_120_fringes.h" -#include "declare_T_120_16_fringes.h" -// #include "declare_T_115_fringes_17e_7.h" -#endif -#include "declare_spectroscopy.h" - -constexpr float AO1_MOT = 6.5; -constexpr float AO2_MOT = 1.76; -constexpr float AO3_MOT = 5; -constexpr float EO_MOT = 8.93; -constexpr float NS_MOT = 0.5; -constexpr float WE_MOT = 1.2; -constexpr float BIAS_MOT = 0.15; - -constexpr float AO1_PGC = AO1_MOT; -constexpr float AO2_PGC = 2.20; -constexpr float AO3_PGC = 1.95; -constexpr float EO_PGC = 9.78; - -constexpr float AO1_MW = 7.8; -constexpr float AO2_MW = 0; -constexpr float AO3_MW = 10; -constexpr float NS_MW = NS_MOT; -constexpr float WE_MW = 3.2; -constexpr float EO_MW = 9.21; -constexpr float BIAS_MW = 0.15; - -constexpr float AO1_RAMAN = 8.1; -constexpr float AO2_RAMAN = 3; -constexpr float NS_RAMAN = 0; -constexpr float WE_RAMAN = 0; -constexpr float EO_RAMAN = 6.5; -constexpr float BIAS_RAMAN = 6; - -constexpr float AO1_IMAGE = 7.2; -constexpr float AO2_IMAGE = 1.75; -constexpr float NS_IMAGE = 0.04; -constexpr float WE_IMAGE = 0.25; -constexpr float EO_IMAGE = 8.88; - -} // namepsace - -// clang-format off -MiniG::MiniG() : - coils_{GPIO_PIN_0}, //GPIOE - liquid_crystal_1_{GPIO_PIN_2}, //GPIOE - under_vac_shutter_{GPIO_PIN_3}, //GPIOG - ao_3_{GPIO_PIN_3}, //GPIOE - ao_2_{GPIO_PIN_4}, //GPIOE - cooling_shutter_{GPIO_PIN_5}, //GPIOE - mot_eo_{GPIO_PIN_6}, //GPIOE - raman_eo_{GPIO_PIN_7}, //GPIOE - m_lock_{GPIO_PIN_8}, //GPIOE - analog_trigger_{GPIO_PIN_12}, //GPIOE - mw_dds_profile_pin_{GPIO_PIN_11}, //GPIOE - dds_switch_{GPIO_PIN_10}, //GPIOE - inter_dds_profile_pin_{GPIO_PIN_9}, //GPIOE - scope_{GPIO_PIN_2}, //GPIOG - camera_ttl_{GPIO_PIN_13}, //GPIOE - laser_jump_{GPIO_PIN_14}, //GPIOE - m_horn_switch_{GPIO_PIN_15}, //GPIOE - - // Analog Outputs - ao1_freq_{MAX11300::PORT10}, - ao2_atten_{MAX11300::PORT11}, - ao3_atten_{MAX11300::PORT12}, - z_field_{MAX11300::PORT13}, - ns_field_{MAX11300::PORT14}, - we_field_{MAX11300::PORT15}, - eo_freq_{MAX11300::PORT16}, - bias_field_{MAX11300::PORT17}, - - // Analog Input - photodiode_{MAX11300::PORT0}, - - // DDS - dds_spi_{PB_5_ALT0, PB_4_ALT0, PB_3_ALT0}, -#if USE_20e6_CLK - dds_{dds_spi_, dds_pins, 20000000 /* ref_freq */, 20 /* mult */}, -#else - dds_{dds_spi_, dds_pins, 10000000 /* ref_freq */, 20 /* mult */}, -#endif - - // PIXI - pixi_spi_{SPI_MOSI, SPI_MISO, SPI_SCK}, - pixi_{pixi_spi_, SPI_CS} {} -// clang-format on - -// void MiniG::set_dds_params(double chirp_rate_kHz_p_ms, -// double raman_detuning_kHz) { -// -// constexpr double free_fall_time_s = .260; -// constexpr double num_steps = 500000; -// // constexpr double num_steps = 130; -// constexpr double num_steps_mw = 50000000; -// constexpr double clock_transition = 12631770; -// double chirp_start_hz = raman_detuning_kHz * 1000 + clock_transition; -// double chirp_stop_hz = -// chirp_start_hz + free_fall_time_s * 1000 * chirp_rate_kHz_p_ms * 1000; -// dds_.reset(); -// dds_.set_freq_linear_sweep_params(AD9959::Channel0, chirp_start_hz, -// chirp_stop_hz, free_fall_time_s * -// num_steps, -// 1 / num_steps); -// dds_.set_freq_linear_sweep_params(AD9959::Channel1, clock_transition, -// chirp_start_hz, .01 * num_steps_mw, -// 1 / num_steps_mw); -// dds_.io_update(); -//} -// -void MiniG::set_dds_params(dds_params_t params) { - dds_.reset(); - dds_.set_freq_linear_sweep_params( - AD9959::Channel0, params.mult, params.chirp_start_hex, - params.chirp_stop_hex, params.chirp_freq_hex, params.chirp_time_hex); - - dds_.set_freq_linear_sweep_params( - AD9959::Channel1, params.mult, params.clk_transition_hex, - params.chirp_start_hex, params.mw_freq_hex, params.mw_time_hex); - dds_.io_update(); -} - -void MiniG::init() { - __HAL_RCC_GPIOE_CLK_ENABLE(); - - __HAL_RCC_GPIOG_CLK_ENABLE(); - - for (int pin = 0; pin < 16; pin++) { - pin_function(port_pin(PortE, pin), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - } - pin_function(port_pin(PortG, 2), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - pin_function(port_pin(PortG, 3), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - - // Ramps for Analog IO - // clang-format off - MAX11300::Ramp mot_on_ramps[] = { - {ns_field_, to_dac(0), to_dac(NS_MOT)}, - {we_field_, to_dac(0), to_dac(WE_MOT)}, - {bias_field_, to_dac(0), to_dac(BIAS_MOT)}, - }; - mot_on_ramp_.configured = 0; - mot_on_ramp_.num_ramps = ARRAYSIZE(mot_on_ramps); - mot_on_ramp_.num_steps = 30; - mot_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&mot_on_ramp_, mot_on_ramps); - - MAX11300::Ramp pgc_on_ramps[] = { - // {ao1_freq_, to_dac(0O1_MOT), to_dac(AO1_PGC)}, - {ao2_atten_, to_dac(AO2_MOT), to_dac(AO2_PGC)}, - {ao3_atten_, to_dac(AO3_MOT), to_dac(AO3_PGC)}, - {eo_freq_, to_dac(EO_MOT), to_dac(EO_PGC)}, - }; - pgc_on_ramp_.configured = 0; - pgc_on_ramp_.num_ramps = ARRAYSIZE(pgc_on_ramps); - pgc_on_ramp_.num_steps = 5; - pgc_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&pgc_on_ramp_, pgc_on_ramps); - - MAX11300::Ramp mw_on_ramps[] = { - {ao1_freq_, to_dac(AO1_PGC), to_dac(AO1_MW)}, - {ao2_atten_, to_dac(AO2_PGC), to_dac(AO2_MW)}, - {ao3_atten_, to_dac(AO3_PGC), to_dac(AO3_MW)}, - {we_field_, to_dac(WE_MOT), to_dac(WE_MW)}, - {eo_freq_, to_dac(EO_PGC), to_dac(EO_MW)}, - }; - mw_on_ramp_.configured = 0; - mw_on_ramp_.num_ramps = ARRAYSIZE(mw_on_ramps); - mw_on_ramp_.num_steps = 30; - mw_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&mw_on_ramp_, mw_on_ramps); - - MAX11300::Ramp raman_on_ramps[] = { - //2ms - {ao1_freq_, to_dac(AO1_MW), to_dac(AO1_RAMAN)}, - {ao2_atten_, to_dac(AO2_MW), to_dac(AO2_RAMAN)}, - // Should be 5ms - {ns_field_, to_dac(NS_MOT), to_dac(NS_RAMAN)}, - {we_field_, to_dac(WE_MW), to_dac(WE_RAMAN)}, - // 2 ms - {eo_freq_, to_dac(EO_MW), to_dac(EO_RAMAN)}, - // should be 5 ms again - {bias_field_, to_dac(BIAS_MOT), to_dac(BIAS_RAMAN)}, - }; - raman_on_ramp_.configured = 0; - raman_on_ramp_.num_ramps = ARRAYSIZE(raman_on_ramps); - raman_on_ramp_.num_steps = 50; - raman_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&raman_on_ramp_, raman_on_ramps); - - MAX11300::Ramp image_on_ramps[] = { - {ao1_freq_, to_dac(AO1_RAMAN), to_dac(AO1_IMAGE)}, - {ao2_atten_, to_dac(AO2_RAMAN), to_dac(AO2_IMAGE)}, - {eo_freq_, to_dac(EO_RAMAN), to_dac(EO_IMAGE)}, - {ns_field_, to_dac(NS_RAMAN), to_dac(NS_IMAGE)}, - {we_field_, to_dac(WE_RAMAN), to_dac(WE_IMAGE)}, - }; - image_on_ramp_.configured = 0; - image_on_ramp_.num_ramps = ARRAYSIZE(image_on_ramps); - image_on_ramp_.num_steps = 30; - image_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&image_on_ramp_, image_on_ramps); - // clang-format on - - // Note: Do not reset after initializing, or you'll waste time debugging for - // no reason. - dds_.init(); - pixi_.init(); - // set_dds_params(22.9, 720); - set_dds_params(fringes[0]); - reset(AO1_MOT); -} - -void MiniG::reset(float var) { - WRITE_IO(GPIOE, liquid_crystal_1_ | ao_3_ | raman_eo_ | m_lock_ | - dds_switch_ | m_horn_switch_, - coils_ | ao_2_ | cooling_shutter_ | mot_eo_ | raman_eo_ | - analog_trigger_ | camera_ttl_ | laser_jump_ | - mw_dds_profile_pin_ | inter_dds_profile_pin_); - WRITE_IO(GPIOG, BITS_NONE, under_vac_shutter_ | scope_); - - pixi_.single_ended_dac_write(ao1_freq_, to_dac(AO1_MOT)); - pixi_.single_ended_dac_write(ao2_atten_, to_dac(AO2_MOT)); - pixi_.single_ended_dac_write(ao3_atten_, to_dac(AO3_MOT)); - pixi_.single_ended_dac_write(z_field_, to_dac(0)); - pixi_.single_ended_dac_write(ns_field_, to_dac(0)); - pixi_.single_ended_dac_write(we_field_, to_dac(0)); - pixi_.single_ended_dac_write(eo_freq_, to_dac(EO_MOT)); - pixi_.single_ended_dac_write(bias_field_, to_dac(0)); - -#if TUNE - // MAX11300::Ramp image_on_ramps[] = { - // {ao1_freq_, to_dac(AO1_RAMAN), to_dac(var)}, - // {ao2_atten_, to_dac(AO2_RAMAN), to_dac(AO2_IMAGE)}, - // {eo_freq_, to_dac(EO_RAMAN), to_dac(EO_IMAGE)}, - // {ns_field_, to_dac(NS_RAMAN), to_dac(NS_IMAGE)}, - // {we_field_, to_dac(WE_RAMAN), to_dac(WE_IMAGE)}, - // }; - // image_on_ramp_.configured = 1; - // image_on_ramp_.num_ramps = ARRAYSIZE(image_on_ramps); - // image_on_ramp_.num_steps = 30; - // image_on_ramp_.step_time_us = 100; - // pixi_.prepare_ramps(&image_on_ramp_, image_on_ramps); - - // MAX11300::Ramp pgc_on_ramps[] = { - // // {ao1_freq_, to_dac(AO1_MOT), to_dac(AO1_PGC)}, - // {ao2_atten_, to_dac(AO2_MOT), to_dac(var)}, - // {ao3_atten_, to_dac(AO3_MOT), to_dac(AO3_PGC)}, - // {eo_freq_, to_dac(EO_MOT), to_dac(EO_PGC)}, - // }; - // pgc_on_ramp_.configured = 1; - // pgc_on_ramp_.num_ramps = ARRAYSIZE(pgc_on_ramps); - // pgc_on_ramp_.num_steps = 5; - // pgc_on_ramp_.step_time_us = 100; - // pixi_.prepare_ramps(&pgc_on_ramp_, pgc_on_ramps); - -#endif - bsm_delay_ms(2); -} - -void MiniG::run() { -#if TUNE - for(float var = 6.0; var <= 8.0; var += 0.1) { -#endif -#if CENTER_PD - for(float d_fall = -2500; d_fall <= 6000; d_fall += 500) { -#endif -#if MW_RABI - for (int pulse = 0; pulse <= 800; pulse += 20) { -#endif -#if RAMAN_RABI - for (uint32_t raman = 0; raman <= 30; raman += 1) { -#endif -#if SPECTROSCOPY - for (size_t j = 0; j < NUM_POINTS_SPEC; j++) { - set_dds_params(specs[j]); -#endif -#if INTER - for (size_t j = 0; j < NUM_POINTS_INTER; j++) { - set_dds_params(fringes[j]); -#endif -#if RAMAN_RABI - set_dds_params(fringes[0]); -#endif -#if TUNE - reset(var); -#else - reset(AO1_MOT); -#endif - mot(); - pgc(); - -#if !MW_RABI - int pulse = 250; -#endif - mw(pulse); - uint32_t T = 120; - float fall_ms = 3.5; - uint32_t fall_us = static_cast(fall_ms * 1000); -#if CENTER_PD - fall_us += d_fall; -#endif - -#if !RAMAN_RABI - uint32_t raman = 8; -#endif - interferometry(T, fall_us, raman); - - image(); -#if USE_CAMERA - bsm_delay_ms(300); -#endif - -#if SPECTROSCOPY - printf("rd: %f\n", specs[j].detuning); -#elif INTER - printf("rd: %f\n", fringes[j].actual_chirp); -#elif MW_RABI - printf("rd: %d\n", pulse); -#elif RAMAN_RABI - printf("rd: %lu\n", raman); -#elif CENTER_PD - printf("rd: %f\n", d_fall); -#elif TUNE - printf("rd: %f\n", var); -#endif - uint32_t f4 = 0, f34 = 0, bg = 6; - size_t i = 0; -#if DEBUG_PD - printf("ListPlot[{"); -#endif - for (; i < 127; i++) { - f4 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127; i++) { - f34 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127 + 127; i++) { - bg += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } -#if DEBUG_PD - printf("}]\n\n"); -#endif - double detection = - (static_cast(f4) - static_cast(bg)) / - (static_cast(f34) - static_cast(bg)); -#if MW_RABI | CENTER_PD | TUNE - printf("fr: %lu\n", f34 - bg); -#elif RAMAN_RABI | SPECTROSCOPY | INTER - printf("fr: %f\n", detection); - printf("atom_num: %lu\n\n", f34 - bg); -#endif -#if CENTER_PD | RAMAN_RABI | SPECTROSCOPY | INTER | MW_RABI | TUNE - } -#endif - } - - void MiniG::mot() { - WRITE_IO(GPIOE, ao_2_ | cooling_shutter_, m_lock_); - - pixi_.run_ramps(&mot_on_ramp_); - - // Actual MOT Stage - WRITE_IO(GPIOE, coils_, BITS_NONE); - bsm_delay_ms(130); - - // Turn the MOT off - WRITE_IO(GPIOE, BITS_NONE, coils_); - - bsm_delay_ms(9); - } - - void MiniG::pgc() { - WRITE_IO(GPIOE, laser_jump_, BITS_NONE); - pixi_.run_ramps(&pgc_on_ramp_); - bsm_delay_us(500); - - // Just hold it to cool - bsm_delay_ms(10); - - // Turn off PGC - WRITE_IO(GPIOE, BITS_NONE, cooling_shutter_); - bsm_delay_ms(7); - } - - void MiniG::mw(int pulse_duration) { - WRITE_IO(GPIOE, cooling_shutter_, - laser_jump_ | liquid_crystal_1_ | ao_2_ | ao_3_); - - pixi_.run_ramps(&mw_on_ramp_); - bsm_delay_ms(2); - - // Actually turn on Microwave - WRITE_IO(GPIOE, BITS_NONE, m_horn_switch_); - bsm_delay_us(pulse_duration); - - // Stop Microwave - WRITE_IO(GPIOE, m_horn_switch_, BITS_NONE); - bsm_delay_ms(1); - - // Blow away - WRITE_IO(GPIOE, - ao_3_ | - mot_eo_ | mw_dds_profile_pin_, BITS_NONE); -#if MW_RABI - bsm_delay_us(10000); -#else - bsm_delay_us(10000 - pulse_duration); -#endif - } - - // Start Interformetry - void MiniG::interferometry(uint32_t T, uint32_t fall, uint32_t raman) { - WRITE_IO(GPIOE, BITS_NONE, - ao_3_ | cooling_shutter_ | raman_eo_ | dds_switch_); - pixi_.run_ramps(&raman_on_ramp_); - // last 5 ms - bsm_delay_ms(5); - - WRITE_IO(GPIOG, scope_, BITS_NONE); - // Freefall - WRITE_IO(GPIOE, inter_dds_profile_pin_ | ao_3_, BITS_NONE); - bsm_delay_ms(5); - -#if INTER - WRITE_IO(GPIOE, ao_2_, BITS_NONE); - bsm_delay_us(5); -#endif - WRITE_IO(GPIOE, BITS_NONE, ao_2_); - - bsm_delay_ms(1); - WRITE_IO(GPIOE, BITS_NONE, ao_3_); - - bsm_delay_ms(T - 6); - - WRITE_IO(GPIOE, ao_3_, BITS_NONE); - bsm_delay_ms(5); - -#if INTER | SPECTROSCOPY - WRITE_IO(GPIOE, ao_2_, BITS_NONE); - bsm_delay_us(10); -#elif RAMAN_RABI - WRITE_IO(GPIOE, ao_2_, BITS_NONE); - bsm_delay_us(raman); -#endif - WRITE_IO(GPIOE, BITS_NONE, ao_2_); - bsm_delay_ms(1); - WRITE_IO(GPIOE, BITS_NONE, ao_3_); - - bsm_delay_ms(T - 6); - - WRITE_IO(GPIOE, ao_3_, BITS_NONE); - bsm_delay_ms(5); -#if INTER - WRITE_IO(GPIOE, ao_2_, BITS_NONE); - bsm_delay_us(5); -#endif - - WRITE_IO(GPIOE, BITS_NONE, ao_2_); - bsm_delay_ms(1); - WRITE_IO(GPIOE, BITS_NONE, ao_3_); - - WRITE_IO(GPIOG, BITS_NONE, scope_); - bsm_delay_us(fall); - - // Stop sweeping - } - - void MiniG::image() { - WRITE_IO(GPIOE, cooling_shutter_ | dds_switch_ | raman_eo_, BITS_NONE); - pixi_.run_ramps(&image_on_ramp_); - // takes 3 ms - bsm_delay_ms(7); - - // Stabilize - WRITE_IO(GPIOE, BITS_NONE, mot_eo_); - bsm_delay_ms(2); - bsm_delay_us(50); - - // Turn laser on - WRITE_IO(GPIOE, m_lock_ | ao_3_ -#if USE_CAMERA - | camera_ttl_ -#endif - , - BITS_NONE); - // TODO(bsm): write code for this in a minute - bsm_delay_us(20); - pixi_.max_speed_adc_read(photodiode_, samples, 127); - - // Repumping Stage - WRITE_IO(GPIOE, ao_2_, BITS_NONE -#if USE_CAMERA - | camera_ttl_ -#endif - ); - bsm_delay_us(150); - - // Second Sample - WRITE_IO(GPIOE, BITS_NONE, ao_2_); - pixi_.max_speed_adc_read(photodiode_, &samples[127], 127); - - // Wait before background - bsm_delay_ms(5); - - // Third detection for background - pixi_.max_speed_adc_read(photodiode_, &samples[127 + 127], 127); - -#if USE_CAMERA - // Wait long time before Camera Background - bsm_delay_ms(40); - - // Take background image - WRITE_IO(GPIOE, camera_ttl_, BITS_NONE); - - bsm_delay_ms(10); -#endif - } diff --git a/backups/130.cpp b/backups/130.cpp deleted file mode 100644 index d3b4302..0000000 --- a/backups/130.cpp +++ /dev/null @@ -1,567 +0,0 @@ -#include "bsm_delay.h" -#include "minig.h" -#include "pinmap.h" - -using drivers::ad9959::AD9959; -using drivers::max11300::MAX11300; - -#define WRITE_IO(PORT, ON_BITS, OFF_BITS) \ - PORT->ODR = ((PORT->ODR & ~(OFF_BITS)) | (ON_BITS)) -#define BITS_NONE (0) - -#define ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -#define STOP \ - while (1) \ - ; - -#define SPECTROSCOPY 0 -#define RAMAN_RABI 0 -#define MW_RABI 0 -#define INTER 0 -#define DEBUG_PD 0 -#define USE_CAMERA 0 -#define CENTER_PD 0 -#define TUNE 1 - -namespace { - -constexpr AD9959::Pins dds_pins = { - PA_4, /* CS */ - D7, /* reset */ - D8, /* update */ - PE_9, /* p0 */ - PE_11 /* p1 */ -}; - -constexpr int16_t to_dac(double volts) { - return static_cast(volts / 10.0 * 0x0fff); -} - -constexpr size_t num_samples = 1200; -uint16_t samples[num_samples]; - -#define USE_20e6_CLK 0 -#if USE_20e6_CLK -#include "declare_20e6_fringes.h" -#else -// #include "declare_T_80_fringes.h" -// #include "declare_T_120_fringes.h" -#include "declare_T_120_16_fringes.h" -// #include "declare_T_115_fringes_17e_7.h" -#endif -#include "declare_spectroscopy.h" - -constexpr float AO1_MOT = 6.6; -constexpr float AO2_MOT = 1.76; -constexpr float AO3_MOT = 5; -constexpr float EO_MOT = 8.93; -constexpr float NS_MOT = 0.5; -constexpr float WE_MOT = 1.2; -constexpr float BIAS_MOT = 0.15; - -constexpr float AO1_PGC = AO1_MOT; -constexpr float AO2_PGC = 2.20; -constexpr float AO3_PGC = 1.95; -constexpr float EO_PGC = 9.78; - -constexpr float AO1_MW = 7.8; -constexpr float AO2_MW = 0; -constexpr float AO3_MW = 10; -constexpr float NS_MW = NS_MOT; -constexpr float WE_MW = 3.2; -constexpr float EO_MW = 9.21; -constexpr float BIAS_MW = 0.15; - -constexpr float AO1_RAMAN = 8.1; -constexpr float AO2_RAMAN = 3; -constexpr float NS_RAMAN = 0; -constexpr float WE_RAMAN = 0; -constexpr float EO_RAMAN = 6.5; -constexpr float BIAS_RAMAN = 6; - -constexpr float AO1_IMAGE = 7.2; -constexpr float AO2_IMAGE = 1.75; -constexpr float NS_IMAGE = 0.04; -constexpr float WE_IMAGE = 0.25; -constexpr float EO_IMAGE = 8.88; - -} // namepsace - -// clang-format off -MiniG::MiniG() : - coils_{GPIO_PIN_0}, //GPIOE - liquid_crystal_1_{GPIO_PIN_2}, //GPIOE - under_vac_shutter_{GPIO_PIN_3}, //GPIOG - ao_3_{GPIO_PIN_3}, //GPIOE - ao_2_{GPIO_PIN_4}, //GPIOE - cooling_shutter_{GPIO_PIN_5}, //GPIOE - mot_eo_{GPIO_PIN_6}, //GPIOE - raman_eo_{GPIO_PIN_7}, //GPIOE - m_lock_{GPIO_PIN_8}, //GPIOE - analog_trigger_{GPIO_PIN_12}, //GPIOE - mw_dds_profile_pin_{GPIO_PIN_11}, //GPIOE - dds_switch_{GPIO_PIN_10}, //GPIOE - inter_dds_profile_pin_{GPIO_PIN_9}, //GPIOE - scope_{GPIO_PIN_2}, //GPIOG - camera_ttl_{GPIO_PIN_13}, //GPIOE - laser_jump_{GPIO_PIN_14}, //GPIOE - m_horn_switch_{GPIO_PIN_15}, //GPIOE - - // Analog Outputs - ao1_freq_{MAX11300::PORT10}, - ao2_atten_{MAX11300::PORT11}, - ao3_atten_{MAX11300::PORT12}, - z_field_{MAX11300::PORT13}, - ns_field_{MAX11300::PORT14}, - we_field_{MAX11300::PORT15}, - eo_freq_{MAX11300::PORT16}, - bias_field_{MAX11300::PORT17}, - - // Analog Input - photodiode_{MAX11300::PORT0}, - - // DDS - dds_spi_{PB_5_ALT0, PB_4_ALT0, PB_3_ALT0}, -#if USE_20e6_CLK - dds_{dds_spi_, dds_pins, 20000000 /* ref_freq */, 20 /* mult */}, -#else - dds_{dds_spi_, dds_pins, 10000000 /* ref_freq */, 20 /* mult */}, -#endif - - // PIXI - pixi_spi_{SPI_MOSI, SPI_MISO, SPI_SCK}, - pixi_{pixi_spi_, SPI_CS} {} -// clang-format on - -// void MiniG::set_dds_params(double chirp_rate_kHz_p_ms, -// double raman_detuning_kHz) { -// -// constexpr double free_fall_time_s = .260; -// constexpr double num_steps = 500000; -// // constexpr double num_steps = 130; -// constexpr double num_steps_mw = 50000000; -// constexpr double clock_transition = 12631770; -// double chirp_start_hz = raman_detuning_kHz * 1000 + clock_transition; -// double chirp_stop_hz = -// chirp_start_hz + free_fall_time_s * 1000 * chirp_rate_kHz_p_ms * 1000; -// dds_.reset(); -// dds_.set_freq_linear_sweep_params(AD9959::Channel0, chirp_start_hz, -// chirp_stop_hz, free_fall_time_s * -// num_steps, -// 1 / num_steps); -// dds_.set_freq_linear_sweep_params(AD9959::Channel1, clock_transition, -// chirp_start_hz, .01 * num_steps_mw, -// 1 / num_steps_mw); -// dds_.io_update(); -//} -// -void MiniG::set_dds_params(dds_params_t params) { - dds_.reset(); - dds_.set_freq_linear_sweep_params( - AD9959::Channel0, params.mult, params.chirp_start_hex, - params.chirp_stop_hex, params.chirp_freq_hex, params.chirp_time_hex); - - dds_.set_freq_linear_sweep_params( - AD9959::Channel1, params.mult, params.clk_transition_hex, - params.chirp_start_hex, params.mw_freq_hex, params.mw_time_hex); - dds_.io_update(); -} - -void MiniG::init() { - __HAL_RCC_GPIOE_CLK_ENABLE(); - - __HAL_RCC_GPIOG_CLK_ENABLE(); - - for (int pin = 0; pin < 16; pin++) { - pin_function(port_pin(PortE, pin), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - } - pin_function(port_pin(PortG, 2), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - pin_function(port_pin(PortG, 3), - STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); - - // Ramps for Analog IO - // clang-format off - MAX11300::Ramp mot_on_ramps[] = { - {ns_field_, to_dac(0), to_dac(NS_MOT)}, - {we_field_, to_dac(0), to_dac(WE_MOT)}, - {bias_field_, to_dac(0), to_dac(BIAS_MOT)}, - }; - mot_on_ramp_.configured = 0; - mot_on_ramp_.num_ramps = ARRAYSIZE(mot_on_ramps); - mot_on_ramp_.num_steps = 30; - mot_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&mot_on_ramp_, mot_on_ramps); - - MAX11300::Ramp pgc_on_ramps[] = { - // {ao1_freq_, to_dac(0O1_MOT), to_dac(AO1_PGC)}, - {ao2_atten_, to_dac(AO2_MOT), to_dac(AO2_PGC)}, - {ao3_atten_, to_dac(AO3_MOT), to_dac(AO3_PGC)}, - {eo_freq_, to_dac(EO_MOT), to_dac(EO_PGC)}, - }; - pgc_on_ramp_.configured = 0; - pgc_on_ramp_.num_ramps = ARRAYSIZE(pgc_on_ramps); - pgc_on_ramp_.num_steps = 5; - pgc_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&pgc_on_ramp_, pgc_on_ramps); - - MAX11300::Ramp mw_on_ramps[] = { - {ao1_freq_, to_dac(AO1_PGC), to_dac(AO1_MW)}, - {ao2_atten_, to_dac(AO2_PGC), to_dac(AO2_MW)}, - {ao3_atten_, to_dac(AO3_PGC), to_dac(AO3_MW)}, - {we_field_, to_dac(WE_MOT), to_dac(WE_MW)}, - {eo_freq_, to_dac(EO_PGC), to_dac(EO_MW)}, - }; - mw_on_ramp_.configured = 0; - mw_on_ramp_.num_ramps = ARRAYSIZE(mw_on_ramps); - mw_on_ramp_.num_steps = 30; - mw_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&mw_on_ramp_, mw_on_ramps); - - MAX11300::Ramp raman_on_ramps[] = { - //2ms - {ao1_freq_, to_dac(AO1_MW), to_dac(AO1_RAMAN)}, - {ao2_atten_, to_dac(AO2_MW), to_dac(AO2_RAMAN)}, - // Should be 5ms - {ns_field_, to_dac(NS_MOT), to_dac(NS_RAMAN)}, - {we_field_, to_dac(WE_MW), to_dac(WE_RAMAN)}, - // 2 ms - {eo_freq_, to_dac(EO_MW), to_dac(EO_RAMAN)}, - // should be 5 ms again - {bias_field_, to_dac(BIAS_MOT), to_dac(BIAS_RAMAN)}, - }; - raman_on_ramp_.configured = 0; - raman_on_ramp_.num_ramps = ARRAYSIZE(raman_on_ramps); - raman_on_ramp_.num_steps = 50; - raman_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&raman_on_ramp_, raman_on_ramps); - - MAX11300::Ramp image_on_ramps[] = { - {ao1_freq_, to_dac(AO1_RAMAN), to_dac(AO1_IMAGE)}, - {ao2_atten_, to_dac(AO2_RAMAN), to_dac(AO2_IMAGE)}, - {eo_freq_, to_dac(EO_RAMAN), to_dac(EO_IMAGE)}, - {ns_field_, to_dac(NS_RAMAN), to_dac(NS_IMAGE)}, - {we_field_, to_dac(WE_RAMAN), to_dac(WE_IMAGE)}, - }; - image_on_ramp_.configured = 0; - image_on_ramp_.num_ramps = ARRAYSIZE(image_on_ramps); - image_on_ramp_.num_steps = 30; - image_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&image_on_ramp_, image_on_ramps); - // clang-format on - - // Note: Do not reset after initializing, or you'll waste time debugging for - // no reason. - dds_.init(); - pixi_.init(); - // set_dds_params(22.9, 720); - set_dds_params(fringes[0]); - reset(AO1_MOT); -} - -void MiniG::reset(float var) { - WRITE_IO(GPIOE, liquid_crystal_1_ | ao_3_ | raman_eo_ | m_lock_ | - dds_switch_ | m_horn_switch_, - coils_ | ao_2_ | cooling_shutter_ | mot_eo_ | raman_eo_ | - analog_trigger_ | camera_ttl_ | laser_jump_ | - mw_dds_profile_pin_ | inter_dds_profile_pin_); - WRITE_IO(GPIOG, BITS_NONE, under_vac_shutter_ | scope_); - - // pixi_.single_ended_dac_write(ao1_freq_, to_dac(AO1_MOT)); - pixi_.single_ended_dac_write(ao2_atten_, to_dac(AO2_MOT)); - pixi_.single_ended_dac_write(ao3_atten_, to_dac(AO3_MOT)); - pixi_.single_ended_dac_write(z_field_, to_dac(0)); - pixi_.single_ended_dac_write(ns_field_, to_dac(0)); - pixi_.single_ended_dac_write(we_field_, to_dac(0)); - pixi_.single_ended_dac_write(eo_freq_, to_dac(EO_MOT)); - pixi_.single_ended_dac_write(bias_field_, to_dac(0)); - -#if TUNE - MAX11300::Ramp image_on_ramps[] = { - {ao1_freq_, to_dac(AO1_RAMAN), to_dac(var)}, - {ao2_atten_, to_dac(AO2_RAMAN), to_dac(AO2_IMAGE)}, - {eo_freq_, to_dac(EO_RAMAN), to_dac(EO_IMAGE)}, - {ns_field_, to_dac(NS_RAMAN), to_dac(NS_IMAGE)}, - {we_field_, to_dac(WE_RAMAN), to_dac(WE_IMAGE)}, - }; - image_on_ramp_.configured = 1; - image_on_ramp_.num_ramps = ARRAYSIZE(image_on_ramps); - image_on_ramp_.num_steps = 30; - image_on_ramp_.step_time_us = 100; - pixi_.prepare_ramps(&image_on_ramp_, image_on_ramps); - - // MAX11300::Ramp pgc_on_ramps[] = { - // // {ao1_freq_, to_dac(AO1_MOT), to_dac(AO1_PGC)}, - // {ao2_atten_, to_dac(AO2_MOT), to_dac(var)}, - // {ao3_atten_, to_dac(AO3_MOT), to_dac(AO3_PGC)}, - // {eo_freq_, to_dac(EO_MOT), to_dac(EO_PGC)}, - // }; - // pgc_on_ramp_.configured = 1; - // pgc_on_ramp_.num_ramps = ARRAYSIZE(pgc_on_ramps); - // pgc_on_ramp_.num_steps = 5; - // pgc_on_ramp_.step_time_us = 100; - // pixi_.prepare_ramps(&pgc_on_ramp_, pgc_on_ramps); - -#endif - bsm_delay_ms(2); -} - -void MiniG::run() { -#if TUNE - for(float var = 6.9; var <= 7.5; var += 0.1) { -#endif -#if CENTER_PD - for(float d_fall = -3000; d_fall <= 0; d_fall += 500) { -#endif -#if MW_RABI - for (int pulse = 0; pulse <= 800; pulse += 20) { -#endif -#if RAMAN_RABI - for (uint32_t raman = 0; raman <= 30; raman += 1) { -#endif -#if SPECTROSCOPY - for (size_t j = 0; j < NUM_POINTS_SPEC; j++) { - set_dds_params(specs[j]); -#endif -#if INTER - for (size_t j = 0; j < NUM_POINTS_INTER; j++) { - set_dds_params(fringes[j]); -#endif -#if RAMAN_RABI - set_dds_params(fringes[0]); -#endif -#if TUNE - reset(var); -#else - reset(AO1_MOT); -#endif - mot(); - pgc(); - -#if !MW_RABI - int pulse = 250; -#endif - mw(pulse); - uint32_t T = 130; - float fall_ms = 0.5; - uint32_t fall_us = static_cast(fall_ms * 1000); -#if CENTER_PD - fall_us += d_fall; -#endif - -#if !RAMAN_RABI - uint32_t raman = 8; -#endif - interferometry(T, fall_us, raman); - - image(); -#if USE_CAMERA - bsm_delay_ms(300); -#endif - -#if SPECTROSCOPY - printf("rd: %f\n", specs[j].detuning); -#elif INTER - printf("rd: %f\n", fringes[j].actual_chirp); -#elif MW_RABI - printf("rd: %d\n", pulse); -#elif RAMAN_RABI - printf("rd: %lu\n", raman); -#elif CENTER_PD - printf("rd: %f\n", d_fall); -#elif TUNE - printf("rd: %f\n", var); -#endif - uint32_t f4 = 0, f34 = 0, bg = 6; - size_t i = 0; -#if DEBUG_PD - printf("ListPlot[{"); -#endif - for (; i < 127; i++) { - f4 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127; i++) { - f34 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127 + 127; i++) { - bg += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } -#if DEBUG_PD - printf("}]\n\n"); -#endif - double detection = - (static_cast(f4) - static_cast(bg)) / - (static_cast(f34) - static_cast(bg)); -#if MW_RABI | CENTER_PD | TUNE - printf("fr: %lu\n", f34 - bg); -#elif RAMAN_RABI | SPECTROSCOPY | INTER - printf("fr: %f\n", detection); - printf("atom_num: %lu\n\n", f34 - bg); -#endif -#if CENTER_PD | RAMAN_RABI | SPECTROSCOPY | INTER | MW_RABI | TUNE - } -#endif - } - - void MiniG::mot() { - WRITE_IO(GPIOE, ao_2_ | cooling_shutter_, m_lock_); - - pixi_.run_ramps(&mot_on_ramp_); - - // Actual MOT Stage - WRITE_IO(GPIOE, coils_, BITS_NONE); - bsm_delay_ms(130); - - // Turn the MOT off - WRITE_IO(GPIOE, BITS_NONE, coils_); - - bsm_delay_ms(9); - } - - void MiniG::pgc() { - WRITE_IO(GPIOE, laser_jump_, BITS_NONE); - pixi_.run_ramps(&pgc_on_ramp_); - bsm_delay_us(500); - - // Just hold it to cool - bsm_delay_ms(10); - - // Turn off PGC - WRITE_IO(GPIOE, BITS_NONE, cooling_shutter_); - bsm_delay_ms(6); - } - - void MiniG::mw(int pulse_duration) { - WRITE_IO(GPIOE, cooling_shutter_, - laser_jump_ | liquid_crystal_1_ | ao_2_ | ao_3_); - - pixi_.run_ramps(&mw_on_ramp_); - bsm_delay_ms(2); - - // Actually turn on Microwave - WRITE_IO(GPIOE, BITS_NONE, m_horn_switch_); - bsm_delay_us(pulse_duration); - - // Stop Microwave - WRITE_IO(GPIOE, m_horn_switch_, BITS_NONE); - bsm_delay_ms(1); - - // Blow away - WRITE_IO(GPIOE, - ao_3_ | - mot_eo_ | mw_dds_profile_pin_, BITS_NONE); -#if MW_RABI - bsm_delay_us(4000); -#else - bsm_delay_us(4000 - pulse_duration); -#endif - } - - // Start Interformetry - void MiniG::interferometry(uint32_t T, uint32_t fall, uint32_t raman) { - WRITE_IO(GPIOE, BITS_NONE, - ao_3_ | cooling_shutter_ | raman_eo_ | dds_switch_); - pixi_.run_ramps(&raman_on_ramp_); - // last 5 ms - bsm_delay_ms(2); - - WRITE_IO(GPIOG, scope_, BITS_NONE); - // Freefall - WRITE_IO(GPIOE, inter_dds_profile_pin_, BITS_NONE); - -#if INTER - WRITE_IO(GPIOE, ao_2_|ao_3_, BITS_NONE); - bsm_delay_us(5); -#endif - WRITE_IO(GPIOE, BITS_NONE, ao_2_|ao_3_); - - bsm_delay_ms(T); - - -#if INTER | SPECTROSCOPY - WRITE_IO(GPIOE, ao_2_|ao_3_, BITS_NONE); - bsm_delay_us(10); -#elif RAMAN_RABI - WRITE_IO(GPIOE, ao_2_|ao_3_, BITS_NONE); - bsm_delay_us(raman); -#endif - WRITE_IO(GPIOE, BITS_NONE, ao_2_|ao_3_); - - bsm_delay_ms(T); - -#if INTER - WRITE_IO(GPIOE, ao_2_|ao_3_, BITS_NONE); - bsm_delay_us(5); -#endif - - WRITE_IO(GPIOE, BITS_NONE, ao_2_|ao_3_); - - WRITE_IO(GPIOG, BITS_NONE, scope_); - bsm_delay_us(fall); - - // Stop sweeping - } - - void MiniG::image() { - WRITE_IO(GPIOE, cooling_shutter_ | dds_switch_ | raman_eo_, BITS_NONE); - pixi_.run_ramps(&image_on_ramp_); - // takes 3 ms - bsm_delay_ms(7); - - // Stabilize - WRITE_IO(GPIOE, BITS_NONE, mot_eo_); - bsm_delay_ms(1); - bsm_delay_us(50); - - // Turn laser on - WRITE_IO(GPIOE, m_lock_ | ao_3_ -#if USE_CAMERA - | camera_ttl_ -#endif - , - BITS_NONE); - // TODO(bsm): write code for this in a minute - bsm_delay_us(20); - pixi_.max_speed_adc_read(photodiode_, samples, 127); - - // Repumping Stage - WRITE_IO(GPIOE, ao_2_, BITS_NONE -#if USE_CAMERA - | camera_ttl_ -#endif - ); - bsm_delay_us(150); - - // Second Sample - WRITE_IO(GPIOE, BITS_NONE, ao_2_); - pixi_.max_speed_adc_read(photodiode_, &samples[127], 127); - - // Wait before background - bsm_delay_ms(5); - - // Third detection for background - pixi_.max_speed_adc_read(photodiode_, &samples[127 + 127], 127); - -#if USE_CAMERA - // Wait long time before Camera Background - bsm_delay_ms(40); - - // Take background image - WRITE_IO(GPIOE, camera_ttl_, BITS_NONE); - - bsm_delay_ms(10); -#endif - } diff --git a/experiment/settings.h b/experiment/settings.h index e680c42..376e483 100644 --- a/experiment/settings.h +++ b/experiment/settings.h @@ -54,7 +54,7 @@ constexpr float NS_IMAGE = 0.04; constexpr float WE_IMAGE = 0.25; constexpr float EO_IMAGE = 8.88; -#define K_UP 0 +#define K_UP 1 // DDS Paramaeters // TODO(split out for different experiment and maybe pass in as object) diff --git a/gravity.proto b/gravity.proto index 9373b7a..a1c60e5 100644 --- a/gravity.proto +++ b/gravity.proto @@ -4,21 +4,24 @@ syntax = "proto2"; package minig; -message DDS { - required uint32 mult = 1; - required uint32 clk_transition_hex = 2; - required uint32 chirp_start_hex = 3; - required uint32 chirp_stop_hex = 4; - required uint32 mw_time_hex = 5; - required uint32 mw_freq_hex = 6; - required uint32 chirp_time_hex = 7; - required uint32 chirp_freq_hex = 8; - required float actual_chirp = 9; - required float detuning = 10; +message RunExperimentShot { + required uint32 T_ms = 1; + required uint32 mult = 2; + required uint32 clk_transition_hex = 3; + required uint32 chirp_start_hex = 4; + required uint32 chirp_stop_hex = 5; + required uint32 mw_time_hex = 6; + required uint32 mw_freq_hex = 7; + required uint32 chirp_time_hex = 8; + required uint32 chirp_freq_hex = 9; + + // If negative, automatically implies k-down configuration. + required float actual_chirp = 10; + required float detuning = 11; } -message FringeParams { - repeated DDS k_up_params = 1; - repeated DDS k_down_params = 2; +message Result { + required float pd_fraction = 1; + required float atom_number = 2; } diff --git a/main.cpp b/main.cpp index 598aa2f..9d241c2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,85 +1,48 @@ /*********************************** -Copyright ©2019. The Regents of the University of California (Regents). All Rights Reserved. -Permission to use, copy, modify, and distribute this software and its documentation for -educational, research, and not-for-profit purposes, without fee and without a signed licensing -agreement, is hereby granted, provided that the above copyright notice, this paragraph and the -following two paragraphs appear in all copies, modifications, and distributions. Contact The Office -of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, -(510) 643-7201, otl@berkeley.edu, http://ipira.berkeley.edu/industry-info for commercial licensing +Copyright ©2019. The Regents of the University of California (Regents). All +Rights Reserved. +Permission to use, copy, modify, and distribute this software and its +documentation for +educational, research, and not-for-profit purposes, without fee and without a +signed licensing +agreement, is hereby granted, provided that the above copyright notice, this +paragraph and the +following two paragraphs appear in all copies, modifications, and distributions. +Contact The Office +of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, +CA 94720-1620, +(510) 643-7201, otl@berkeley.edu, http://ipira.berkeley.edu/industry-info for +commercial licensing opportunities. -IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR -CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING -DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE +IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, +INCIDENTAL, OR +CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS +SOFTWARE AND ITS +DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + +REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +AND ACCOMPANYING +DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO +OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ***********************************/ +#include "auto_g.h" #include "cycle_count_delay.h" #include "mbed.h" #include "minig.h" #include "util/macros.h" -#if !DEVICE_FLASH -#error [NOT_SUPPORTED] Flash API not supported for this target -#endif - -#define K_UP 0 - - -#include "FlashIAP.h" - -// Create flash IAP block device -FlashIAP bd; -void test_bd() { - printf("FlashIAPBlockDevice test\n"); - - // Initialize the flash IAP block device and print the memory layout - bd.init(); - printf("Flash block device size: %lu\n", bd.get_flash_size()); - printf("Flash block device read size: %lu\n", bd.get_page_size()); - printf("Flash block device program size: %lu\n", bd.get_page_size()); - printf("Flash block device erase size: %lu\n", - bd.get_sector_size(bd.get_flash_start())); - - // Write "Hello World!" to the first block - char *buffer = (char *)malloc(bd.get_page_size()); - sprintf(buffer, "Hello World!\n"); - bd.erase(0, bd.get_page_size()); - bd.program(buffer, 0, bd.get_page_size()); - - // Read back what was stored - bd.read(buffer, 0, bd.get_page_size()); - printf("%s", buffer); - - // Deinitialize the device - bd.deinit(); -} - int main() { enableCycleCounter(); - test_bd(); -#if K_UP - MiniG minig(true); -#else - MiniG minig(false); -#endif + MiniG minig{true /* k_up */}; minig.init(); while (1) { minig.run(); } - - // For recording timing parameters - // - // while (1) { - - // WRITE_IO(GPIOG, GPIO_PIN_2, BITS_NONE); - // bsm_delay_us(4); - // WRITE_IO(GPIOG, BITS_NONE, GPIO_PIN_2); - // bsm_delay_us(4); - // } } diff --git a/minig.cpp b/minig.cpp index 90df3b6..9b5093d 100644 --- a/minig.cpp +++ b/minig.cpp @@ -41,14 +41,16 @@ using drivers::ad9959::AD9959; using drivers::max11300::MAX11300; using util::DDSConfig; -#define SPECTROSCOPY 0 -#define RAMAN_RABI 0 -#define MW_RABI 0 -#define INTER 1 -#define DEBUG_PD 0 #define USE_CAMERA 0 -#define CENTER_PD 0 -#define TUNE 0 +#define STORE 0 + +#if STORE +#if !DEVICE_FLASH +#error[NOT_SUPPORTED] Flash API not supported for this target +#endif + +#include "FlashIAP.h" +#endif namespace { @@ -64,12 +66,35 @@ constexpr int16_t to_dac(double volts) { return static_cast(volts / 10.0 * 0x0fff); } -constexpr size_t num_samples = 1200; -uint16_t samples[num_samples]; +constexpr size_t num_pd_samples = 1200; +uint16_t pd_samples[num_pd_samples]; DDSConfig dds_config; #include "experiment/settings.h" + +#if STORE +// Create flash IAP block device +FlashIAP bd; + +char *storage_buff; +size_t store_idx = 0; +size_t page_addr = 0; + + +template +void store(store_type val) { + memcpy(&storage_buff[store_idx], &val, sizeof(store_type)); + store_idx += sizeof(store_type); + if (store_idx == bd.get_page_size()) { + bd.program(storage_buff, page_addr, bd.get_page_size()); + store_idx = 0; + page_addr += bd.get_page_size(); + } +} + +#endif + } // namepsace // clang-format off @@ -129,6 +154,13 @@ void MiniG::init() { pin_function(port_pin(PortG, 3), STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); + +#if STORE + // Initialize the flash IAP block device and print the memory layout + bd.init(); + storage_buff = (char *)malloc(bd.get_page_size()); +#endif + // Ramps for Analog IO // clang-format off MAX11300::Ramp mot_on_ramps[] = { @@ -233,65 +265,10 @@ void MiniG::reset(float var) { pixi_.single_ended_dac_write(eo_freq_, to_dac(EO_MOT)); pixi_.single_ended_dac_write(bias_field_, to_dac(0)); -#if TUNE -// pixi_.single_ended_dac_write(ao1_freq_, to_dac(var)); -// MAX11300::Ramp image_on_ramps[] = { -// {ao1_freq_, to_dac(AO1_RAMAN), to_dac(var)}, -// {ao2_atten_, to_dac(AO2_RAMAN), to_dac(AO2_IMAGE)}, -// {eo_freq_, to_dac(EO_RAMAN), to_dac(EO_IMAGE)}, -// {ns_field_, to_dac(NS_RAMAN), to_dac(NS_IMAGE)}, -// {we_field_, to_dac(WE_RAMAN), to_dac(WE_IMAGE)}, -// }; -// image_on_ramp_.configured = 1; -// image_on_ramp_.num_ramps = ARRAYSIZE(image_on_ramps); -// image_on_ramp_.num_steps = 30; -// image_on_ramp_.step_time_us = 100; -// pixi_.prepare_ramps(&image_on_ramp_, image_on_ramps); - -// MAX11300::Ramp pgc_on_ramps[] = { -// // {ao1_freq_, to_dac(AO1_MOT), to_dac(AO1_PGC)}, -// {ao2_atten_, to_dac(AO2_MOT), to_dac(var)}, -// {ao3_atten_, to_dac(AO3_MOT), to_dac(AO3_PGC)}, -// {eo_freq_, to_dac(EO_MOT), to_dac(EO_PGC)}, -// }; -// pgc_on_ramp_.configured = 1; -// pgc_on_ramp_.num_ramps = ARRAYSIZE(pgc_on_ramps); -// pgc_on_ramp_.num_steps = 5; -// pgc_on_ramp_.step_time_us = 100; -// pixi_.prepare_ramps(&pgc_on_ramp_, pgc_on_ramps); - -#endif cycle_delay_ms(2); } void MiniG::run() { -#if TUNE - for (float var = 6.4; var <= 7.5; var += 0.1) { -#endif -#if CENTER_PD - for (float d_fall = -3000; d_fall <= 0; d_fall += 500) { -#endif -#if MW_RABI - for (int pulse = 0; pulse <= 800; pulse += 20) { -#endif -#if RAMAN_RABI - for (uint32_t raman = 0; raman <= 30; raman += 1) { - if (k_up_) { - dds_config.configure_up(dds_, fringes[0]); - } else { - dds_config.configure_down(dds_, fringes[0]); - } -#endif -#if SPECTROSCOPY - for (size_t j = 0; j < NUM_POINTS_SPEC; j++) { - if (k_up_) { - dds_config.configure_up(dds_, specs[j]); - } else { - dds_config.configure_down(dds_, specs[j]); - } - -#endif -#if INTER for (size_t j = 0; j < NUM_POINTS_INTER; j++) { if (k_up_) { dds_config.configure_up(dds_, fringes[j]); @@ -299,87 +276,37 @@ void MiniG::run() { dds_config.configure_down(dds_, fringes[j]); } -#endif -#if TUNE - reset(var); -#else reset(AO1_MOT); -#endif mot(); pgc(); -#if !MW_RABI int pulse = 300; -#endif mw(pulse); uint32_t T = 129; float fall_ms = 0.5; uint32_t fall_us = static_cast(fall_ms * 1000); -#if CENTER_PD - fall_us += d_fall; -#endif -#if !RAMAN_RABI uint32_t raman = 8; -#endif interferometry(T, fall_us, raman); - image(); #if USE_CAMERA - cycle_delay_ms(300); + image_with_camera(); +#else + image(); #endif -#if SPECTROSCOPY - printf("rd: %f\n", specs[j].detuning); -#elif INTER + integrate(); + +#if STORE + store(fringes[j].actual_chirp); + store(pd_fraction_); + store(atom_number_); +#else printf("rd: %f\n", fringes[j].actual_chirp); -#elif MW_RABI - printf("rd: %d\n", pulse); -#elif RAMAN_RABI - printf("rd: %lu\n", raman); -#elif CENTER_PD - printf("rd: %f\n", d_fall); -#elif TUNE - printf("rd: %f\n", var); -#endif - uint32_t f4 = 0, f34 = 0, bg = 6; - size_t i = 0; -#if DEBUG_PD - printf("ListPlot[{"); -#endif - for (; i < 127; i++) { - f4 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127; i++) { - f34 += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } - for (; i < 127 + 127 + 127; i++) { - bg += samples[i]; -#if DEBUG_PD - printf("%d,", samples[i]); -#endif - } -#if DEBUG_PD - printf("}]\n\n"); + printf("fr: %f\n", pd_fraction_); + printf("atom_num: %lu\n\n", atom_number_); #endif - double detection = - (static_cast(f4) - static_cast(bg)) / - (static_cast(f34) - static_cast(bg)); -#if MW_RABI | CENTER_PD | TUNE - printf("fr: %lu\n", f34 - bg); -#elif RAMAN_RABI | SPECTROSCOPY | INTER - printf("fr: %f\n", detection); - printf("atom_num: %lu\n\n", f34 - bg); -#endif -#if CENTER_PD | RAMAN_RABI | SPECTROSCOPY | INTER | MW_RABI | TUNE } -#endif } void MiniG::mot() { @@ -506,39 +433,89 @@ void MiniG::image() { // Turn laser on WRITE_IO(GPIOE, m_lock_ | ao_3_ -#if USE_CAMERA + , BITS_NONE); + // TODO(bsm): write code for this in a minute + cycle_delay_us(20); + pixi_.max_speed_adc_read(photodiode_, pd_samples, 127); + + // Repumping Stage + WRITE_IO(GPIOE, ao_2_, BITS_NONE + ); + cycle_delay_us(150); + + // Second Sample + WRITE_IO(GPIOE, BITS_NONE, ao_2_); + pixi_.max_speed_adc_read(photodiode_, &pd_samples[127], 127); + + // Wait before background + cycle_delay_ms(5); + + // Third detection for background + pixi_.max_speed_adc_read(photodiode_, &pd_samples[127 + 127], 127); + +} +void MiniG::image_with_camera() { + WRITE_IO(GPIOE, cooling_shutter_ | dds_switch_ | raman_eo_, + BITS_NONE); + pixi_.run_ramps(&image_on_ramp_); + // takes 3 ms + cycle_delay_ms(7); + + // Stabilize + WRITE_IO(GPIOE, BITS_NONE, mot_eo_); + cycle_delay_ms(1); + cycle_delay_us(50); + + // Turn laser on + WRITE_IO(GPIOE, m_lock_ | ao_3_ | camera_ttl_ -#endif , BITS_NONE); // TODO(bsm): write code for this in a minute cycle_delay_us(20); - pixi_.max_speed_adc_read(photodiode_, samples, 127); + pixi_.max_speed_adc_read(photodiode_, pd_samples, 127); // Repumping Stage WRITE_IO(GPIOE, ao_2_, BITS_NONE -#if USE_CAMERA | camera_ttl_ -#endif ); cycle_delay_us(150); // Second Sample WRITE_IO(GPIOE, BITS_NONE, ao_2_); - pixi_.max_speed_adc_read(photodiode_, &samples[127], 127); + pixi_.max_speed_adc_read(photodiode_, &pd_samples[127], 127); // Wait before background cycle_delay_ms(5); // Third detection for background - pixi_.max_speed_adc_read(photodiode_, &samples[127 + 127], 127); + pixi_.max_speed_adc_read(photodiode_, &pd_samples[127 + 127], 127); -#if USE_CAMERA // Wait long time before Camera Background cycle_delay_ms(40); // Take background image WRITE_IO(GPIOE, camera_ttl_, BITS_NONE); - cycle_delay_ms(10); -#endif + cycle_delay_ms(310); +} + + +void MiniG::integrate() { + uint32_t f4 = 0, f34 = 0, bg = 6; + size_t i = 0; + for (; i < 127; i++) { + f4 += pd_samples[i]; + } + for (; i < 127 + 127; i++) { + f34 += pd_samples[i]; + } + for (; i < 127 + 127 + 127; i++) { + bg += pd_samples[i]; + } + double detection = + (static_cast(f4) - static_cast(bg)) / + (static_cast(f34) - static_cast(bg)); + // printf("atom_num: %lu\n\n", f34 - bg); + atom_number_ = f34 - bg; + pd_fraction_ = detection; } diff --git a/minig.h b/minig.h index b97c0ba..26f730c 100644 --- a/minig.h +++ b/minig.h @@ -29,18 +29,20 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. class MiniG { public: MiniG(bool k_up = true); - void init(); - void run(); + virtual void init(); + virtual void run(); protected: - void reset(float var); - void mot(); - void pgc(); - void mw(int pulse); - void interferometry(uint32_t T, uint32_t fall, uint32_t raman); - void image(); - - const bool k_up_; + virtual void reset(float var); + virtual void mot(); + virtual void pgc(); + virtual void mw(int pulse); + virtual void interferometry(uint32_t T, uint32_t fall, uint32_t raman); + virtual void image(); + virtual void image_with_camera(); + virtual void integrate(); + + bool k_up_; const uint32_t coils_; const uint32_t liquid_crystal_1_; const uint32_t under_vac_shutter_; @@ -64,6 +66,10 @@ class MiniG { const uint32_t laser_jump_; const uint32_t m_horn_switch_; + // End of shot storage variables + float pd_fraction_; + uint32_t atom_number_; + // Analog Outputs drivers::max11300::MAX11300::MAX11300_Ports ao1_freq_; drivers::max11300::MAX11300::MAX11300_Ports ao2_atten_; @@ -73,8 +79,12 @@ class MiniG { drivers::max11300::MAX11300::MAX11300_Ports we_field_; drivers::max11300::MAX11300::MAX11300_Ports eo_freq_; drivers::max11300::MAX11300::MAX11300_Ports bias_field_; + // Analog Input drivers::max11300::MAX11300::MAX11300_Ports photodiode_; + drivers::max11300::MAX11300::MAX11300_Ports vibration_; + drivers::max11300::MAX11300::MAX11300_Ports tilt_x_; + drivers::max11300::MAX11300::MAX11300_Ports tilt_y_; SPI dds_spi_; drivers::ad9959::AD9959 dds_; diff --git a/util/dds_config.h b/util/dds_config.h index 11cbf4f..7c6f52f 100644 --- a/util/dds_config.h +++ b/util/dds_config.h @@ -28,6 +28,7 @@ namespace util { class DDSConfig { public: + // TODO(get rid of this old struct) struct params_t { uint8_t mult; @@ -44,6 +45,7 @@ class DDSConfig void configure_up(drivers::ad9959::AD9959 dds, params_t params); void configure_down(drivers::ad9959::AD9959 dds, params_t params); + }; } // namespace util