some fixes
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
|
||||
#include "adc_mux.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "board_handles.h"
|
||||
#include "main.h"
|
||||
|
||||
@ -117,35 +119,65 @@ uint16_t adc_mux_read_external_channel(uint8_t channel_index)
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t adc_mux_process_internal_adc_step(uint8_t step)
|
||||
static bool adc_mux_read_sequence(ADC_HandleTypeDef *hadc, uint16_t *output_buffer, uint8_t sample_count)
|
||||
{
|
||||
uint16_t output = 0u;
|
||||
uint8_t sample_index;
|
||||
|
||||
switch (step)
|
||||
if ((hadc == NULL) || (output_buffer == NULL) || (sample_count == 0u))
|
||||
{
|
||||
case 0u:
|
||||
HAL_ADC_Start(&hadc1);
|
||||
break;
|
||||
case 1u:
|
||||
HAL_ADC_PollForConversion(&hadc1, 100u);
|
||||
output = HAL_ADC_GetValue(&hadc1);
|
||||
break;
|
||||
case 2u:
|
||||
HAL_ADC_Stop(&hadc1);
|
||||
break;
|
||||
case 3u:
|
||||
HAL_ADC_Start(&hadc3);
|
||||
break;
|
||||
case 4u:
|
||||
HAL_ADC_PollForConversion(&hadc3, 100u);
|
||||
output = HAL_ADC_GetValue(&hadc3);
|
||||
break;
|
||||
case 5u:
|
||||
HAL_ADC_Stop(&hadc3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
return output;
|
||||
if (HAL_ADC_Start(hadc) != HAL_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (sample_index = 0u; sample_index < sample_count; ++sample_index)
|
||||
{
|
||||
if (HAL_ADC_PollForConversion(hadc, 100u) != HAL_OK)
|
||||
{
|
||||
(void)HAL_ADC_Stop(hadc);
|
||||
return false;
|
||||
}
|
||||
|
||||
output_buffer[sample_index] = (uint16_t)HAL_ADC_GetValue(hadc);
|
||||
}
|
||||
|
||||
(void)HAL_ADC_Stop(hadc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adc_mux_capture_internal_telemetry(adc_internal_telemetry_t *telemetry)
|
||||
{
|
||||
uint16_t adc1_samples[5];
|
||||
uint16_t adc3_samples[3];
|
||||
|
||||
if (telemetry == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(telemetry, 0, sizeof(*telemetry));
|
||||
|
||||
if (!adc_mux_read_sequence(&hadc1, adc1_samples, 5u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!adc_mux_read_sequence(&hadc3, adc3_samples, 3u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
telemetry->external_temperature_1_raw = adc1_samples[0];
|
||||
telemetry->external_temperature_2_raw = adc1_samples[1];
|
||||
telemetry->rail_3v3_raw = adc1_samples[2];
|
||||
telemetry->rail_5v1_raw = adc1_samples[3];
|
||||
telemetry->rail_5v2_raw = adc1_samples[4];
|
||||
telemetry->input_pf3_raw = adc3_samples[0];
|
||||
telemetry->input_pf4_raw = adc3_samples[1];
|
||||
telemetry->rail_7v0_raw = adc3_samples[2];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -6,9 +6,37 @@
|
||||
#ifndef ADC_MUX_H
|
||||
#define ADC_MUX_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Snapshot of all internal STM32 ADC channels exported through telemetry.
|
||||
*
|
||||
* The firmware keeps the UART telemetry frame fixed at 30 bytes, so the host
|
||||
* and the board agree on a stable slot order. These fields are captured from
|
||||
* the MCU ADC peripherals once per telemetry refresh and then packed into that
|
||||
* frame by the application core.
|
||||
*/
|
||||
typedef struct adc_internal_telemetry_t {
|
||||
/** @brief Raw 12-bit code for external temperature sensor channel 1. */
|
||||
uint16_t external_temperature_1_raw;
|
||||
/** @brief Raw 12-bit code for external temperature sensor channel 2. */
|
||||
uint16_t external_temperature_2_raw;
|
||||
/** @brief Raw 12-bit code for the monitored 3.3V rail. */
|
||||
uint16_t rail_3v3_raw;
|
||||
/** @brief Raw 12-bit code for the monitored 5V1 rail. */
|
||||
uint16_t rail_5v1_raw;
|
||||
/** @brief Raw 12-bit code for the monitored 5V2 rail. */
|
||||
uint16_t rail_5v2_raw;
|
||||
/** @brief Raw 12-bit code read from free analog input PF3 / ADC3_IN9. */
|
||||
uint16_t input_pf3_raw;
|
||||
/** @brief Raw 12-bit code read from free analog input PF4 / ADC3_IN14. */
|
||||
uint16_t input_pf4_raw;
|
||||
/** @brief Raw 12-bit code for the monitored 7V rail. */
|
||||
uint16_t rail_7v0_raw;
|
||||
} adc_internal_telemetry_t;
|
||||
|
||||
uint16_t adc_mux_read_external_channel(uint8_t channel_index);
|
||||
uint16_t adc_mux_process_internal_adc_step(uint8_t step);
|
||||
bool adc_mux_capture_internal_telemetry(adc_internal_telemetry_t *telemetry);
|
||||
|
||||
#endif /* ADC_MUX_H */
|
||||
|
||||
@ -8,9 +8,10 @@
|
||||
#include "main.h"
|
||||
|
||||
#define DS1809_POSITION_COUNT 64u
|
||||
#define DS1809_CPU_PULSE_WIDTH_MS 2u
|
||||
#define DS1809_CPU_INTER_PULSE_HIGH_MS 2u
|
||||
#define DS1809_CONTROL_PORT_READY_DELAY_MS 10u
|
||||
#define DS1809_RESET_DOWN_PULSE_COUNT 80u
|
||||
#define DS1809_CPU_PULSE_WIDTH_MS 8u
|
||||
#define DS1809_CPU_INTER_PULSE_HIGH_MS 8u
|
||||
#define DS1809_CONTROL_PORT_READY_DELAY_MS 500u
|
||||
|
||||
static void ds1809_drive_idle_high(void)
|
||||
{
|
||||
@ -69,7 +70,7 @@ void ds1809_apply_position_from_min(uint8_t position_from_min)
|
||||
* - repetitive pulses need at least 1 ms of high time between steps;
|
||||
* - the control inputs are locked out for at least 10 ms after power-up.
|
||||
*
|
||||
* Use 2 ms low/high timing for margin, always drive to the RL end first,
|
||||
* Use 8 ms low/high timing for margin, always drive to the RL end first,
|
||||
* then walk back up to the requested absolute position.
|
||||
*/
|
||||
if (position_from_min >= DS1809_POSITION_COUNT)
|
||||
@ -78,6 +79,6 @@ void ds1809_apply_position_from_min(uint8_t position_from_min)
|
||||
}
|
||||
|
||||
HAL_Delay(DS1809_CONTROL_PORT_READY_DELAY_MS);
|
||||
ds1809_pulse_direction(0u, 1u, DS1809_POSITION_COUNT, DS1809_CPU_PULSE_WIDTH_MS, DS1809_CPU_INTER_PULSE_HIGH_MS);
|
||||
ds1809_pulse_direction(0u, 1u, DS1809_RESET_DOWN_PULSE_COUNT, DS1809_CPU_PULSE_WIDTH_MS, DS1809_CPU_INTER_PULSE_HIGH_MS);
|
||||
ds1809_pulse_direction(1u, 0u, position_from_min, DS1809_CPU_PULSE_WIDTH_MS, DS1809_CPU_INTER_PULSE_HIGH_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user