Skip to content

Commit d927eb7

Browse files
MPAE-19111 implemented tech writer edits.
1 parent df55b51 commit d927eb7

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

README.md

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- Please do not change this html logo with link -->
22
![MCHP](./images/microchip.png)
33

4-
# Direct Memory Access (DMA) on PIC MCUs [Part 2] - UART to PWM
4+
# Direct Memory Access (DMA) on PIC MCUs [Part two] - UART to PWM
55

6-
This is part 2 of 2 of an example showing how to set up [Direct Memory Access (DMA)](https://www.microchip.com/design-centers/8-bit/peripherals/core-independent/direct-memory-access?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) using the [Microchip Code Configurator (MCC)](https://www.microchip.com/mplab/mplab-code-configurator?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) on a [PIC18F57Q43 microcontroller](https://www.microchip.com/wwwproducts/en/PIC18F57Q43?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) to transfer data from the devices UART recieve buffer to the PWM duty cycle register to alter the brightness of an LED based on the incoming serial messages from the device we set up in part 1. The data transfer is triggered directly by the hardware UART module when the Rx buffer register is full, meaning we achieve this with zero CPU utilization.
6+
This is part 2 of 2 of an example showing how to set up DMA using the Microchip Code Configurator (MCC) to transfer data from the devices Universal Asynchronous Receiver Transmitter (UART) recieve buffer to the Pulse-Width Modulation (PWM) duty cycle register to alter the brightness of an LED based on the incoming serial messages from the device set up in part 1. The data transfer is triggered directly by the hardware UART module when the Rx buffer register is full, meaning we achieve this with zero CPU utilization.
77

88
![](images/part2-gif.gif)
99
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
@@ -35,14 +35,14 @@ All software used in this example is listed here:
3535
- [Microchip PIC18F-Q Series Device Support (1.26.442)](https://www.microchip.com/mplab/mplab-code-configurator?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) or newer
3636

3737
## Hardware Used
38-
- **PIC18F57Q43 Curiosity Nano** [(DM164150)](https://www.microchip.com/Developmenttools/ProductDetails/DM164150?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha)
39-
- **NOTE:** There is second device used in [part 1](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1)
40-
- **Potentiometer (x1)** - used in [part 1](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1)
41-
- **[Optional]** Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) - this was used in lieu of a breadboard.
38+
- PIC18F57Q43 Curiosity Nano [(DM164150)](https://www.microchip.com/Developmenttools/ProductDetails/DM164150?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha)
39+
- **Note:** There is a second device used in [part 1](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1)
40+
- Potentiometer (x1) - used in [part 1](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1)
41+
- [Optional] Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) - this was used in lieu of a breadboard
4242

4343
## Setup
4444

45-
The hardware is setup as shown in more detail in [**this video**](https://www.youtube.com/watch?v=Wz7gt11gpSw). Below is a diagram of the specific pins used. You'll notice the Curiosity Nano Baseboard for clicks is missing from this diagram as they were only used as alternative to a breadboard in this cases
45+
The hardware is setup as shown in more detail in [**this video**](https://www.youtube.com/watch?v=Wz7gt11gpSw). Below is a diagram of the specific pins used. The Curiosity Nano Baseboard for clicks is missing from this diagram as they were only used as alternative to a breadboard in this case.
4646

4747
![](images/hardware_setup.jpg)
4848

@@ -55,7 +55,7 @@ The hardware is setup as shown in more detail in [**this video**](https://www.yo
5555

5656
## Operation & Summary
5757

58-
As noted before - this is part 2 of 2 of an example showing how to set up [Direct Memory Access (DMA)](https://www.microchip.com/design-centers/8-bit/peripherals/core-independent/direct-memory-access?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) using the [Microchip Code Configurator (MCC)](https://www.microchip.com/mplab/mplab-code-configurator) on a [PIC18F57Q43 microcontroller](https://www.microchip.com/mplab/mplab-code-configurator?utm_campaign=PIC18FQ43&utm_source=GitHub&utm_medium=hyperlink&utm_term=&utm_content=pic18f57q43-dma-uart-to-pwm-part2-MCU8_MMTCha) to transfer data from the devices UART recieve buffer to the PWM duty cycle register to alter the brightness of an LED based on the incoming serial messages from the device we set up in [**part 1.**](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1)
58+
The images below show the operation of the demo.
5959

6060
![part2-example-gif](images/part2-gif.gif)
6161
![functional-block-diagram](images/fbd-diagram.JPG)
@@ -65,92 +65,92 @@ As noted before - this is part 2 of 2 of an example showing how to set up [Direc
6565

6666
### Create New MPLAB X Project and Open MCC
6767
1. Same as before in [part 1](https://github.com/microchip-pic-avr-examples/pic18f57q43-dma-adc-to-uart-part1), but restated here for clarity.
68-
2. Open the MPLAB X IDE
68+
2. Open the MPLAB X IDE.
6969
3. Create new project by clicking the icon: ![new project icon](images/new_project_icon.png)
70-
1. Alternatively: file >> New Project
71-
4. In **Choose Project** window
72-
1. Select **Microchip Embedded** category
73-
2. Select **Standalone Project**
74-
3. Click **Next>**
75-
5. In **Select Device** window
76-
1. Select **PIC18F57Q43** as your device
70+
1. Alternatively: *File>New Project*
71+
4. In the Choose Project window:
72+
1. Select Microchip Embedded category.
73+
2. Select Standalone Project.
74+
3. Click **Next**.
75+
5. In Select Device window:
76+
1. Select PIC18F57Q43 as your device.
7777
2. Pro-tip: quickly filter for devices by inputting the last 3-4 characters of the device name and then selecting from the drop-down list (e.g. Q43).
78-
3. Click **Next>**
79-
6. In **Select Tool (Optional)** window
80-
1. If device is connected – select Microchip Kits -> PIC18F57Q43 Curiosity Nano (PKOB nano)
78+
3. Click **Next>**.
79+
6. In Select Tool (optional) window:
80+
1. If the device is connected – select Microchip Kits>PIC18F57Q43 Curiosity Nano (PKOB nano).
8181
2. If not, you can do this later when programming the device.
82-
3. Click **Next>**
83-
7. In **Select Compiler** window
84-
1. Select XC8 (v3.00)
85-
2. Click **Finish**
82+
3. Click **Next>**.
83+
7. In the Select Compiler window.
84+
1. Select XC8 (v3.00).
85+
2. Click **Finish**.
8686

8787
### Configure MCC
88-
8. In **Project Resources** under **System** select **Clock Control**
89-
9. In **Clock Control** tab, set Clock Source to **HFINTOSC**
90-
1. While this example uses a system clock of 1MHz, it should be noted that any larger value for the system clock should provide similar results.
88+
8. In **Project Resources** under System select **Clock Control**.
89+
9. In **Clock Control** tab, set Clock Source to HFINTOSC.
90+
1. While this example uses a system clock of 1 MHz, it must be noted that any larger value for the system clock will provide similar results.
9191

9292
![](images/configure-system-clock.jpg)
9393

94-
10. In **Project Resources** under **System** select **Configuration Bits**
95-
1. In the **Configuration Bits** tab, choose **Oscillator not enabled** under **External Oscillaotr Selection**
96-
2. Under **Reset Oscillator Selection** choose **HFINTOSC with HFFRQ = 4 MHz and CDIV = 4:1**
94+
10. In **Project Resources** under System select **Configuration Bits**.
95+
1. In the **Configuration Bits** tab, choose Oscillator not enabled under External Oscillator Selection.
96+
2. Under **Reset Oscillator Selection** choose "HFINTOSC with HFFRQ = 4 MHz and CDIV = 4:1".
9797

9898

99-
11. Under **Device Resources** left-hand pane
100-
1. Open the **Drivers** drop-down
101-
2. Double-click **PWM1_16BIT** under the **PWM** drop-down to add it to your project.
102-
3. Double-click **UART3** under the **UART** drop-down to add it to your project.
99+
11. Under **Device Resources** left-hand pane:
100+
1. Open the Drivers drop-down.
101+
2. Double-click PWM1_16BIT under the PWM drop-down to add it to your project.
102+
3. Double-click UART3 under the UART drop-down to add it to your project.
103103

104104

105-
12. Click on **UART3** under the **Project Resources** pane
106-
1. In the **UART** tab, set baud rate to 9600
105+
12. Click on **UART3** under the **Project Resources** pane.
106+
1. In the **UART** tab, set baud rate to 9600.
107107

108108
![](images/configure-uart3.jpg)
109109

110-
13. In the **PWM1_16BIT window** / Easy Setup tab
111-
1. Check the Slider next to **Enable PWM**
112-
2. Choose **Left aligned mode** under the **Mode** drop-down
113-
3. Set the **Requested Frequency** to 1 KHz
110+
13. In the **PWM1_16BIT window** / Easy Setup tab:
111+
1. Check the Slider next to Enable PWM.
112+
2. Choose Left aligned mode under the Mode drop-down.
113+
3. Set the Requested Frequency to 1 kHz.
114114

115115
![](images/mcc-configure-pwm-easy-view.jpg)
116116

117117

118118
14. In the **Pin Manager: Grid View** window, connect pins:
119-
1. RX3 -> RA4
120-
2. PWM -> RF3 (pin tied to CNano board LED0 as per schematic)
121-
3. Select **Pins** under the **System** drop-down in **Project Resources**
122-
4. Make sure that the **Analog** option for RA4 and RF3 is un-checked
119+
1. RX3 -> RA4.
120+
2. PWM -> RF3 (pin tied to CNano board LED0 as per schematic).
121+
3. Select Pins under the System drop-down in **Project Resources**.
122+
4. Make sure that the Analog option for RA4 and RF3 is un-checked.
123123

124124
![](images/mcc-configure-pin-manager-gridview.jpg)
125125
![](images/pinsview.jpg)
126126

127127

128-
15. Choose **DMA1** under **Device Resources**
129-
1. In the **DMA1** tab, select **DMA Enable**
130-
2. Choose the **Start Trigger** as **U3RX**
131-
3. Turn on **Start Trigger Enable**
132-
4. Choose **SFR**, **UART3**, **U3RXB** for **Source Region**, **Source Module**, and **Source SFR** respectively
133-
5. Choose **Source Mode** as unchanged
134-
6. Set **Source Message Size** to **1**
135-
7. Choose **SFR**, **PWM1_16BIT**, and **PWM1S1P1L** for **Destination Region**, **Destination Module** and **Destination SFR** respectively
136-
8. Set **Destination Mode** to **incremented**
137-
9. Set **Destination Message Size** to **2**
128+
15. Choose **DMA1** under **Device Resources**.
129+
1. In the **DMA1** tab, select DMA Enable.
130+
2. Choose the Start Trigger as U3RX.
131+
3. Turn on Start Trigger Enable.
132+
4. Choose SFR, UART3, U3RXB for Source Region, Source Module, and Source SFR respectively.
133+
5. Choose Source Mode as unchanged.
134+
6. Set Source Message Size to 1.
135+
7. Choose SFR, PWM1_16BIT, and PWM1S1P1L for Destination Region, Destination Module and Destination SFR respectively.
136+
8. Set Destination Mode to incremented.
137+
9. Set Destination Message Size to 2.
138138

139139

140140

141141
![](images/configure-dma-1.jpg)
142142

143143

144-
16. What we just did:
145-
1. **UART3** is the data **source module** of DMA channel 1
146-
2. **U3RXB** is the **SFR (Special function register) region** that we want data to be sourced from.
147-
3. The **U3RXB SFR register is 1-byte**, therefore the **mode is unchanged** since we don’t need to increment over multiple bytes or registers.
148-
4. Similarly, the **UART RX Buffer is 1-byte**, so we need to indicate that the **message size is 1-byte**
149-
5. **PWM1_16bit** is the data destination module, with the **PWM1S1P1L** being the specific destination SFR.
150-
6. The PWM period register is 16-bits, meaning we will need to **increment** in order to load both the low register that we started with and the PWM1S1P1H (high), which also means our **message size** is 2 bytes since we are loading two 8-bit registers.
151-
7. Set the DMA **start trigger** to fire every time the RX Buffer is full (**U3RX**).
152-
8. **NOTE*** we did not need to set VarSize, VarName, and Address parameters as these are only required when working with user-defined values in memory as opposed to fixed SFRs in this case.
153-
17. Click **Generate Project**
144+
16. Outcome of previous settings:
145+
1. UART3 is the data source module of DMA channel 1.
146+
2. U3RXB is the Special function register (SFR) region that we want data to be sourced from.
147+
3. The U3RXB SFR register is 1-byte, therefore the mode is unchanged since we don’t need to increment over multiple bytes or registers.
148+
4. Similarly, the UART RX Buffer is 1-byte, so we need to indicate that the message size is 1-byte.
149+
5. PWM1_16bit is the data destination module, with the PWM1S1P1L being the specific destination SFR.
150+
6. The PWM period register is 16-bits, meaning we will need to increment in order to load both the low register that we started with and the PWM1S1P1H (high), which also means our message size is two bytes since we are loading two 8-bit registers.
151+
7. Set the DMA start trigger to fire every time the RX Buffer is full (U3RX).
152+
8. **Note*** we did not need to set VarSize, VarName, and Address parameters as these are only required when working with user-defined values in memory as opposed to fixed SFRs in this case.
153+
17. Click **Generate Project**.
154154
18. In the `main.c` file that was generated, add the following line of code before `while(1)`:
155155
<br>
156156
`PWM1LDS = 0xB; // PWM1 auto-load trigger source is DMA1_Destination_Count_Done`
@@ -159,4 +159,4 @@ As noted before - this is part 2 of 2 of an example showing how to set up [Direc
159159
19. Click **Program the device** ![](images/program-device-icon.png)
160160

161161
## Conclusion
162-
There you have it. You just implemented some systems coms, automatic memory operations, and waveform while only having to write one line of code. Feel free to build on the project as you see fit, find more detailed applications in the documents linked in the [**resource section**](#related-documentation), or check out other code examples in the repo.
162+
This example showed how to implement some systems coms, automatic memory operations, and waveform generation while only having to write one line of code. The project can be built to accomodate other preferences as well. Find more detailed applications in the documents linked in the [**resource section**](#related-documentation), or check out other code examples in the repo.

0 commit comments

Comments
 (0)