Embedded Signal Processing 

Project 2: GPIO and DAC


Overview

M.S. students randomized groups of two each week, never working with same student, unless otherwise directed by instructor.
Ph.D. students have option to choose their groups (all Ph.D. or mix), with or without randomization.


The objective of this project is to become familiar with:

NOTE: Use the Project Report Template and see below for minimum required data content your reports and demos.

IN NO CASE may code or files or data or pictures be exchanged between student groups, there is to be NO COPYING of group reports!
Also, each student must be able to independently answer any questions themselves during demos.
All students are expected to learn all aspects of every project.
Nevertheless, students are encouraged to collaborate (not copy) during the lab sessions.



Part 1, GPIO (general-purpose input/output) Programming

zz
Fig. 1
zz
Fig. 2
#include "mbed.h"

DigitalOut gpo(D0);
DigitalOut led(LED_RED);

int main()
{
    while (true) {
        gpo = !gpo; // toggle pin
       // led = !led; // toggle led
       // wait(2.2f);
    }
}

zz
Fig. 3a


zz
Fig. 4


#include "mbed.h"

DigitalOut gpo(D0);
DigitalOut led(LED_RED);

int main()
{
    uint32_t mask16=1<<16;
    uint32_t dat1=(PTC->PDOR) | mask16; //set
    uint32_t dat0=(PTC->PDOR) & (!mask16); //clear
    while (true) {
         //example using write to a single bit, DOarduino=PTC16
        (PTC->PDOR)=dat0; //clear
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat0; //clear
        (PTC->PDOR)=dat0; //clear
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat1; //set
        (PTC->PDOR)=dat0; //clear
        //gpo = !gpo; // toggle pin
       // led = !led; // toggle led
       // wait(2.2f);     
     }
}
zz
Fig. 5


#include "mbed.h"
//#include "MK64F12.h"
DigitalOut gpo(D0);
DigitalIn gpi(D1);
DigitalOut ledred(LED_RED);
DigitalOut ledblue(LED_BLUE);

int main()
{
    gpo = 0; // set D0=0
    uint32_t D1in=0;
    uint32_t mask17=1<<17;
    while(1) {
        //D1in = (PTC->PDIR) & mask17; this doesnt seem to work?
        wait(0.5f);
        if(((PTC->PDIR)  & mask17)==0)  {
            ledblue=1;    //set red red if pin D1=0
            ledred=0;
        } else {
            ledblue=0;
            ledred=1; //Blue  }
        }
    }
    }


Part 2, DAC Programming


#include "mbed.h"

DigitalOut gpo(D0);
DigitalOut led(LED_RED);
AnalogOut  dac0out(DAC0_OUT);

int main()
{
    uint32_t mask16=1<<16;
    //PDOR is Port Data Output Register, offset: 0x0
    uint32_t dat1=(PTC->PDOR) | mask16; //set
    uint32_t dat0=(PTC->PDOR) & (!mask16); //clear
   
    while (true)
       {
        (PTC->PDOR)=dat0; //clear   use data bit as a timing flag/marker for oscilloscope
        (PTC->PDOR)=dat1; //set
         for(int nn=0;nn<6;nn++)
             {
             dac0out=(0.1f*nn);  
             //DAC0->DAT[0].DATL = (uint8_t)((uint16_t)(500+ 200*nn)      & 0xFF);
             //DAC0->DAT[0].DATH = (uint8_t)(((uint16_t)(500+ 200*nn) >> 8) & 0x0F);
             wait((float)(0.001e-6));
             }
        (PTC->PDOR)=dat0; //clear
        }   
}

zz
Fig. 6

#include "mbed.h"

DigitalOut gpo(D0);
DigitalOut led(LED_RED);
AnalogOut  dac0out(DAC0_OUT);

int main()
{
     //usually do not need the following few initialization lines
    //DAC0->C0 = 0; //reset state
    //DAC0->C1 = 0;
    //DAC0->C0 = DAC_C0_DACEN_MASK      // Enable
     //       | DAC_C0_DACSWTRG_MASK   // Software Trigger
     //        | DAC_C0_DACRFS_MASK;    // VDDA selected


    uint32_t mask16=1<<16;
    //PDOR is Port Data Output Register, offset: 0x0
    uint32_t dat1=(PTC->PDOR) | mask16; //set
    uint32_t dat0=(PTC->PDOR) & (!mask16); //clear
   
    while (true)
       {
        (PTC->PDOR)=dat0; //clear   use data bit as a timing flag/marker for oscilloscope
        (PTC->PDOR)=dat1; //set
         for(int nn=0;nn<6;nn++)
             {
             //dac0out=(0.1f*nn);  
             DAC0->DAT[0].DATL = (uint8_t)((uint16_t)(500+ 500*nn)      & 0xFF);
             DAC0->DAT[0].DATH = (uint8_t)(((uint16_t)(500+ 500*nn) >> 8) & 0x0F);
             wait((float)(0.001e-6));
             }
        (PTC->PDOR)=dat0; //clear
        }   
}

zz
Fig. 7

Report Data

zz            zz  


Report:


Copyright  2015 T. Weldon

Freescale, Kinetis are registered trademarks of Freescale Semiconductor, Inc.   Texas Instruments, TI, C2000, and Code Composer Studio are a registered trademarks of Texas Instruments Incorporated.   Adafruit is a registered TradeMark of Limor Fried.  ARM, Cortex and Keil are registered trademarks of ARM Limited (or its subsidiaries).  Apple, Yosemite, Mac OS, iPhone, iPad, MacBook, Mac, iTunes, and Xcode are trademarks of Apple inc. All other product or service names are the property of their respective owners.  Arduino is a registered trademark of Arduino.