Giter VIP home page Giter VIP logo

uctrl's Introduction

STM32 microcontrollers feature fast ADC, sampling with 12 bit resolution at up to 2 Megasamples per second.

USB 2.0 Fullspeed specification is 12 megabits per second, or 1.5 MBytes per second.

STM32 microcontrollers should be able to sample an analogic and stream ait over USB at up to 1.5 Megasamples per second. The project below was tested using internal STM32F401 oscilator as 725 kSample per second, or 300 kHz bandwidth.

Higher bandwith over USB can be achieved through USB 2.0 HighSpeed (480 Mbps) or through fast compression algorithm.

STM32 MCU

STM32CubeIDE

STM32F4 Discovery STM32F407VG https://www.st.com/en/evaluation-tools/stm32f4discovery.html

Blackpill MCU STM32F401CCU6 256kB flash / 64kB RAM / 84MHz HSI 16MHz LSI 32kHz HSE 25MHz LSE 32.768kHz User LED Connected to PC13 / Mode Sink

USB setup

Pinout & Config

  • Connectivity
  • USB_OTG_FS Mode = Device Only Active VBUS = Yes (VBUS Sensing enabled)
  • Middleware & Software
  • USB_DEVICE Class for FS IP = Communication Device Class (CDC)

Linux host lsusb cat /dev/ttyACM0

ADC setup

Pinout & Config

  • Change PA0 to ADC1_IN5.
  • Under Analog / ADC1, change IN5 to IN5 Single-ended.
  • Under Analog / ADC1 / Configuration / Parameter Settings / ADC_Settings change 'Continuous Conversion Mode' to Enabled.
  • System Core / DMA / DMA1 (or DMA2 depending on MCU and ADC), Add a new request, and change it to ADC1. Change Mode to Circular,
  • Back to Analog / ADC1 / Configuration / Parameter Settings / ADC_Settings change DMA Continuous Requests to Enabled.

12 bits 130 buffer per 1000ms 130x4096samples = 532480 samples/s = 532 kS/s +/- 4 kS 16 MHz APB Clock x 1/2 prescaler / 15 step/sample = 533 kS/s

8 bits 178 buffer per 1000ms 178x4096samples = 729088 samples/s = 729 kS/s+/- 4 kS 16 MHz APB Clock x 1/2 prescaler / 11 = 727 kS/s

  • Change PA10 (which is connected to header pin D2) to GPIO_Output.

PWM Setup

Pinout & Config

  • Change PA5 to TIM2_CH1
  • Under TImers / TIM2 / Mode change Clock Source to 'Internal Clock'. change Channel 1 to 'PWM Generation Channel 1'.
  • Under TImers / TIM2 / Configuration / Parameter Settings change 'Prescaler (PSC - 16 bits value)' to '16-1', It will bring back APB2 from 16MHz to 1MHz TIM Clock. change 'Counter Period (AutoReload Register - 32 bits value )' to '100-1'. It will set the PWM to 100 periods of the TIM Clock => 10kHz. change 'Auto Reload-Preload' to 'Enabled'.
  • Start in main function, before the while loop, with TIM2->CCR1 = 30; HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);

Enabling external oscillator

Rationale:

  • more accurate/stable frequency for USB communications
  • higher MCU clock

Pinout & Config

  • Under TImers / TIM2 / Mode

Refs:

uctrl's People

Contributors

kljh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.