Skip to content

Commit

Permalink
Today's work
Browse files Browse the repository at this point in the history
  • Loading branch information
rosterloh committed Apr 12, 2014
1 parent 6a935c2 commit 7aa3aa7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
13 changes: 10 additions & 3 deletions DAC/DAC.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
// Initialize 4-bit DAC
// Input: none
// Output: none
void DAC_Init(void){

void DAC_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x02; // 1) activate Port B
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
// 2) no need to unlock
GPIO_PORTB_AMSEL_R &= ~0x0F; // 3) disable analog functionality on PB3-0
GPIO_PORTB_PCTL_R &= ~0x0000FFFF;// 4) configure PB3-0 as GPIO
GPIO_PORTB_DIR_R |= 0x0F; // 5) make PB3-0 out
GPIO_PORTB_AFSEL_R &= ~0x0F; // 6) disable alt funct on PB3-0
GPIO_PORTB_DEN_R |= 0x0F; // 7) enable digital I/O on PB3-0
}


Expand All @@ -23,5 +30,5 @@ void DAC_Init(void){
// Input: 4-bit data, 0 to 15
// Output: none
void DAC_Out(unsigned long data){

GPIO_PORTB_DATA_R = data;
}
2 changes: 1 addition & 1 deletion DAC/Lab13.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(void){ // Real Lab13
EnableInterrupts(); // enable after all initialization are done
while(1){
// input from keys to select tone

}

}
Expand Down
29 changes: 25 additions & 4 deletions DAC/Piano.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
// Initialize piano key inputs
// Input: none
// Output: none
void Piano_Init(void){

void Piano_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x10; // activate Port E
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
// no need to unlock
GPIO_PORTE_AMSEL_R &= ~0x0F; // disable analog functionality on PE3-0
GPIO_PORTE_PCTL_R &= ~0x0000FFFF;// configure PE3-0 as GPIO
GPIO_PORTE_DIR_R &= ~0x0F; // make PE3-0 in
GPIO_PORTE_AFSEL_R &= ~0x0F; // disable alt funct on PE3-0
GPIO_PORTF_PUR_R |= 0x0F; // enable pull-up on PE3-0
GPIO_PORTE_DEN_R |= 0x0F; // enable digital I/O on PE3-0
}
// **************Piano_In*********************
// Input from piano key inputs
Expand All @@ -25,6 +33,19 @@ void Piano_Init(void){
// 0x01 is key 0 pressed, 0x02 is key 1 pressed,
// 0x04 is key 2 pressed, 0x08 is key 3 pressed
unsigned long Piano_In(void){

return 0; // remove this, replace with input
int key = GPIO_PORTE_DATA_R;
// For now just return the lowest value
if(key&0x01) {
key = 0x01;
} else if(key&0x02) {
key = 0x02;
} else if(key&0x04) {
key = 0x04;
} else if(key&0x08) {
key = 0x08;
} else {
key = 0x00;
}

return key;
}
16 changes: 14 additions & 2 deletions DAC/Sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
#include "DAC.h"
#include "..//tm4c123gh6pm.h"

unsigned char Index;
const unsigned char SineWave[16] = {4,5,6,7,7,7,6,5,4,3,2,1,1,1,2,3};

// **************Sound_Init*********************
// Initialize Systick periodic interrupts
// Also calls DAC_Init() to initialize DAC
// Input: none
// Output: none
void Sound_Init(void){

DAC_Init(); // Port B is DAC
Index = 0;
NVIC_ST_CTRL_R = 0; // disable SysTick during setup
NVIC_ST_RELOAD_R = 90909-1; // reload value for 880Hz => (1/880Hz) / (1/80Mhz)
NVIC_ST_CURRENT_R = 0; // any write to current clears it
NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF)|0x20000000; // priority 1
NVIC_ST_CTRL_R = 0x00000007; // enable with core clock and interrupts
}

// **************Sound_Tone*********************
Expand All @@ -28,6 +37,7 @@ void Sound_Init(void){
// Output: none
void Sound_Tone(unsigned long period){
// this routine sets the RELOAD and starts SysTick
NVIC_ST_RELOAD_R = period-1; // reload value
}


Expand All @@ -36,11 +46,13 @@ void Sound_Tone(unsigned long period){
// Output: none
void Sound_Off(void){
// this routine stops the sound output
DAC_Out(0);
}


// Interrupt service routine
// Executed every 12.5ns*(period)
void SysTick_Handler(void){

Index = (Index+1)&0x0F;
DAC_Out(SineWave[Index]);
}
15 changes: 15 additions & 0 deletions DAC/Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
// Daniel Valvano, Jonathan Valvano
// March 13, 2014

enum Notes {
A,
B,
C,
D,
E,
F,
G,
};

#define C 9556 // 80Mhz/(523.251*16) = 9555.6435
#define D 8513 // 80Mhz/(587.330*16) = 8513.1017
#define E 7584 // 80Mhz/(659.255*16) = 7584.3187
#define G 6378 // 80Mhz/(783.991*16) = 6577.6242

// **************Sound_Init*********************
// Initialize Systick periodic interrupts
// Also initializes DAC
Expand Down

0 comments on commit 7aa3aa7

Please sign in to comment.