1 Star 0 Fork 0

microchip-pic-avr-examples/pic18f57q43-dma-uart-to-pwm-part2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

MCHP

Direct Memory Access (DMA) on PIC MCUs [Part 2] - UART to PWM

This is part 2 of 2 of an example showing how to set up Direct Memory Access (DMA) using the Microchip Code Configurator (MCC) on a PIC18F57Q43 microcontroller 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.

Related Documentation

Software Used

All software used in this example is listed here:

  • MPLAB® X IDE 5.30 or newer - link
  • MPLAB® XC8 2.10 or a newer compiler - link
  • MPLAB® Code Configurator (MCC) 3.95.0 or newer - link
  • MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs - link
  • Microchip PIC18F-Q Series Device Support (1.4.109) or newer - link

Hardware Used

  • PIC18F47Q10 Curiosity Nano (DM164150)
    • NOTE: There is second one used in part 1 --LINK--
  • Potentiometer (x1) - used in part 1
  • [Optional] Curiosity Nano Base for Click boards™ (AC164162) - this was only used in lieu of a breadboard.

Setup

The hardware is setup as shown more closely in this video --LINK--. Below is a diagram where of the specific pins I used. You'll notice the Curiosity Nano Baseboard for clicks is missing from this diagram as they were really only used as breadboard-alternatives in this case.

Potentiometer Q43 (part 1) Q43 (part 2)
+ 3.3V
gnd gnd
output RA0 (Yellow Wire)
RA3 (UART3 TX) -----------> RA4 (UART3 RX)

Operation

As noted before - this is part 2 of 2 of an example showing how to set up Direct Memory Access (DMA) using the Microchip Code Configurator (MCC) on a PIC18F57Q43 microcontroller 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.

Summary

Walkthrough

Create New MPLAB X Project and Open MCC

  1. Same as before in part 1 -- LINK --
  2. Open the MPLAB X IDE
  3. Create new project by clicking the icon:
    1. Alternatively: file >> New Project
  4. In Choose Project window
    1. Select Microchip Embedded category
    2. Select Standalone Project
    3. Hit Next>
  5. In Select Device window
    1. Select PIC18F57Q43 as your device
    2. Pro-tip: quickly filter for devices by inputting last 3-4 characters of the device and selecting from the drop-down list (e.g. Q43).
    3. Hit Next>
  6. In Select Tool (Optional) window
    1. If device is connected – select Microchip Kits -> PIC18F57Q43 Curiosity Nano (PKOB nano)
    2. If not, you can do this later when programming the device.
    3. Hit Next>
  7. In Select Compiler window
    1. Select XC8 (v2.10)
    2. Hit Finish

Configure MCC

  1. In System Module window
  2. Set Oscillator Select to HFINTOSC
    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.
  3. Under Device Resources left-hand pane
    1. Open the Peripherals drop-down
    2. Double-click the (PIC10/PIC12/…) instance of the PWM and USART3 peripherals to add them your project.

  1. In UART window/tab
    1. Set baud rate to 9600

  1. In the PWM window / Easy Setup tab
    1. Check the box next to Enable PWM
    2. In the Registers tab, Set PWM1LDS to DMA1
    3. Warning: Make this change only after doing the previous step where you configure the model in the Easy Setup window.

  1. In the Pin Manager: Grid View window, connect pins:
    1. RX3 -> A4
    2. TX3 -> A3 (not needed necessarily since we are just receiving)
    3. PWM -> RF3 (pin tied to CNano board LED0 as per schematic)

  1. In the DMA window manager
    1. Enable DMA CHANNEL 1 and make the changes shown in the table and screenshot below with explanations
Module Region SFR VarName VarSize Address Mode Message Size Start Trigger Abort Trigger
Src UART3 SFR U3RXB - - - unchanged 1 U3RX None
Dst PWM_16bit SFR PWMS1P1 - - - increment 2 (see above) (see above)

  1. What we just did:
    1. UART3 is the data source module of DMA channel 1
    2. U3RXB is the SFR (Special function register) region that we want data to be sourced from.
    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.
    4. Similarly, the UART RX Buffer is 1-byte, so we need to indicate that the message size is 1-byte
    5. PWM1_16bit is the data destination module, with the PWM1S1P1L being the specific destination SFR.
    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.
    7. Set the DMA start trigger to fire every time the RX Buffer is full (U3RX).
    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.
  2. Hit Generate Project and
  3. Hit Program the device

空文件

简介

This example [part2] shows how to set up Direct Memory Access (DMA) using the Microchip Code Configurator (MCC) on a PIC18F57Q43 microcontroller to transfer data from the UART recieve buffer to the PWM duty cycle register to alter the brightness of an LED. The data transfer is triggered by the UART module when the Rx buffer register is full. 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/microchip-pic-avr-examples/pic18f57q43-dma-uart-to-pwm-part2.git
git@gitee.com:microchip-pic-avr-examples/pic18f57q43-dma-uart-to-pwm-part2.git
microchip-pic-avr-examples
pic18f57q43-dma-uart-to-pwm-part2
pic18f57q43-dma-uart-to-pwm-part2
master

搜索帮助