Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert stm AnalogOutput to use DAC #382

Open
BlakeFreer opened this issue Jan 12, 2025 · 1 comment
Open

Convert stm AnalogOutput to use DAC #382

BlakeFreer opened this issue Jan 12, 2025 · 1 comment
Assignees

Comments

@BlakeFreer
Copy link
Contributor

BlakeFreer commented Jan 12, 2025

STM32 currently produces an "analog output voltage" by controlling the duty cycle of a PWM peripheral. However, stm32 has DAC peripherals. We should use these instead.

EDIT: We should have two AnalogOutput implementations in mcal/stm32 - one for AnalogOutputDAC and AnalogOutputPWM, the latter is the one we already use. Both should be subclasses of the shared::periph::AnalogOutput. Then, each project has the choice of using PWM or DAC to simulate an analog signal, but the public interface is the same.

See the datasheet section 16


Task

  1. Rename the existing stm32 AnalogOutput class (and file) to AnalogOutputPWM. Apply this to all projects where it's used. You can ignore the debug/ projects
  2. Create a new file & class AnalogOutputDAC. Follow the structure of the other peripherals.
  3. Implement the SetVoltage() function using DAC instead of PWM.

Testing

  1. Create a project Demo/AnalogDAC.
  2. In main(), use a DAC to create an interesting signal (ex sine / sawtooth wave) which shows you can control the voltage.

    Between each voltage level, add a couple milliseconds of delay. See DelayMS() in the Demo/Blink project

  3. Create an stm32 platform. Look at other projects for the structure.
  4. Open the STM32CubeMX program and start a new project for your board. Save the project as AnalogDAC/platforms/stm32/cubemx/board_config.ioc
  5. Set up a DAC pin.
  6. In the "Project Manager" tab of CubeMX, choose these settings
    • Project Structure: Basic
    • Toolchain: CMake
    • Check "Do not generate main()`
    • Code Generation Tab:
      • Select "Generate separate .c and .h files"

Build the project from racecar/firmware/ with

make PROJECT=Demo/AnalogDAC PLATFORM=stm32

Verify the signal on an oscilloscope

@BlakeFreer
Copy link
Contributor Author

This is low priority since none of our ECUs currently use AnalogOutput.

It is a good task through for someone who wants to write low-level code for the stm

@floralandfaded floralandfaded self-assigned this Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants