Skip to content

Commit

Permalink
Working TimerOc for Raman pulses. Initial MiniG experimental Setup wi…
Browse files Browse the repository at this point in the history
…th MOT and PCG and Imagining
  • Loading branch information
Bola Malek committed Jul 20, 2018
1 parent d2b7667 commit 41dc879
Show file tree
Hide file tree
Showing 12 changed files with 963 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ OBJECTS += main.o
# drivers
OBJECTS += drivers/max11300/max11300.o
OBJECTS += drivers/ad9959/ad9959.o
OBJECTS += minig.o
OBJECTS += timer_oc_api.o

# utilities
OBJECTS += utils/analog_operations.o
Expand Down
72 changes: 72 additions & 0 deletions TimerOc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef TIMER_OC_H
#define TIMER_OC_H

#include "platform/platform.h"

#include "platform/mbed_critical.h"
#include "platform/mbed_power_mgmt.h"
#include "timer_oc_api.h"

class TimerOc {

public:
/** Create a TimerOc connected to the specified pin
*
* @param pin TimerOc pin to connect to
*/
TimerOc(PinName pin) : _deep_sleep_locked(false) {
core_util_critical_section_enter();
timer_oc_init(&_timer_oc, pin);
core_util_critical_section_exit();
}

~TimerOc() {
core_util_critical_section_enter();
unlock_deep_sleep();
core_util_critical_section_exit();
}

/** Set the ouput duty-cycle, specified as a percentage (float)
*
* @param value A floating-point value representing the output duty-cycle,
* specified as a percentage. The value should lie between
* 0.0f (representing on 0%) and 1.0f (representing on 100%).
* Values outside this range will be saturated to 0.0f or 1.0f.
*/
void start(int period_us, int num_repetitions, uint32_t *ticks) {
core_util_critical_section_enter();
lock_deep_sleep();
timer_oc_start(&_timer_oc, period_us, num_repetitions, ticks);
core_util_critical_section_exit();
}

void stop() {
printf("before cs\n");
core_util_critical_section_enter();
lock_deep_sleep();
timer_oc_stop(&_timer_oc);
core_util_critical_section_exit();
}

protected:
/** Lock deep sleep only if it is not yet locked */
void lock_deep_sleep() {
if (_deep_sleep_locked == false) {
sleep_manager_lock_deep_sleep();
_deep_sleep_locked = true;
}
}

/** Unlock deep sleep in case it is locked */
void unlock_deep_sleep() {
if (_deep_sleep_locked == true) {
sleep_manager_unlock_deep_sleep();
_deep_sleep_locked = false;
}
}

timer_oc_t _timer_oc;
bool _deep_sleep_locked;
};

#endif
5 changes: 3 additions & 2 deletions drivers/max11300/MAX11300Hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ dac_data_port_19 = 0x73,
#define port_cfg_18_funcprm_range 0x0700
#define port_cfg_18_funcprm_nsamples 0x00e0
#define port_cfg_18_funcprm_port 0x001f
#define port_cfg_18_DESIGNVALUE 0x0000
// #define port_cfg_18_DESIGNVALUE 0x3000
#define port_cfg_18_DESIGNVALUE 0x5100

/// 0x33 r/w port_cfg_19 PIXI port 19 configuration register
/// <code>1111xxxxxxxxxxxx</code> PortCfgFuncID Port function / mode
Expand All @@ -1274,7 +1275,7 @@ dac_data_port_19 = 0x73,
#define port_cfg_19_funcprm_range 0x0700
#define port_cfg_19_funcprm_nsamples 0x00e0
#define port_cfg_19_funcprm_port 0x001f
#define port_cfg_19_DESIGNVALUE 0x0000
#define port_cfg_19_DESIGNVALUE 0x5100

/// 0x40 r/o adc_data_port_00 PIXI port 0 Analog to Digital Converter register
/// <code>xxxx111111111111</code> adccode 12-bit ADC code
Expand Down
2 changes: 1 addition & 1 deletion drivers/max11300/max11300.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "max11300.h"

namespace {
constexpr uint32_t MAX_SPI_RATE_HZ = 20000000;
constexpr uint32_t MAX_SPI_RATE_HZ = 12500000;

constexpr uint16_t port_config_design_vals[20] = {
port_cfg_00_DESIGNVALUE, port_cfg_01_DESIGNVALUE, port_cfg_02_DESIGNVALUE,
Expand Down
122 changes: 76 additions & 46 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
#include "drivers/ad9959/ad9959.h"
#include "drivers/max11300/max11300.h"
#include "TimerOc.h"
#include "mbed.h"

#include "utils/analog_operations.h"

using drivers::ad9959::AD9959;
using drivers::max11300::MAX11300;

using utils::AnalogOperations;
#include "minig.h"

DigitalOut red{LED1};
DigitalOut blue{LED2};
DigitalOut green{LED3};

Ticker led_ticker;

SPI dds_spi{PB_5, PB_4, PB_3};
constexpr AD9959::Pins dds_pins = {
PA_4, /* CS */
D6, /* reset */
D5, /* update */
D4, /* p0 */
D3 /* p1 */
};

AD9959 dds{dds_spi, dds_pins, 24000000 /* ref_freq */, 10 /* mult */};

SPI pixi_spi{SPI_MOSI, SPI_MISO, SPI_SCK};
MAX11300 pixi{pixi_spi, SPI_CS /* cs */, NC, D8};

void toggle_led() {
static int i = 0;

Expand All @@ -37,31 +15,83 @@ void toggle_led() {
green = i & 4;
i++;
}
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Definition of TIM instance */
#define TIMx TIM3

/* Definition for TIMx clock resources */
#define TIMx_CLK_ENABLE __HAL_RCC_TIM3_CLK_ENABLE
#define DMAx_CLK_ENABLE __HAL_RCC_DMA1_CLK_ENABLE

/* Definition for TIMx Pins */
#define TIMx_CHANNEL3_GPIO_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE

#define TIMx_GPIO_CHANNEL3_PORT GPIOB
#define GPIO_PIN_CHANNEL3 GPIO_PIN_0

#define GPIO_AF_TIMx GPIO_AF2_TIM3

/* Definition for TIMx's DMA */
#define TIMx_CC3_DMA_INST DMA1_Stream7

/* Definition for ADCx's NVIC */
#define TIMx_DMA_IRQn DMA1_Stream7_IRQn
#define TIMx_DMA_IRQHandler DMA1_Stream7_IRQHandler

void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) {
static DMA_HandleTypeDef hdma_tim;

/* Enable DMA clock */
DMAx_CLK_ENABLE();

/* Set the parameters to be configured */
hdma_tim.Init.Channel = DMA_CHANNEL_5;
hdma_tim.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_tim.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tim.Init.MemInc = DMA_MINC_ENABLE;
hdma_tim.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_tim.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_tim.Init.Mode = DMA_CIRCULAR;
hdma_tim.Init.Priority = DMA_PRIORITY_HIGH;
hdma_tim.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_tim.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_tim.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_tim.Init.PeriphBurst = DMA_PBURST_SINGLE;

/* Set hdma_tim instance */
hdma_tim.Instance = TIMx_CC3_DMA_INST;

/* Link hdma_tim to hdma[TIM_DMA_ID_CC3] (channel3) */
__HAL_LINKDMA(htim, hdma[TIM_DMA_ID_CC3], hdma_tim);

/* Initialize TIMx DMA handle */
HAL_DMA_Init(htim->hdma[TIM_DMA_ID_CC3]);

/*##-2- Configure the NVIC for DMA #########################################*/
/* NVIC configuration for DMA transfer complete interrupt */
HAL_NVIC_SetPriority(TIMx_DMA_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIMx_DMA_IRQn);
}

uint32_t ticks[3] = {4, 8, 4};

// MiniG minig;
int main() {
led_ticker.attach(toggle_led, 0.2);
printf("\nhello debugging! \n");

// Note: Do not reset and initializing, or you'll waste time debugging for no
// reason.
dds.init();
dds.set_freq(AD9959::Channel1, 11000000.0);
dds.set_freq_linear_sweep_params(AD9959::Channel0, 12000000.0, 13000000.0,
2 << 19, 2 << 19, .0001, .0001);
dds.io_update();

pixi.init();
AnalogOperations::set_voltage(pixi, MAX11300::PORT16, 5.0);
AnalogOperations::ramp_voltage(pixi, MAX11300::PORT16, 5.0, 7.5, 1000,
9000000);
wait(1);
AnalogOperations::ramp_voltage(pixi, MAX11300::PORT16, 7.5, 5.0, 1000,
9000000);
led_ticker.attach(toggle_led, .2);
printf("\nhello debugging!\n");

// minig.init();

TimerOc timer_oc{PB_0_ALT0};
printf("before start\n");
timer_oc.start(100000 /* us*/, 3, ticks);
printf("before wait\n");
wait_ms(210);
printf("after wait\n");
timer_oc.stop();

while (1) {
dds.start_linear_sweep_up(AD9959::Channel0);
wait(5);
dds.start_linear_sweep_down(AD9959::Channel0);
wait(5);
// minig.run();
}
}
27 changes: 27 additions & 0 deletions mappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
coils_ D43
liquid_crystal_1_ D44
under_vac_shutter_ D46
ao_2_ D47
ao_3_ D48
cooling_shutter_ D49
mot_eo_ D50
raman_eo_ D51
m_horn_switch_ D52
m_lock_ D53
analog_trigger_ D54
dds_switch_ D56
dds_trigger_1_ D57
dds_trigger_2_ D58
oscillscope_trigger_ D59
camera_ttl_ D60
ao1_freq_ OUT0}
ao2_atten_ OUT1}
ao3_atten_ OUT2}
z_field_ OUT3}
ns_field_ OUT4}
we_field_ OUT5}
eo_freq_ OUT6}
bias_field_ OUT7}
laser_jump_ OUT8}
photodiode_ IN0}

Loading

0 comments on commit 41dc879

Please sign in to comment.