Cornell University ECE 3140 - Lab 6
/
Lab6-FinalProject
Repository for ECE 3140 Final Project
main.cpp@96:93d556043569, 2019-05-12 (annotated)
- Committer:
- TSSherman98
- Date:
- Sun May 12 04:09:15 2019 +0000
- Revision:
- 96:93d556043569
- Parent:
- 95:f191a7ee705b
Commit as of 05/12/2019 at 12:09 AM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TSSherman98 | 96:93d556043569 | 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 | double offset = 65535/2; |
TSSherman98 | 95:f191a7ee705b | 14 | double amplitude = 65535/2; //this controls VOLUME |
TSSherman98 | 95:f191a7ee705b | 15 | double freq = 2000.0; //frequency in Hz --> controls TONE |
mbed_official | 88:bea4f2daa48c | 16 | |
TSSherman98 | 95:f191a7ee705b | 17 | DigitalOut led1(LED1); //Red LED |
TSSherman98 | 95:f191a7ee705b | 18 | AnalogOut aout(DAC0_OUT); //DAC0_OUT = Analog Out pin = J4-P11 |
TSSherman98 | 95:f191a7ee705b | 19 | |
TSSherman98 | 95:f191a7ee705b | 20 | /*---------------------------------------------------------------------------- |
TSSherman98 | 95:f191a7ee705b | 21 | MAIN FUNCTION - Begin Program |
TSSherman98 | 95:f191a7ee705b | 22 | *----------------------------------------------------------------------------*/ |
mbed_official | 82:abf1b1785bd7 | 23 | int main() |
mbed_official | 82:abf1b1785bd7 | 24 | { |
TSSherman98 | 95:f191a7ee705b | 25 | f = freq/1000000.0; //convert seconds-->microseconds |
TSSherman98 | 95:f191a7ee705b | 26 | Timer clock; //begin time |
TSSherman98 | 95:f191a7ee705b | 27 | clock.start(); //counts time in microseconds |
TSSherman98 | 95:f191a7ee705b | 28 | uint16_t sample; //voltage to be output |
TSSherman98 | 95:f191a7ee705b | 29 | led1 = !led1; //turn on LED to indicate operation |
TSSherman98 | 96:93d556043569 | 30 | |
TSSherman98 | 95:f191a7ee705b | 31 | while (1) { |
TSSherman98 | 96:93d556043569 | 32 | sample = (uint16_t)((amplitude)*sin(2.0*pi*f*clock.read_us())+offset); |
TSSherman98 | 95:f191a7ee705b | 33 | aout.write_u16(sample); |
Jonathan Austin |
0:2757d7abb7d9 | 34 | } |
Jonathan Austin |
0:2757d7abb7d9 | 35 | } |