Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

DAC Programming in LPC1768- (Part 10/21)

By Prabakaran P.M March 2, 2016

This tutorial will teach you how to use the inbuilt DAC of LPC1768 to generate a analog output (cosine wave) from a digital pin and display in the CRO. For setting up the Environment for the development of ARM cortex M3 is well discussed in this article.

The LPC 1768 is ARM Cortex- M3 based Microcontrollers for embedded application features in low power consumption and a high level of integration. The ARM Cortex M3 is designed in a such way to enhance debug features and a higher level of system integration. It clocks at a CPU frequency of 100 MHz, and incorporates a 3-stage pipeline and uses a Harvard architecture with separate local instruction and data buses for third bus peripherals. The ARM Cortex- M3 CPU have an internal pre-fetch unit to support speculative branching. The peripheral components include 512KB of flash memory, 64kb of data memory, Ethernet MAC, USB OTG, 4 UART’s, 8-channel general purpose DMA controller, 2 SSP Controllers, 10-bit DAC, Quadrature encoder interface, SPI interface, 3 I2C bus interface, 2 input plus 2 outputs I2S bus interface, 4 general purpose timers, ultra-low power Real-Time Clock (RTC) with separate battery supply, and up to 70 general purpose I/O pins, 6-output general purpose PWM. The LPC1768/66/65/64 are pin-compatible with the 100-pin LPC236x ARM7-based Microcontroller series.


DAC Programming in LPC1768 Prototype

Fig. 1: DAC Programming In LPC1768 Prototype

The ARM Cortex M3(NXP LPC1768) contains a 10-bit DAC (Digital to Analog Converter). All the pins of LPC1768 has alternate functions to the default digital input-output functions we have to first select the pin for the appropriate function. ADC of it has 8 multiplexed pins. (See table below). The second alternate function for P0.26 (pin 6) is AOUT. ie the DAC output.

SELECTING CLOCK FOR DAC:

By assuming that the main clock for the LPC1768 has been programmed. Each LPC1768 peripheral including the DAC has a clock derived from the main clock as illustrated.

Peripheral Clock Divider

As shown in the below block the frequency of the peripheral clock is determined by two bits in the PCLKSEL registers. DAC is included in PCLKSEL0. With the NXP LPC1768 the peripheral clocks are always active. Following RESET PCLKSEL registers are cleared setting the peripheral clock frequency to CCLK/4 to all the peripherals. The user will have a choice of frequency which can be determined by two bits for each peripherals among the peripheral clock selection registers PCLKSEL0 and PCLKSEL1. By default at reset all values are 00 ie CCLK/4.

00

PCLK_peripheral = CCLK/4

01

PCLK_peripheral = CCLK

10

PCLK_peripheral = CCLK/2

11

PCLK_peripheral = CCLK/8, except for CAN1, CAN2,
and CAN filtering when “11” selects = CCLK/6.

Fig. 2: Bit Value Of PCLK_Peripheral For Clock Frequency

 

Bit

Symbol

Description

1:0

PCLK_WDT

Peripheral clock selection for WDT.

3:2

PCLK_TIMER0

Peripheral clock selection for TIMER0.

5:4

PCLK_TIMER1

Peripheral clock selection for TIMER1.

7:6

PCLK_UART0

Peripheral clock selection for UART0.

9:8

PCLK_UART1

Peripheral clock selection for UART1.

11:10

–

Reserved.

13:12

PCLK_PWM1

Peripheral clock selection for PWM1.

15:14

PCLK_I2C0

Peripheral clock selection for I2C0.

17:16

PCLK_SPI

Peripheral clock selection for SPI.

19:18

–

Reserved.

21:20

PCLK_SSP1

Peripheral clock selection for SSP1.

23:22

PCLK_DAC

Peripheral clock selection for DAC.

25:24

PCLK_ADC

Peripheral clock selection for ADC.

27:26

PCLK_CAN1

Peripheral clock selection for CAN1.[1]

29:28

PCLK_CAN2

Peripheral clock selection for CAN2.[1]

31:30

PCLK_ACF

Peripheral clock selection for CAN acceptance filtering.[1]

Fig. 3: Bit Value And Description Of PCLK_Peripheral In LPC1768

Code snipet:

LPC_SC->PCLKSEL0 |= 1 <<24; //pclk = cclk

 

SELECTING THE DAC FUNCTION TO GPIO:

As we discussed in the previous articles the GPIO function is selected with the help of PINSEL register of the Pin control block. Port 1 is controlled by PINSEL0,1 and Port 1 is controlled by PINSEL2,3. RESET makes all the bits of PINSEL to be cleared results in attachment of GPIO function to the pins.

Each pin is controlled by 2 consecutive bits of PINSEL register. PINSEL0[1:0] bits controls the Pin P0.0, PINSEL0[3:2] bits controls the Pin P0.1. PINSEL0[31:30] bits controls the Pin P0.15, etc.- PSEL3[31:30] bits will control the pins Pin P1.31. The DAC is attached to pin P0.26. The following code will select alternate function 2 (DAC or AOUT) for pin P0.26.

Adc Channel

Port Pin

Pin Functions

Associated PINSEL Register

AD0

P0.23

0-GPIO, 1-AD0[0], 2-I2SRX_CLK, 3-CAP3[0]

14,15 bits of PINSEL1

AD1

P0.24

0-GPIO, 1-AD0[1], 2-I2SRX_WS, 3-CAP3[1]

16,17 bits of PINSEL1

AD2

P0.25

0-GPIO, 1-AD0[2], 2-I2SRX_SDA, 3-TXD3

18,19 bits of PINSEL1

AD3

P0.26

0-GPIO, 1-AD0[3], 2-AOUT, 3-RXD3

20,21 bits of PINSEL1

AD4

P1.30

0-GPIO, 1-VBUS, 2- , 3-AD0[4]

28,29 bits of PINSEL3

AD5

P1.31

0-GPIO, 1-SCK1, 2- , 3-AD0[5]

30,31 bits of PINSEL3

AD6

P0.3

0-GPIO, 1-RXD0, 2-AD0[6], 3-

6,7 bits of PINSEL0

AD7

P0.2

0-GPIO, 1-TXD0, 2-AD0[7], 3-

4,5 bits of PINSEL0

Fig. 4: Selecting DAC Function Using GPIO Pins With PINSEL register In LPC1768

Code snipet:

LPC_PINCON->PINSEL1 |= 0x02<<20; //Pin P0.26 allocated to alternate function 2

DAC Registers and DAC Operation:

For simple operations only the DAC converter register DACR is required.

DACR register:

 

Bit

Symbol

Description

Reset Value

5:0

–

Reserved, user software should not write ones to reserved bits. 
The value read from a reserved bit is not defined.

NA

15:6

VALUE

After the selected settling time after this field is written with a newVALUE, the voltage on the AOUT pin (with respect to VSSA) is VALUE x ((VREFP – VREFN)/1024) + VREFN.

0

16

BIAS[1]

0 The settling time of the DAC is 1 us max, and the maximum current is 700 uA. 
—This allows a maximum update rate of 1 MHz.
1 The settling time of the DAC is 2.5us and the maximum current is 350 uA. 
—This allows a maximum update rate of 400 kHz.

0

31:17

–

Reserved, user software should not write ones to reserved bits.

 

Fig. 5: Bit Description Of DACR Register In LPC1768

The DACR register is a read/write register that includes the digital value to be converted to analog, and a bit that trades off performance vs. power. With references voltages between 3.3 and 0 the output AOUT will be;

AOUT = 3.3*VALUE/1024

Code for DAC to generate a 1Volt output.

Code snipet:

LPC_DAC->DACR = 0x155<<6; //output = 1 volt

Controlling the DAC ouput with the System Tick:

In this cosine example the time between steps can also be determined by the software delay loop. However a software loop will use most of the processors resources. A alternate better solution is to use a hardware timer such as the system tick to generate a time reference to control the output changes. The tick period is set by the register LOAD. The system tick will generate a non maskable interrupt which vectors to the routine SysTick_Handler( ) that generates an output voltage step.

Create a project using Keil uvision4 for LPC1768 Microcontroller:

In this section, we will start creating a project in Keil MDK we have already installed Keil µVision and Co-MDK Plug-in + CoLinkEx Drivers required for the CoLinkEx programming adapter. You can start by downloading the project files and kick start your practical experiment.

Code.rar

For more details on interfacing the LCD in 4 bit mode with LPC1768 refer this link.

Output Waveform of DAC Programming in LPC1768

Fig. 6: Output Waveform Of DAC Programming In LPC1768

Project Source Code

###
 
The codes are linked in Description ###

Circuit Diagrams

Circuit-Diagram-of-DAC-Programming-in-LPC1768

Project Components

  • LCD
  • LED
  • Resistor

Project Video


Filed Under: ARM

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • System for measuring the amount of Joules delivered from a capacitor discharge.
  • Two sections broadband impedance matching
  • The GaN revolution must now happen?
  • How to find the resonance frequency and impedance of a planar spiral coil in HFSS?
  • PhD for Electronics Designers

RSS Electro-Tech-Online.com Discussions

  • The Analog Gods Hate Me
  • Impact of Tariffs on PCB Fab
  • More fun with ws2812 this time XC8 and CLC
  • I Wanna build a robot
  • Wierd makita battery

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz
  • Amphenol RF introduces SMPM to SMPM assemblies on RG-178 cable

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe