You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- Please do not change this html logo with link -->
2
2

3
3
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
5
5
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.
7
7
8
8

9
9
<!-- 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:
35
35
-[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
-**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.
-**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
42
42
43
43
## Setup
44
44
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.
46
46
47
47

48
48
@@ -55,7 +55,7 @@ The hardware is setup as shown in more detail in [**this video**](https://www.yo
55
55
56
56
## Operation & Summary
57
57
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)
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.
138
138
139
139
140
140
141
141

142
142
143
143
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**.
154
154
18. In the `main.c` file that was generated, add the following line of code before `while(1)`:
155
155
<br>
156
156
`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
159
159
19. Click **Program the device**
160
160
161
161
## 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