Skip to content

Instantly share code, notes, and snippets.

@connerbrooks
Created March 25, 2016 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connerbrooks/c9c8ee531f6acb0d32b7 to your computer and use it in GitHub Desktop.
Save connerbrooks/c9c8ee531f6acb0d32b7 to your computer and use it in GitHub Desktop.
/*
* DAC.cpp
*
* Created on: Mar 23, 2016
* Author: conne
*/
#include "DAC.h"
volatile struct DAC_REGS *DAC_PTR[4] = {0x0,&DacaRegs,&DacbRegs,&DaccRegs};
void DAC_INIT(uint16_t dac)
{
EALLOW;
switch(dac) {
case 1:
CpuSysRegs.PCLKCR16.bit.DAC_A = 1;
break;
case 2:
CpuSysRegs.PCLKCR16.bit.DAC_B = 1;
break;
case 3:
CpuSysRegs.PCLKCR16.bit.DAC_A = 1;
break;
}
DAC_PTR[dac]->DACCTL.bit.DACREFSEL = REFERENCE_VDAC;
DAC_PTR[dac]->DACOUTEN.bit.DACOUTEN = 1;
EDIS;
}
void DAC_OUT(uint16_t dac, float value, int32_t gain, int32_t offset)
{
DAC_PTR[dac]->DACVALS.bit.DACVALS = (value*gain) + offset;
}
/*
* DAC.h
*
* Created on: Mar 23, 2016
* Author: cbrooks
*/
#ifndef DAC_H_
#define DAC_H_
#include <stdint.h>
#include <Energia.h>
// Defines
#define REFERENCE_VDAC 0
#define REFERENCE_VREF 1
#define DACA 1
#define DACB 2
#define DACC 3
// DAC initialization
void DAC_INIT(uint16_t dac);
// DAC output functions
void DAC_OUT(uint16_t dac, float value, int32_t gain, int32_t offset);
#endif /* DAC_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment