Repository for ECE 3140 Final Project

Committer:
TSSherman98
Date:
Sun May 12 03:35:54 2019 +0000
Revision:
95:f191a7ee705b
Parent:
88:bea4f2daa48c
Child:
96:93d556043569
Sinusode generation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TSSherman98 95:f191a7ee705b 1 /*
TSSherman98 95:f191a7ee705b 2 ECE 3140 - Spring 2019
TSSherman98 95:f191a7ee705b 3 Lab #6 - Final Project
TSSherman98 95:f191a7ee705b 4 04//25/2019 - 05/17/2019
TSSherman98 95:f191a7ee705b 5 Nicole Lin (nl392) & Tyler Sherman (tss86)
TSSherman98 95:f191a7ee705b 6 */
Jonathan Austin 0:2757d7abb7d9 7 #include "mbed.h"
Jonathan Austin 0:2757d7abb7d9 8
TSSherman98 95:f191a7ee705b 9 /*----------------------------------------------------------------------------
TSSherman98 95:f191a7ee705b 10 GLOBAL VARIABLES
TSSherman98 95:f191a7ee705b 11 *----------------------------------------------------------------------------*/
TSSherman98 95:f191a7ee705b 12 const double pi = 3.141592653589793238462;
TSSherman98 95:f191a7ee705b 13 const double amplitude = 0.5f;
TSSherman98 95:f191a7ee705b 14 const double offset = 65535/2;
TSSherman98 95:f191a7ee705b 15 double offset = 65535/2;
TSSherman98 95:f191a7ee705b 16 double amplitude = 65535/2; //this controls VOLUME
TSSherman98 95:f191a7ee705b 17 double freq = 2000.0; //frequency in Hz --> controls TONE
mbed_official 88:bea4f2daa48c 18
TSSherman98 95:f191a7ee705b 19 DigitalOut led1(LED1); //Red LED
TSSherman98 95:f191a7ee705b 20 AnalogOut aout(DAC0_OUT); //DAC0_OUT = Analog Out pin = J4-P11
TSSherman98 95:f191a7ee705b 21
TSSherman98 95:f191a7ee705b 22 /*----------------------------------------------------------------------------
TSSherman98 95:f191a7ee705b 23 MAIN FUNCTION - Begin Program
TSSherman98 95:f191a7ee705b 24 *----------------------------------------------------------------------------*/
mbed_official 82:abf1b1785bd7 25 int main()
mbed_official 82:abf1b1785bd7 26 {
TSSherman98 95:f191a7ee705b 27 f = freq/1000000.0; //convert seconds-->microseconds
TSSherman98 95:f191a7ee705b 28 Timer clock; //begin time
TSSherman98 95:f191a7ee705b 29 clock.start(); //counts time in microseconds
TSSherman98 95:f191a7ee705b 30 uint16_t sample; //voltage to be output
TSSherman98 95:f191a7ee705b 31 led1 = !led1; //turn on LED to indicate operation
TSSherman98 95:f191a7ee705b 32
TSSherman98 95:f191a7ee705b 33 while (1) {
TSSherman98 95:f191a7ee705b 34 sample = (uint16_t)((amplitude)*sin(2.0*pi*f*clock.read_us())+offset);
TSSherman98 95:f191a7ee705b 35 aout.write_u16(sample);
Jonathan Austin 0:2757d7abb7d9 36 }
Jonathan Austin 0:2757d7abb7d9 37 }