Skip to content

Commit

Permalink
updated for 5v ref pin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Apr 7, 2024
1 parent 73381c6 commit 99ec12f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 31 deletions.
86 changes: 71 additions & 15 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;

CAN_HandleTypeDef hcan1;
CAN_HandleTypeDef hcan2;

Expand Down Expand Up @@ -82,6 +84,7 @@ static void MX_I2C1_Init(void);
static void MX_TIM1_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM8_Init(void);
static void MX_ADC1_Init(void);
/* USER CODE BEGIN PFP */

void watchdog_init(void);
Expand Down Expand Up @@ -224,6 +227,7 @@ int main(void)
MX_TIM1_Init();
MX_TIM2_Init();
MX_TIM8_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
for (int i = 0; i < 58; i++)
{
Expand Down Expand Up @@ -335,6 +339,58 @@ void SystemClock_Config(void)
}
}

/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{

/* USER CODE BEGIN ADC1_Init 0 */

/* USER CODE END ADC1_Init 0 */

ADC_ChannelConfTypeDef sConfig = {0};

/* USER CODE BEGIN ADC1_Init 1 */

/* USER CODE END ADC1_Init 1 */

/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}

/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */

/* USER CODE END ADC1_Init 2 */

}

/**
* @brief CAN1 Initialization Function
* @param None
Expand Down Expand Up @@ -855,8 +911,8 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOD_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC15_Pin|Communication_GPIOC0_Pin
|SPI_2_CS_Pin|Debug_LED_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC0_Pin|SPI_2_CS_Pin
|Debug_LED_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, Fault_Output_Pin|SPI_1_CS_Pin|SPI_3_CS_Pin, GPIO_PIN_RESET);
Expand All @@ -868,15 +924,21 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(External_GPIO_GPIO_Port, External_GPIO_Pin, GPIO_PIN_RESET);

/*Configure GPIO pins : FPGA_Reset_Pin Communication_GPIO_Pin Communication_GPIOC15_Pin Communication_GPIOC0_Pin
SPI_2_CS_Pin Debug_LED_Pin */
GPIO_InitStruct.Pin = FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC15_Pin|Communication_GPIOC0_Pin
|SPI_2_CS_Pin|Debug_LED_Pin;
/*Configure GPIO pins : FPGA_Reset_Pin Communication_GPIO_Pin Communication_GPIOC0_Pin SPI_2_CS_Pin
Debug_LED_Pin */
GPIO_InitStruct.Pin = FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC0_Pin|SPI_2_CS_Pin
|Debug_LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PC15 */
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : Interlock_Read_Pin */
GPIO_InitStruct.Pin = Interlock_Read_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
Expand All @@ -890,17 +952,11 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pin : I_Sense_Pin */
GPIO_InitStruct.Pin = I_Sense_Pin;
/*Configure GPIO pin : I_SenseB2_Pin */
GPIO_InitStruct.Pin = I_SenseB2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(I_Sense_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pins : I_SenseB0_Pin I_SenseB1_Pin I_SenseB2_Pin */
GPIO_InitStruct.Pin = I_SenseB0_Pin|I_SenseB1_Pin|I_SenseB2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(I_SenseB2_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pins : Debug_LEDB11_Pin Watchdog_Out_Pin External_GPIOB3_Pin External_GPIOB4_Pin
External_GPIOB5_Pin */
Expand Down
29 changes: 13 additions & 16 deletions shepherd2.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ PA9.Signal=USB_OTG_FS_VBUS
PB0.GPIOParameters=GPIO_Label
PB0.GPIO_Label=I Sense
PB0.Locked=true
PB0.Signal=SharedAnalog_PB0
PB0.Signal=ADCx_IN8
PB1.GPIOParameters=GPIO_Label
PB1.GPIO_Label=I Sense
PB1.Locked=true
PB1.Signal=SharedAnalog_PB1
PB1.Signal=ADCx_IN9
PB10.Mode=Full_Duplex_Master
PB10.Signal=SPI2_SCK
PB11.GPIOParameters=GPIO_Label
Expand Down Expand Up @@ -246,10 +246,8 @@ PC14-OSC32_IN.GPIOParameters=GPIO_Label
PC14-OSC32_IN.GPIO_Label=Communication GPIO
PC14-OSC32_IN.Locked=true
PC14-OSC32_IN.Signal=GPIO_Output
PC15-OSC32_OUT.GPIOParameters=GPIO_Label
PC15-OSC32_OUT.GPIO_Label=Communication GPIO
PC15-OSC32_OUT.Locked=true
PC15-OSC32_OUT.Signal=GPIO_Output
PC15-OSC32_OUT.Signal=GPXTI15
PC2.Mode=Full_Duplex_Master
PC2.Signal=SPI2_MISO
PC3.Mode=Full_Duplex_Master
Expand All @@ -261,7 +259,7 @@ PC4.Signal=GPIO_Output
PC5.GPIOParameters=GPIO_Label
PC5.GPIO_Label=I Sense
PC5.Locked=true
PC5.Signal=SharedAnalog_PC5
PC5.Signal=ADCx_IN15
PC6.GPIOParameters=GPIO_Label
PC6.GPIO_Label=Fan PWM
PC6.Locked=true
Expand Down Expand Up @@ -317,7 +315,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,10-MX_I2C1_Init-I2C1-false-HAL-true,11-MX_TIM1_Init-TIM1-false-HAL-true,12-MX_TIM2_Init-TIM2-false-HAL-true,13-MX_TIM8_Init-TIM8-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,10-MX_I2C1_Init-I2C1-false-HAL-true,11-MX_TIM1_Init-TIM1-false-HAL-true,12-MX_TIM2_Init-TIM2-false-HAL-true,13-MX_TIM8_Init-TIM8-false-HAL-true,14-MX_ADC1_Init-ADC1-false-HAL-true
RCC.48MHZClocksFreq_Value=48000000
RCC.AHBFreq_Value=16000000
RCC.APB1Freq_Value=16000000
Expand All @@ -342,6 +340,14 @@ RCC.VCOI2SOutputFreq_Value=320000000
RCC.VCOInputFreq_Value=1666666.6666666667
RCC.VCOOutputFreq_Value=240000000
RCC.VcooutputI2S=160000000
SH.ADCx_IN15.0=ADC1_IN15,IN15
SH.ADCx_IN15.ConfNb=1
SH.ADCx_IN8.0=ADC1_IN8,IN8
SH.ADCx_IN8.ConfNb=1
SH.ADCx_IN9.0=ADC1_IN9,IN9
SH.ADCx_IN9.ConfNb=1
SH.GPXTI15.0=ADC1_EXTI15,External-Trigger-for-Injected-conversion
SH.GPXTI15.ConfNb=1
SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1
SH.S_TIM1_CH1.ConfNb=1
SH.S_TIM1_CH3.0=TIM1_CH3,PWM Generation3 CH3
Expand All @@ -354,15 +360,6 @@ SH.S_TIM8_CH3.0=TIM8_CH3,PWM Generation3 CH3
SH.S_TIM8_CH3.ConfNb=1
SH.S_TIM8_CH4.0=TIM8_CH4,PWM Generation4 CH4
SH.S_TIM8_CH4.ConfNb=1
SH.SharedAnalog_PB0.0=GPIO_Analog
SH.SharedAnalog_PB0.1=ADC1_IN8,IN8
SH.SharedAnalog_PB0.ConfNb=2
SH.SharedAnalog_PB1.0=GPIO_Analog
SH.SharedAnalog_PB1.1=ADC1_IN9,IN9
SH.SharedAnalog_PB1.ConfNb=2
SH.SharedAnalog_PC5.0=GPIO_Analog
SH.SharedAnalog_PC5.1=ADC1_IN15,IN15
SH.SharedAnalog_PC5.ConfNb=2
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16
SPI1.CLKPhase=SPI_PHASE_2EDGE
SPI1.CLKPolarity=SPI_POLARITY_HIGH
Expand Down

0 comments on commit 99ec12f

Please sign in to comment.