Code Monkey home page Code Monkey logo

pwmcontrol's Introduction

PWMControl

PWMControl allows you to setup up to two PWM outputs by directly controlling the approprieate timer registers. The application is written for the STM32f103C8T6, a.k.a. BluePill, but may be easily ported to other controllers of the STM32 family.
After you've compiled and flashed the binary, a virtual COM-Port will appear that allows you to configure the timers.

Features

  • Control two PWM outputs independently.
  • Serial over USB. Just connect via USB and go!
  • Extendable! Missing some features? PWMControl is easy to extend!

Commands

The command syntax is as follows:
<timer>:<command>[:<argument>]
where <timer> is the desired timer t1or t2.<command> and <argument> are described below:

Command Function Arguments
start Starts the timer N/A
stop Stops timer execution N/A
duty Sets the duty cycle 0..100
period Sets the period [0..65535]
compare Sets the comare value [0..65535]
prescaler Sets the prescaler [0..65535]
status Prints the status of the timer N/A

Each recognized command is acknowledged with an OK. The only exception to this scheme is the helpcommand. In order to get help, just type help.

Examples

help example

The output of help is as follows:

help
OK
Syntax: <timer>:<command>[:<argument>]

<timer>...... [t1,t2]
    t1........... Timer connected to A8
    t2........... Timer connected to A9
<command>[:<arguments>]
    start ....... starts PWM
    stop ........ stops PWM
    duty ........ sets duty cycle [0..100]
    period ...... sets the period [0..65535]
    compare ..... sets compare value [0.65535]
    prescaler ... sets the prescaler [0..65535]
    status ...... prints the current configuration

status example

The output of t1:status may look as follows:

t1:status
OK
Clock: 72000000MHz
Prescaler: 0
Period: 80
Compare: 27

PWM example

In order to run timer1 with 50% dutycycle and a period of 1ms assuming the the clock is running at 72MHz issue the following commands:

t1:prescaler:719
OK
t1:period:99
OK
t1:compare:49
OK
t1:start
OK

t1:prescaler:7199 will set the prescaler to 719. At a clock speed of 72MHz the timer clock will become 100kHz. Then the period is set to 99 and compare 49. If you are confused due to of the odd values, dont't forget that the timer values period, prescaler and compare are always substracted by 1.

Pinout

Pinout

Pin Function
PA6 Timer1 Output
PA8 Timer2 Output

pwmcontrol's People

Contributors

onemillionbytes 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.