Skip to content

Commit

Permalink
Merge branch 'driver_merge_tmp/mcpwm' into 'master'
Browse files Browse the repository at this point in the history
feature: Motor Control PWM(mcpwm) driver and examples



See merge request !698
  • Loading branch information
jack0c committed May 12, 2017
2 parents 9e46b89 + 2008f4d commit a660864
Show file tree
Hide file tree
Showing 22 changed files with 6,008 additions and 0 deletions.
709 changes: 709 additions & 0 deletions components/driver/include/driver/mcpwm.h

Large diffs are not rendered by default.

733 changes: 733 additions & 0 deletions components/driver/mcpwm.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions components/esp32/ld/esp32.peripherals.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ PROVIDE ( RMT = 0x3ff56000 );
PROVIDE ( RMTMEM = 0x3ff56800 );
PROVIDE ( PCNT = 0x3ff57000 );
PROVIDE ( LEDC = 0x3ff59000 );
PROVIDE ( MCPWM0 = 0x3ff5E000 );
PROVIDE ( TIMERG0 = 0x3ff5F000 );
PROVIDE ( TIMERG1 = 0x3ff60000 );
PROVIDE ( SPI2 = 0x3ff64000 );
PROVIDE ( SPI3 = 0x3ff65000 );
PROVIDE ( I2C1 = 0x3ff67000 );
PROVIDE ( MCPWM1 = 0x3ff6C000 );
PROVIDE ( I2S1 = 0x3ff6D000 );
PROVIDE ( UART2 = 0x3ff6E000 );
PROVIDE ( SDMMC = 0x3ff68000 );
3,028 changes: 3,028 additions & 0 deletions components/soc/esp32/include/soc/mcpwm_reg.h

Large diffs are not rendered by default.

452 changes: 452 additions & 0 deletions components/soc/esp32/include/soc/mcpwm_struct.h

Large diffs are not rendered by default.

133 changes: 133 additions & 0 deletions docs/api/peripherals/mcpwm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
MCPWM
=====

Overview
--------

ESP32 has two MCPWM units which can be used to control different motors.

Block Diagram
-------------

The block diagram of MCPWM unit is as shown.

::

__________________________________________________________________________
| SYNCSIG FAULT SIG CAPTURE SIG |
| 0 1 2 0 1 2 0 1 2 |
|___________________________________________________________________ G |
INTERRUPTS<-----+ | | | | | | | | | | P |
| | | | | | | | | | | I |
________|_|___|___|_____________|___|___|_________|___|___|_________ | O |
| | | | | | | | | | | | |
| | | | | | | | | | | | M |
| | | | __v___v___v__ __v___v___v__ | | A |
| | | | | | | | | | T |
| | | | | FAULT | | CAPTURE | | | R |
| | | | | HANDLER | | | | | I |
| | | | | | |___________| | | X |
| | | | |___________| | | |
| | | | | | |
| ____v___v___v____ ____________________ | | |
| | +---------+ | | +------------+ |--------->|PWM0A|
| | | Timer 0 | | | | Operator 0 | | | | |
| | +---------+ | | +------------+ |--------->|PWM0B|
| | | | | | | |
| | +---------+ | | +------------+ |--------->|PWM1A|
| | | Timer 1 | |------------------->| | Operator 1 | | | | |
| | +---------+ | | +------------+ |--------->|PWM1B|
| | | | | | | |
| | +---------+ | | +------------+ |--------->|PWM2A|
| | | Timer 2 | | | | Operator 2 | | | | |
| | +---------+ | | +------------+ |--------->|PWM2B|
| |_______________| |__________________| | |_____|
| |
| MCPWM-UNIT 0/1 |
|___________________________________________________________________|

Application Example
-------------------

MCPWM different motor example: :example:`peripherals/mcpwm`.

API Reference
-------------

Header Files
^^^^^^^^^^^^

* :component_file:`driver/include/driver/mcpwm.h`

Type Definitions
^^^^^^^^^^^^^^^^


Enumerations
^^^^^^^^^^^^

.. doxygenenum:: mcpwm_io_signals_t
.. doxygenenum:: mcpwm_unit_t
.. doxygenenum:: mcpwm_timer_t
.. doxygenenum:: mcpwm_operator_t
.. doxygenenum:: mcpwm_counter_type_t
.. doxygenenum:: mcpwm_duty_type_t
.. doxygenenum:: mcpwm_carrier_os_t
.. doxygenenum:: mcpwm_carrier_out_ivt_t
.. doxygenenum:: mcpwm_sync_signal_t
.. doxygenenum:: mcpwm_fault_signal_t
.. doxygenenum:: mcpwm_fault_input_level_t
.. doxygenenum:: mcpwm_action_on_pwmxa_t
.. doxygenenum:: mcpwm_action_on_pwmxb_t
.. doxygenenum:: mcpwm_capture_signal_t
.. doxygenenum:: mcpwm_capture_on_edge_t
.. doxygenenum:: mcpwm_deadtime_type_t

Structures
^^^^^^^^^^

.. doxygenstruct:: mcpwm_config_t
:members:

.. doxygenstruct:: mcpwm_carrier_config_t
:members:


Functions
^^^^^^^^^

.. doxygenfunction:: mcpwm_gpio_init
.. doxygenfunction:: mcpwm_init
.. doxygenfunction:: mcpwm_set_frequency
.. doxygenfunction:: mcpwm_set_duty
.. doxygenfunction:: mcpwm_set_duty_in_us
.. doxygenfunction:: mcpwm_set_duty_type
.. doxygenfunction:: mcpwm_get_frequency
.. doxygenfunction:: mcpwm_get_duty
.. doxygenfunction:: mcpwm_set_signal_high
.. doxygenfunction:: mcpwm_set_signal_low
.. doxygenfunction:: mcpwm_start
.. doxygenfunction:: mcpwm_stop
.. doxygenfunction:: mcpwm_carrier_init
.. doxygenfunction:: mcpwm_carrier_enable
.. doxygenfunction:: mcpwm_carrier_disable
.. doxygenfunction:: mcpwm_carrier_set_period
.. doxygenfunction:: mcpwm_carrier_set_duty_cycle
.. doxygenfunction:: mcpwm_carrier_oneshot_mode_enable
.. doxygenfunction:: mcpwm_carrier_oneshot_mode_disable
.. doxygenfunction:: mcpwm_carrier_output_invert
.. doxygenfunction:: mcpwm_deadtime_enable
.. doxygenfunction:: mcpwm_deadtime_disable
.. doxygenfunction:: mcpwm_fault_init
.. doxygenfunction:: mcpwm_fault_set_oneshot_mode
.. doxygenfunction:: mcpwm_fault_set_cyc_mode
.. doxygenfunction:: mcpwm_fault_deinit
.. doxygenfunction:: mcpwm_capture_enable
.. doxygenfunction:: mcpwm_capture_disable
.. doxygenfunction:: mcpwm_capture_signal_get_value
.. doxygenfunction:: mcpwm_capture_signal_get_edge
.. doxygenfunction:: mcpwm_sync_enable
.. doxygenfunction:: mcpwm_sync_disable
.. doxygenfunction:: mcpwm_isr_register

9 changes: 9 additions & 0 deletions examples/peripherals/mcpwm/mcpwm_basic_config/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := mcpwm_basic_config

include $(IDF_PATH)/make/project.mk

32 changes: 32 additions & 0 deletions examples/peripherals/mcpwm/mcpwm_basic_config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MCPWM basic config Example

This example will show you how to use each submodule of MCPWM unit

The example can't be used without modifying the code first

Edit the macros at the top of mcpwm_example_basic_config.c to enable/disable the submodules which are used in the example


## Step 1: Pin assignment
* The gpio init function initializes:
* six MCPWM output pins
* three MCPWM fault input pins
* three MCPWM sync input pins
* three MCPWM capture input pins


## Step 2: Connection
* Six MCPWM output pins to motor driver input signals
* Fault, sync, capture signals can be connected to respective signals


## Step 3: Initialize MCPWM
* You need to set the frequency and duty cycle of each three MCPWM timer along with other parameters mentioned
* You need to set the MCPWM channel you want to use, with these timers


## Step 4: Testing
* The deadtime module, set deadtime type and with value as time*100ns
* The sync module, synchonizes all the timer pulses
* The fault module when enabled takes action on MCPWM signals when fault occurs
* The capture module captures input signal(digital i.e. hall sensor value, etc), timing between two rising/falling edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Main Makefile. This is basically the same as a component makefile.
#

0 comments on commit a660864

Please sign in to comment.