Circuit Playground Express (& other ATSAMD21 Boards) DAC Hacks

Similar documents
TV Synchronism Generation with PIC Microcontroller

BTV Tuesday 21 November 2006

Lab experience 1: Introduction to LabView

ANTENNAS, WAVE PROPAGATION &TV ENGG. Lecture : TV working

User's Manual. Rev 1.0

Arduino Lesson 3. RGB LEDs

NAPIER. University School of Engineering. Advanced Communication Systems Module: SE Television Broadcast Signal.

TV Character Generator

Working with a Tektronix TDS 3012B Oscilloscope EE 310: ELECTRONIC CIRCUIT DESIGN I

imso-104 Manual Revised August 5, 2011

Exercise 1-2. Digital Trunk Interface EXERCISE OBJECTIVE

The Micropython Microcontroller

Lesson 4 RGB LED. Overview. Component Required:

Department of Communication Engineering Digital Communication Systems Lab CME 313-Lab

Design and Implementation of an AHB VGA Peripheral

Experiment 9A: Magnetism/The Oscilloscope

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Dave Jones Design Phone: (607) Lake St., Owego, NY USA

Traditionally video signals have been transmitted along cables in the form of lower energy electrical impulses. As new technologies emerge we are

Model 5250 Five Channel Digital to Analog Video Converter Data Pack

Spectrum Analyser Basics

Introduction. The Clock Hardware. A Unique LED Clock Article by Craig A. Lindley

ME EN 363 ELEMENTARY INSTRUMENTATION Lab: Basic Lab Instruments and Data Acquisition

Experiment 13 Sampling and reconstruction

CM-392-Video to HDMI Scaler Box ID#481

What is sync? Why is sync important? How can sync signals be compromised within an A/V system?... 3

S op o e p C on o t n rol o s L arni n n i g n g O bj b e j ctiv i e v s

SingMai Electronics SM06. Advanced Composite Video Interface: DVI/HD-SDI to acvi converter module. User Manual. Revision th December 2016

SingMai Electronics SM06. Advanced Composite Video Interface: HD-SDI to acvi converter module. User Manual. Revision 0.

Presented by: Amany Mohamed Yara Naguib May Mohamed Sara Mahmoud Maha Ali. Supervised by: Dr.Mohamed Abd El Ghany

Rec. ITU-R BT RECOMMENDATION ITU-R BT * WIDE-SCREEN SIGNALLING FOR BROADCASTING

Chapter 3 Fundamental Concepts in Video. 3.1 Types of Video Signals 3.2 Analog Video 3.3 Digital Video

Learning to Use The VG91 Universal Video Generator

High Performance TFT LCD Driver ICs for Large-Size Displays

Multimedia Systems Video I (Basics of Analog and Digital Video) Mahdi Amiri April 2011 Sharif University of Technology

A 400MHz Direct Digital Synthesizer with the AD9912

AC334A. VGA-Video Ultimate BLACK BOX Remote Control. Back Panel View. Side View MOUSE DC IN BLACK BOX ZOOM/FREEZE POWER

imso-104 Manual Revised July 19, 2012

The BAT WAVE ANALYZER project

Lecture 14: Computer Peripherals

The Cathode Ray Tube

ASK THE EXPERTS: Procedure for Verifying Magnetic Pickup Signal Integrity Using a Windrock Portable Analyzer

DataSAT ACU-2 Controller Wiring Configuration - Operation

Experiment # 4 Counters and Logic Analyzer

MIE 402: WORKSHOP ON DATA ACQUISITION AND SIGNAL PROCESSING Spring 2003

To discuss. Types of video signals Analog Video Digital Video. Multimedia Computing (CSIT 410) 2

MAIN PCA TEST PROCEDURE DOCUMENT NUMBER:

ECE 5765 Modern Communication Fall 2005, UMD Experiment 10: PRBS Messages, Eye Patterns & Noise Simulation using PRBS

N3ZI Digital Dial Manual For kit with Backlit LCD Rev 4.00 Jan 2013 PCB

Model 6010 Four Channel 20-Bit Audio ADC Data Pack

fbas_enc: FBAS(CVBS) encoder for PAL and/or NTSC

High-Definition, Standard-Definition Compatible Color Bar Signal

NanoGiant Oscilloscope/Function-Generator Program. Getting Started

Scanning For Photonics Applications

Log-detector. Sweeper setup using oscilloscope as XY display

Model 5405 Dual Analog Sync Generator Data Pack

Converters: Analogue to Digital

SM02. High Definition Video Encoder and Pattern Generator. User Manual

PRELIMINARY INFORMATION. Professional Signal Generation and Monitoring Options for RIFEforLIFE Research Equipment

Grove - OLED Display 1.12"

MaxView Cinema Kit Quick Install Guide

Elements of a Television System

IBM Enhanced Color Display. Personal Computer. Hardware Reference Library _.-

ECE-320 Lab 5: Modeling and Controlling a Pendulum

D R M A X - 2 DDS FREQUENCY SYNTHESIZED DRM MW TRANSMITTER. User s Guide (Please read carefully before using for the first time!)

Video to SXGA Converter Box ID#475

Application Note AN-708 Vibration Measurements with the Vibration Synchronization Module

W0EB/W2CTX DSP Audio Filter Operating Manual V1.12

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

Designing Custom DVD Menus: Part I By Craig Elliott Hanna Manager, The Authoring House at Disc Makers

XTAL Bank DDS Version 0.02 Sept Preliminary, highly likely to contain numerous errors

Video SystemVideo System

AC335A. VGA-Video Ultimate Plus BLACK BOX Back Panel View. Remote Control. Side View MOUSE DC IN OVERLAY

4830A Accelerometer simulator Instruction manual. IM4830A, Revision E1

A. All equipment and materials used shall be standard components that are regularly manufactured and used in the manufacturer s system.

Interfacing Analog to Digital Data Converters. A/D D/A Converter 1

Digital Fundamentals. Lab 5 Latches & Flip-Flops CETT Name: Date:

Electrical and Electronic Laboratory Faculty of Engineering Chulalongkorn University. Cathode-Ray Oscilloscope (CRO)

TFT-LCD Color Monitor FS-L4201C

Choosing an Oscilloscope

Troubleshooting. 1. Symptom: Status indicator (Red LED) on SSR is constant on. 2. Symptom: Output indicator (Yellow LED) on SSR is flashing.

Agilent 6000 Series Oscilloscope Demo Guide

SNG-2150C User s Guide

Zero Crossover Dynamic Power Synchronization Technology Overview

Model 5240 Digital to Analog Key Converter Data Pack

Microcontrollers. Outline. Class 4: Timer/Counters. March 28, Timer/Counter Introduction. Timers as a Timebase.

Manual of Operation for WaveNode Model WN-2m. Revision 1.0

Obtain Power Measurements of a DOCSIS Downstream Signal Using a Spectrum Analyzer

Sound & Vision, August 2004 reprinted by permission

Analog/digital watch Multi frequency reception, 4 digit LCD, 3 hands. Preliminary Specification

PCM ENCODING PREPARATION... 2 PCM the PCM ENCODER module... 4

University of Utah Electrical & Computer Engineering Department ECE1050/1060 Oscilloscope

Ch. 1: Audio/Image/Video Fundamentals Multimedia Systems. School of Electrical Engineering and Computer Science Oregon State University

USER MANUAL. VP-501N UXGA Scan Converter MODEL: P/N: Rev 5

Viewing Serial Data on the Keysight Oscilloscopes

"shell" digital storage oscilloscope (Beta)

USER MANUAL. 28" 4K Ultra HD Monitor L28TN4K

SigPlay User s Guide

Project Final Report. Z8 Arcade! 4/25/2006 James Bromwell,

Doc: page 1 of 5

Transcription:

Circuit Playground Express (& other ATSAMD21 Boards) DAC Hacks Created by Phillip Burgess Last updated on 2017-11-17 01:49:03 AM UTC

Guide Contents Guide Contents Overview Getting Started Composite Video Output How It Works Creating New TV Projects Limitations So there s NTSC, but what about PAL video? Why not color? Transmitting AM Radio Creating New Radio Projects How It Works Limitations Isn t broadcasting without a license illegal? Even with an amateur license, isn t broadcasting in this frequency band illegal? Will the FCC haul me away? 2 3 3 5 6 7 8 8 8 9 9 10 12 13 Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 2 of 13

Overview With each new generation of microcontrollers we tend to dwell on quantifiables like memory and speed bigger, faster programs! At the same time, new devices often bring additional capabilities that are overlooked at first glance. These features open whole new doors, beyond what program size or speed can do. The SAMD ARM M0 microcontroller used in Circuit Playground Express, Feather M0 and other Adafruit boards with the Express or M0 designations along with the Arduino Zero include some intriguing new features, among them: A digital-to-analog converter (DAC). Pin A0 can provide a true analog voltage between 0 and 3.3 Volts. Previously, Arduino s so-called analogwrite() function wasn't really analog it generated a pulse-widthmodulated digital signal. Direct memory access (DMA) allows data transfers between memory and peripherals (including the DAC) very quickly and without CPU intervention it goes about its task in the background while other code continues to run at 100% speed. We ll demonstrate by generating composite TV and AM radio signals straight from the board. No shields or breadboards or soldering extra components, just some simple test leads! While the projects shown here have a vintage rinky-dink flair, the fact that a microcontroller can do this entirely on its own no extra parts, just some wires is pretty remarkable. Rather than just thinking bigger and faster, what unconventional ideas and applications might you hatch from new hardware? None of this is really what the DAC is intended for, but it s cool in a demo-scene kind of way. Getting Started These demo projects will require: An Atmel SAMD M0-based microcontroller board such as Circuit Playground Express, Feather M0 or Arduino Zero. 8-bit AVR boards and classic 8-bit Circuit Playground are not compatible. Corresponding board support enabled in the Arduino IDE: Tools Board Boards Manager Adafruit boards require an extra step first, explained in this guide. For Circuit Playground Express: some alligator clip test leads. For other boards, some solid-core wire. The Adafruit_ZeroDMA library: Download Adafruit_ZeroDMA Library https://adafru.it/lnd This library must be installed manually it s experimental and won t appear in the normal Arduino Library Manager window. If you re unfamiliar with manual library installation, the process is explained in this guide. You ll need to quit Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 3 of 13

and restart the Arduino IDE. To confirm that SAMD board support is working, try uploading the basic blink sketch to a board. To confirm the Adafruit_ZeroDMA library is correctly installed, check that the Files Examples Adafruit_ZeroDMA rollover menu is present. Each of the projects that follow will require its own additional library, again manually installed. Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 4 of 13

Composite Video Output The DAC is just fast enough to generate low-resolution composite video that can be viewed on a television or monitor with composite video input (typically a yellow RCA connector). There are very few pixels, and it s only grayscale, but it s sufficient for creating simple games or to print readings from sensors. To use this, download and manually install the Adafruit_CompositeVideo library: Download Adafruit_CompositeVideo Library https://adafru.it/wae This also requires the Adafruit_GFX library, which is much easier to install using the Arduino Library Manager: Sketch Include Library Manage Libraries (enter GFX in the search field). After the Adafruit_CompositeVideo library is installed, there are a couple of example sketches. One prints the current value from the Circuit Playground light sensor, another shows large horizontal-scrolling text. Connect a couple of test leads to pin A0 and any ground pin. Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 5 of 13

At the other end, connect A0 to the tip (center) of the composite video connector, and ground to the ring (outside). Depending on the TV/monitor connection and available cabling, you may need a spare composite cable or maleto-male adapter to get something you can clip onto. Since I ll be testing the code often, I cobbled together a somewhat more permanent connector from a spare cable and test leads, but it s not necessary to go to such lengths if just trying it out. How It Works Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 6 of 13

NTSC video runs at 29.97 frames per second. Each frame is comprised of 525 horizontal scanlines. Each scanline starts and ends with carefully-timed synchronization signals, with image data in-between: an analog voltage from about 0.3 to 1.0V determines the brightness at that point along the scanline. Twice per frame, there are also vertical synchronization signals following a specific timing and pattern. Some of these blips are just a couple of microseconds long! Digital outputs can easily manage such timing, but for the SAMD DAC this is challenging the makeshift video signal is just good enough for most screens to latch on to. Creating New TV Projects To use the library, add these two lines at the top of your sketch: #include <Adafruit_GFX.h> #include <Adafruit_CompositeVideo.h> Then, before the setup() function, declare a global object of type Adafruit_NTSC40x24: Adafruit_NTSC40x24 display; (It s called this just in case other resolutions are supported in the future but don t hold your breath, I ve tried going higher and the DAC can t quite make a stable image.) Then, inside your setup() function, call the object s begin() function to enable composite video out on the A0 pin: Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 7 of 13

display.begin(); Because it builds upon the Adafruit_GFX library, all the same drawing functions (including fonts) are available as with our other Arduino-compatible displays. Colors passed to the drawing functions should be 8-bit grayscale values (0 to 255, where 0=black, 255=white). display.drawline(0, 0, 39, 23, 128); // Gray line, corner-to-corner display.settextcolor(255); // White text display.print("hello World"); Limitations Circuit Playground Express speaker is disabled; tone() and other audio code will not work in combination with this 40x24 pixel resolution; actual usable area may be slightly smaller due to overscan Grayscale only Adafruit_CompositeVideo and Adafruit_AMRadio (on the next page) both use the DAC peripheral and the same timer/counter; the two libraries can not be used at the same time. The video resolution is extremely crude it s more a novelty than anything else. If you need high-quality visuals from a small board, consider a Raspberry Pi Zero! Folks have generated much sharper video (with color, even!) from much more modest hardware. These all require extra components though. The benefit to this simple gator-clip approach is that classrooms might not allow soldering, or a lesson might not have time for assembling parts on a breadboard. Or it s just fun showing off. So there s NTSC, but what about PAL video? It s not in there. And unless you re actually using a really old CRT telly, it s probably not necessary. Most, if not all, LCD monitors that handle composite video will automatically detect and adapt to the video signal, so NTSC is fine. This is true even if you are in a "PAL zone" like Europe! Why not color? Composite color video is insane and would require a DAC orders of magnitude faster. Let s see where microcontrollers are in a few years! Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 8 of 13

Transmitting AM Radio kind of. Temper your expectations. :) Another task we can use this fast DAC for is generating AM radio waveforms, which can be heard on a regular AM receiver tuned to the right frequency and held very close by (power is limited and an ideal antenna is impractically long, but it s a fun proof of concept). This too requires a library: Download Adafruit_AMRadio Library https://adafru.it/waf After the Adafruit_AMRadio library is installed, there are a couple of example sketches. One plays the Jeopardy theme song over the AM 540 KHz frequency, the other plays a Godzilla roar sound. Clip a test lead or connect a length of wire to pin A0 as a makeshift antenna. Just one end the other is left unconnected. This is far from an optimal antenna, but we need something there. An ideal antenna would be something like 450 feet long clearly that s not gonna happen. The test lead will do fine. Creating New Radio Projects To use the library, add this line at the top of your code: Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 9 of 13

#include <Adafruit_AMRadio.h> Before the setup() function, declare a global object of type Adafruit_AMRadio: Adafruit_AMRadio radio; Then, inside your setup() function, call the object s begin() function to start it running. By default this will transmit at 540 KHz, but you can optionally pass an integer argument, the desired frequency in Hertz: radio.begin(530000); // Transmit at 530 KHz instead Try to keep this as low as possible, but still within the AM band (530 to 1700 KHz). It won t run at precisely this frequency the DMA clock has to run at some integer divisor of the 48 MHz CPU clock so it will pick the closest thing it can muster, which may be a few megahertz to either side. If your AM radio has analog tuning you can dial it in for the best reception, like the old days. The tone() function can be used for playing notes similar to the normal Arduino tone() function which accepts a frequency in Hertz and a duration in milliseconds (unlike Arduino s tone(), the duration is required here). For example, to play middle C (262 Hertz) for one half second (500 milliseconds): radio.tone(262, 500); If you need more granular control over the audio waveform, use the radio.write() function to control the wave directly, passing a value from 0 to 1023 (the library s equivalent of Arduino s 10-bit analogwrite() function). For example, a neutral level: radio.write(512); This alone does not generate a sound. You then need to call write() repeatedly and quickly to generate an audio waveform. This can be seen in the zilla example sketch, which reads from a digitized audio sample stored in program memory and calls the write() function roughly 11,025 times a second. Any existing code that uses analogwrite(a0) to generate sound through the Circuit Playground speaker can be easily modified to use the radio library instead. How It Works Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 10 of 13

Amplitude modulation (AM) the earliest method of sound transmission over radio conveys a relatively low-frequency variable audio wave (such as voice or music, up to a few kilohertz) into a much higher fixedfrequency radio wave (500 KHz or more), called the carrier wave, by you guessed it modulating the amplitude of the carrier wave in direct proportion to the sound wave s shape. Image credit: Wikimedia Commons contributor Berserkerus, CC-SA The DAC is barely fast enough to generate a reasonable carrier wave for the lower end of the AM radio band. Our library simply adjusts the peaks and troughs of this wave in response to the Arduino sketch code. Actually the DAC isn t fast enough for this. We re cheating! Generating a 540 KHz square wave requires 1,080 kilosamples per second from the DAC, but it s really only rated for 350 Ksps. We simply feed it at the faster rate. This is not harmful in any way to the DAC, the output just isn t numerically precise until it s fully settled (the 350K rate), and we re interrupting it before it gets all the way there. It s reasonably close though. The video library does something similar, but not quite as fast, as that one does require a little more precision. This is also why it only works toward the lower end of the AM band. As the frequency increases, the DAC output precision decreases. Zooming way in with an oscilloscope, the 540 KHz carrier wave is visible. Though we re feeding the DAC a square wave, the slow settling time produces this truncated triangle wave. This works to our benefit, as the carrier should ideally be a sine wave, and this is a coarse but acceptable facsimile. Zooming out a bit, you can see the carrier wave amplitude (height) being modulated by the lowerfrequency sound wave. Zooming out still further, the individual audio samples from a digitized Godzilla roar 11,050 per second can be seen. The high-frequency carrier wave is so Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 11 of 13

much smaller by comparison, it appears solid on the scope. Limitations Circuit Playground Express speaker is disabled; tone() and other audio code will not work in combination with this Range is extremely limited, just a few inches this is science project fun and not a serious radio transmitter! Limited to lower AM band; example code uses 540 KHz Adafruit Industries https://learn.adafruit.com/circuit-playground-express-dac-hacks Page 12 of 13

Adafruit_CompositeVideo (on the prior page) and Adafruit_AMRadio both use the DAC peripheral and the same timer/counter; the two libraries can not be used at the same time. Isn t broadcasting without a license illegal? Even with an amateur license, isn t broadcasting in this frequency band illegal? Will the FCC haul me away? Maybe in some ultra-pedantic interpretation, but the range is so limited (less than a foot) it can t possibly interfere with other receivers or devices, so this shouldn t be a problem. It s only broadcasting if targeting a wider audience. This is low-grade noise. But hey, if the experiment piques your interest, why not study for an amateur radio license? Adafruit Industries Last Updated: 2017-11-17 01:49:02 AM UTC Page 13 of 13