collab/PineapplePad

git clone https://git.julia.blue/collab/PineapplePad

Joseph RyanAdd sfx0e8c935

master
865 B28 linesraw
1#include <stdint.h>
2#include "../inc/tm4c123gh6pm.h"
3#include "../inc/DAC.h"
4
5void DAC_Init(void){
6    SYSCTL_RCGCPWM_R |= SYSCTL_RCGCPWM_R0;
7    SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R4;
8    GPIO_PORTE_LOCK_R = 0x4C4F434B;
9    GPIO_PORTE_CR_R |= 0x20;
10    GPIO_PORTE_DIR_R |= 0x20;
11    GPIO_PORTE_DEN_R |= 0x20;
12    GPIO_PORTE_AMSEL_R &= ~0x20;
13    GPIO_PORTE_AFSEL_R |= 0x20;
14    GPIO_PORTE_PCTL_R |= GPIO_PCTL_PE5_M0PWM5;
15    SYSCTL_RCC_R &= ~SYSCTL_RCC_USEPWMDIV;
16    PWM0_2_CTL_R |= PWM_2_CTL_DBCTLUPD_I;
17    PWM0_2_GENA_R &= PWM_2_GENA_ACTCMPBD_NONE;
18    PWM0_2_GENB_R |= (PWM_2_GENB_ACTCMPBD_ZERO | PWM_2_GENB_ACTLOAD_ONE);
19    PWM0_2_LOAD_R = (256 - 1);
20    PWM0_2_CMPB_R = 128;
21    PWM0_2_CTL_R |= PWM_2_CTL_ENABLE;
22    PWM0_INVERT_R |= PWM_INVERT_PWM5INV;
23    PWM0_ENABLE_R |= PWM_ENABLE_PWM5EN;
24}
25
26void DAC_Out(uint32_t data){
27    PWM0_2_CMPB_R = data;
28}