VCO

VCO

Postby michaelmartin2758 » Fri Aug 09, 2013 11:30 pm

hi

I wonder if anyone can help please
I'm using the VCO sketch.(arduino uno) When it loads it immediately puts out a sine wave at 554hz without a control voltage attached to the left channel input. when i send a voltage to the input and change the voltage it changes the frequency for a second then settles back to 554hz. I have tried both libraries.

ps the control voltage is being sent from another DAC /buffered using a separate Arduino uno

pps all other sketches work fine

ppps What did the zero say to the number eight ? ....................Nice belt

thanks for reading
michaelmartin2758
 
Posts: 4
Joined: Fri Aug 09, 2013 10:56 pm

Re: VCO

Postby guest » Sat Aug 10, 2013 12:50 pm

its actually a hardware thing. the input is AC-coupled, so it always drifts back to 0. apply your signal at the IN_R or IN_L header, and it should work fine. but, be very sure that you are only applying a signal between 0V and 3.3V. what is the signal coming from?
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: VCO

Postby michaelmartin2758 » Sun Aug 11, 2013 6:35 am

thanks for that ...........i should have known it

i obviously had a bit of a brain freeze but i'm very old

everything's working now
i'm using a separate dac mcp4728 to generate control voltage to feed into the shield.......I've restricted the voltage with a diode circuit stuff ............so nothing above 3.2v is getting near it ......

thank you again
michaelmartin2758
 
Posts: 4
Joined: Fri Aug 09, 2013 10:56 pm

Re: VCO

Postby guest » Sun Aug 11, 2013 1:35 pm

awesome, glad to hear its working. and good idea with the diode protection.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: VCO

Postby michaelmartin2758 » Tue Aug 27, 2013 9:24 am

Thanks for all your help so far

first things first

Why was the 6 afraid of the 7
Because 7 8 9



I'm working on a wave switching vco and i've managed to get it to work with the following code.
i'm now trying something a bit more adventurous.
i have attached a 4ch DAC to the Spi
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en541737
using this library
http://neuroelec.com/2011/02/mcp4728-library-for-arduino/

Every thing is sort of ok
if i send a value to the mcp4728 in the main loop it works .....on sketch load
if i send a value from the ISR to the main loop it works ....on sketch load
but if i try changing that value in the isr .....say from the counter it doesn't update the mcp4728

I know its a bit off topic
but i'm wondering if anyone can point me in the right direction

Code: Select all

// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1kHz sample rate
#define ADCS 0 // dont use ADCs
#define ADCHPD 1 // high pass filter disabled -> DC coupled



// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>
#include "mcp4728.h"    // Mcp4728
 mcp4728 dac = mcp4728(1); // instantiate mcp4728 object, Device ID = 1



// create data variables for audio transfer
// even though there is no input needed, the codec requires stereo data
int left_in = 0; // in from codec (LINE_IN)
int right_in = 0;
int left_out = 0; // out to codec (HP_OUT)
int right_out = 0;

int *selection; //Array selection
int arraypointer = 0; //array pointer
unsigned long counter = 0; //counter for wave switcher
unsigned long mcpVoltOut = 4000;




//Wave 1
  PROGMEM prog_int16_t wave1 [1024]  = {

1105, 1401, 1696, 1992, 2288, 2583, 2879, 3128, 3289, 3451, 3613, 3775, 3936, 4098, 4246, 4387, 4529, 4670, 4812, 4954, 5093, 5197, 5302, 5406, 5510, 5614, 5718, 5895, 6179, 6464, 6749, 7033, 7318, 7603, 7988, 8406, 8825, 9243, 9661, 10079, 10479, 10721, 10963, 11205, 11447, 11688, 11930, 12240, 12631, 13021, 13412, 13803, 14194, 14585, 15067, 15571, 16076, 16580, 17085, 17589, 18039, 18193, 18347, 18501, 18655, 18809, 18963, 19042, 19049, 19055, 19062, 19069, 19075, 19082, 19109, 19140, 19170, 19201, 19231, 19262, 19258, 19121, 18985, 18849, 18712, 18576, 18440, 18219, 17933, 17646, 17359, 17072, 16785, 16498, 16451, 16428, 16404, 16381, 16357, 16334, 16272, 16101, 15930, 15759, 15589, 15418, 15247, 14947, 14565, 14183, 13800, 13418, 13036, 12654, 12417, 12185, 11954, 11723, 11491, 11260, 11073, 10984, 10895, 10805, 10716, 10627, 10538, 10452, 10367, 10282, 10198, 10113, 10029, 9942, 9693, 9445, 9196, 8947, 8699, 8450, 8209, 7981, 7753, 7526, 7298, 7070, 6843, 6701, 6593, 6486, 6378, 6271, 6163, 6073, 6234, 6394, 6555, 6715, 6876, 7037, 7207, 7393, 7579, 7764, 7950, 8135, 8321, 8413, 8476, 8539, 8602, 8665, 8728, 8790, 8846, 8902, 8958, 9014, 9070, 9125, 9276, 9534, 9792, 10050, 10308, 10565, 10823, 11101, 11384, 11667, 11949, 12232, 12514, 12772, 12910, 13047, 13185, 13323, 13460, 13598, 13648, 13616, 13585, 13554, 13522, 13491, 13459, 13532, 13621, 13709, 13798, 13886, 13974, 14078, 14237, 14395, 14554, 14712, 14870, 15029, 15176, 15314, 15453, 15591, 15730, 15868, 16007, 16154, 16302, 16450, 16598, 16746, 16894, 16990, 16947, 16903, 16860, 16817, 16774, 16730, 16637, 16514, 16391, 16269, 16146, 16023, 15900, 15578, 15250, 14923, 14595, 14268, 13940, 13553, 13043, 12532, 12021, 11511, 11000, 10490, 9904, 9281, 8659, 8037, 7415, 6792, 6172, 5615, 5058, 4500, 3943, 3386, 2829, 2317, 1879, 1441, 1003, 565, 128, -310, -519, -643, -766, -890, -1013, -1137, -1238, -1082, -925, -769, -612, -456, -299, -144, 8, 161, 313, 466, 618, 771, 844, 894, 944, 995, 1045, 1095, 1158, 1304, 1449, 1595, 1741, 1886, 2032, 2139, 2204, 2270, 2336, 2401, 2467, 2532, 2379, 2182, 1985, 1788, 1590, 1393, 1199, 1022, 845, 667, 490, 313, 136, -61, -276, -490, -704, -918, -1132, -1346, -1573, -1802, -2031, -2259, -2488, -2717, -2894, -2902, -2911, -2919, -2927, -2936, -2944, -2852, -2689, -2526, -2363, -2199, -2036, -1873, -1757, -1644, -1530, -1417, -1304, -1191, -1108, -1096, -1085, -1074, -1063, -1051, -1040, -948, -809, -670, -531, -392, -254, -115, 518, 1157, 1796, 2435, 3074, 3713, 4236, 4533, 4831, 5128, 5426, 5723, 6020, 5867, 5511, 5155, 4798, 4442, 4085, 3733, 3480, 3227, 2974, 2721, 2468, 2215, 2078, 2122, 2166, 2210, 2253, 2297, 2341, 2409, 2485, 2561, 2637, 2713, 2789, 2818, 2380, 1943, 1506, 1069, 632, 194, -366, -1081, -1797, -2513, -3228, -3944, -4659, -4952, -5133, -5314, -5496, -5677, -5859, -5931, -5349, -4767, -4185, -3603, -3021, -2439, -2010, -1737, -1464, -1191, -919, -646, -373, -724, -1191, -1657, -2123, -2589, -3055, -3571, -4290, -5010, -5729, -6449, -7169, -7888, -8441, -8857, -9272, -9687, -10102, -10518, -10933, -10742, -10481, -10221, -9960, -9700, -9439, -9238, -9219, -9200, -9181, -9162, -9143, -9124, -9828, -11016, -12205, -13394, -14582, -15771, -16960, -18127, -19293, -20459, -21625, -22792, -23958, -24556, -23823, -23091, -22358, -21626, -20893, -20161, -19332, -18451, -17570, -16689, -15808, -14927, -14046, -13680, -13314, -12947, -12581, -12215, -11848, -11610, -11608, -11606, -11604, -11601, -11599, -11597, -12075, -12756, -13437, -14118, -14799, -15480, -16068, -14973, -13879, -12785, -11690, -10596, -9502, -8273, -6844, -5415, -3986, -2558, -1129, 300, -293, -1546, -2799, -4052, -5305, -6558, -7789, -8830, -9872, -10914, -11956, -12997, -14039, -14119, -13046, -11974, -10901, -9829, -8756, -7684, -6779, -5914, -5049, -4185, -3320, -2455, -1760, -1979, -2198, -2418, -2637, -2856, -3075, -3112, -2974, -2835, -2696, -2557, -2418, -2280, -1586, -800, -14, 772, 1558, 2343, 3010, 3222, 3434, 3647, 3859, 4071, 4283, 4437, 4543, 4649, 4756, 4862, 4969, 5075, 4810, 4508, 4206, 3904, 3602, 3301, 2993, 2668, 2344, 2019, 1695, 1370, 1046, 1105, 1408, 1711, 2014, 2317, 2620, 2923, 2684, 2424, 2164, 1904, 1644, 1384, 1067, 626, 184, -257, -699, -1140, -1582, -1645, -1517, -1389, -1261, -1133, -1005, -875, -602, -328, -55, 219, 492, 766, 908, 822, 736, 650, 564, 478, 393, 329, 275, 221, 167, 113, 59, 36, 446, 856, 1266, 1675, 2085, 2495, 2928, 3394, 3860, 4325, 4791, 5257, 5722, 5804, 5769, 5734, 5699, 5664, 5630, 5581, 5432, 5283, 5134, 4984, 4835, 4686, 4688, 4861, 5033, 5206, 5379, 5552, 5725, 5823, 5904, 5986, 6068, 6149, 6231, 6274, 6130, 5986, 5841, 5697, 5553, 5409, 5317, 5272, 5228, 5184, 5140, 5096, 5052, 4835, 4592, 4349, 4107, 3864, 3621, 3471, 3645, 3819, 3993, 4167, 4342, 4516, 4912, 5474, 6036, 6598, 7160, 7723, 8285, 8026, 7698, 7371, 7043, 6716, 6388, 5924, 5095, 4266, 3437, 2608, 1780, 951, 513, 310, 107, -95, -298, -501, -704, -556, -400, -243, -87, 70, 226, 285, 140, -4, -148, -293, -437, -582, -813, -1087, -1361, -1634, -1908, -2182, -2457, -2815, -3173, -3530, -3888, -4245, -4603, -4864, -4966, -5069, -5171, -5273, -5375, -5478, -5342, -5118, -4894, -4670, -4446, -4222, -4052, -4516, -4980, -5444, -5907, -6371, -6835, -7557, -8623, -9689, -10755, -11821, -12887, -13953, -14360, -14582, -14804, -15026, -15248, -15470, -15651, -15565, -15478, -15392, -15306, -15219, -15133, -15432, -16147, -16862, -17577, -18292, -19007, -19722, -20197, -20624, -21052, -21479, -21906, -22333, -22565, -21925, -21284, -20644, -20004, -19364, -18723, -18273, -17989, -17704, -17420, -17135, -16851, -16567, -16869, -17248, -17627, -18006, -18385, -18764, -19014, -18844, -18673, -18503, -18333, -18162, -17992, -17721, -17378, -17036, -16693, -16351, -16008, -15666, -15487, -15319, -15151, -14982, -14814, -14646, -14489, -14358, -14226, -14095, -13963, -13832, -13701, -13852, -14165, -14478, -14790, -15103, -15415, -15728, -15897, -16065, -16232, -16399, -16567, -16734, -16716, -16337, -15958, -15579, -15199, -14820, -14441, -14127, -13841, -13556, -13271, -12986, -12701, -12425, -12371, -12317, -12263, -12209, -12156, -12102, -11947, -11637, -11326, -11015, -10704, -10393, -10083, -9647, -9168, -8689, -8210, -7730, -7251, -6787, -6468, -6150, -5832, -5513, -5195, -4876, -4627, -4465, -4303, -4140, -3978, -3816, -3654, -3644, -3673, -3703, -3732, -3762, -3791, -3810, -3765, -3720, -3675, -3631, -3586, -3541, -3612, -3802, -3992, -4182, -4372, -4562, -4752, -4913, -5068, -5224, -5379, -5535, -5690, -5734, -5321, -4908, -4496, -4083, -3670, -3257, -2979, -2814, -2648, -2482, -2317, -2151, -1986, -2188, -2433, -2677, -2922, -3166, -3411, -3582, -3530, -3477, -3425, -3373, -3321, -3269, -3157, -3007, -2856, -2705, -2555, -2404, -2253, -2163, -2076, -1989, -1902, -1816, -1729, -1559, -1198, -836, -475, -113, 248, 610, 819, 947, 1075, 1202, 1330, 1458,

};


//Wave 2
 PROGMEM prog_int16_t wave2 [1024]  = {

3144, 3388, 3631, 3875, 4118, 4362, 4606, 4848, 5089, 5330, 5571, 5812, 6053, 6287, 6472, 6657, 6842, 7027, 7211, 7396, 7542, 7669, 7796, 7922, 8049, 8176, 8307, 8451, 8594, 8737, 8881, 9024, 9168, 9270, 9362, 9454, 9547, 9639, 9731, 9852, 10025, 10198, 10371, 10544, 10716, 10889, 11162, 11444, 11726, 12008, 12289, 12571, 12840, 13096, 13351, 13606, 13862, 14117, 14367, 14469, 14572, 14674, 14777, 14879, 14982, 15094, 15213, 15332, 15451, 15570, 15689, 15811, 15948, 16085, 16222, 16360, 16497, 16634, 16495, 16247, 15999, 15751, 15503, 15255, 14914, 14331, 13747, 13164, 12580, 11996, 11413, 10809, 10201, 9593, 8985, 8377, 7769, 7242, 6837, 6432, 6027, 5622, 5218, 4813, 4494, 4179, 3865, 3550, 3235, 2921, 2672, 2485, 2297, 2110, 1923, 1736, 1587, 1915, 2243, 2570, 2898, 3225, 3553, 4019, 4564, 5109, 5654, 6199, 6745, 7268, 7704, 8139, 8574, 9010, 9445, 9880, 10149, 10362, 10576, 10790, 11004, 11218, 11345, 11284, 11223, 11162, 11101, 11040, 10979, 10859, 10731, 10603, 10475, 10347, 10218, 9999, 9659, 9320, 8981, 8641, 8302, 7963, 7418, 6872, 6326, 5780, 5234, 4688, 4297, 4030, 3764, 3498, 3231, 2965, 2706, 2502, 2298, 2093, 1889, 1685, 1481, 1104, 644, 184, -276, -737, -1197, -1639, -2022, -2405, -2788, -3171, -3554, -3937, -4246, -4534, -4823, -5112, -5401, -5690, -6008, -6380, -6751, -7123, -7495, -7867, -8238, -8480, -8710, -8939, -9168, -9398, -9627, -9629, -9376, -9123, -8870, -8617, -8364, -8111, -7888, -7665, -7441, -7218, -6995, -6772, -6680, -6679, -6678, -6677, -6677, -6676, -6668, -6624, -6579, -6535, -6490, -6446, -6402, -6552, -6782, -7012, -7242, -7473, -7703, -8058, -8752, -9446, -10140, -10834, -11528, -12222, -13274, -14399, -15524, -16649, -17774, -18899, -20030, -21172, -22313, -23454, -24595, -25736, -26877, -27434, -27959, -28484, -29009, -29535, -30060, -30285, -30222, -30159, -30096, -30033, -29969, -29895, -29670, -29446, -29221, -28996, -28771, -28547, -28139, -27623, -27107, -26590, -26074, -25558, -24923, -23775, -22626, -21478, -20330, -19182, -18033, -16851, -15657, -14464, -13270, -12076, -10882, -9884, -9323, -8761, -8200, -7639, -7078, -6517, -6454, -6468, -6481, -6494, -6508, -6521, -6578, -6692, -6807, -6921, -7036, -7151, -7265, -7242, -7217, -7191, -7166, -7141, -7116, -7193, -7354, -7515, -7676, -7837, -7998, -8174, -8482, -8790, -9098, -9406, -9714, -10022, -10111, -10092, -10073, -10053, -10034, -10015, -9893, -9420, -8948, -8476, -8004, -7532, -7059, -6548, -6025, -5503, -4981, -4458, -3936, -3446, -3017, -2587, -2158, -1729, -1300, -871, -438, -5, 427, 860, 1293, 1726, 2042, 2224, 2406, 2588, 2770, 2952, 3125, 2944, 2763, 2582, 2401, 2220, 2039, 1908, 1813, 1717, 1621, 1525, 1430, 1368, 1508, 1647, 1787, 1927, 2067, 2206, 2126, 1954, 1782, 1609, 1437, 1265, 1026, 600, 174, -251, -677, -1103, -1528, -1597, -1589, -1581, -1573, -1565, -1557, -1407, -1029, -651, -273, 105, 483, 861, 1257, 1654, 2051, 2449, 2846, 3243, 3548, 3762, 3976, 4189, 4403, 4616, 4815, 4785, 4755, 4725, 4696, 4666, 4636, 4592, 4540, 4488, 4436, 4384, 4332, 4360, 4748, 5135, 5523, 5910, 6298, 6685, 7065, 7442, 7819, 8197, 8574, 8951, 9224, 9258, 9292, 9326, 9360, 9394, 9428, 9577, 9744, 9911, 10078, 10245, 10412, 10721, 11225, 11730, 12234, 12739, 13243, 13747, 14262, 14777, 15293, 15808, 16323, 16838, 17108, 17170, 17232, 17294, 17357, 17419, 17448, 17178, 16908, 16638, 16368, 16098, 15828, 15120, 14186, 13253, 12319, 11385, 10452, 9529, 8647, 7764, 6882, 6000, 5117, 4235, 3657, 3166, 2675, 2184, 1692, 1201, 692, 148, -396, -939, -1483, -2027, -2571, -3196, -3830, -4464, -5098, -5732, -6366, -6747, -6829, -6911, -6993, -7075, -7157, -7224, -6490, -5756, -5022, -4289, -3555, -2821, -2330, -2016, -1702, -1388, -1074, -759, -533, -850, -1167, -1484, -1802, -2119, -2436, -2838, -3276, -3714, -4152, -4590, -5028, -5413, -5643, -5873, -6104, -6334, -6565, -6795, -7151, -7536, -7920, -8305, -8689, -9073, -9455, -9833, -10211, -10588, -10966, -11344, -11721, -11788, -11834, -11879, -11925, -11971, -12017, -11892, -11596, -11300, -11004, -10708, -10412, -10101, -9554, -9007, -8460, -7913, -7366, -6818, -6296, -5789, -5282, -4776, -4269, -3762, -3286, -2955, -2625, -2294, -1964, -1633, -1302, -1072, -877, -683, -488, -293, -99, 84, 239, 394, 549, 704, 859, 1014, 797, 518, 238, -41, -321, -600, -849, -1054, -1258, -1463, -1668, -1873, -2077, -1938, -1789, -1641, -1492, -1343, -1195, -1125, -1122, -1120, -1117, -1115, -1112, -1140, -1450, -1761, -2072, -2383, -2694, -3004, -3198, -3329, -3461, -3592, -3724, -3855, -3964, -3989, -4015, -4040, -4066, -4091, -4117, -4281, -4485, -4690, -4895, -5099, -5304, -5512, -5728, -5944, -6161, -6377, -6593, -6809, -7040, -7272, -7505, -7738, -7970, -8203, -8338, -8354, -8370, -8387, -8403, -8420, -8434, -8259, -8085, -7911, -7736, -7562, -7388, -7073, -6652, -6232, -5812, -5392, -4972, -4528, -3929, -3330, -2731, -2132, -1533, -934, -307, 331, 969, 1608, 2246, 2884, 3491, 4004, 4516, 5028, 5541, 6054, 6566, 6977, 7364, 7752, 8139, 8526, 8914, 9268, 9566, 9864, 10162, 10460, 10758, 11056, 11129, 11185, 11242, 11298, 11354, 11410, 11329, 11104, 10879, 10655, 10430, 10206, 9984, 9818, 9653, 9487, 9321, 9156, 8990, 8952, 8995, 9038, 9082, 9125, 9168, 9241, 9463, 9685, 9907, 10128, 10350, 10572, 10790, 11006, 11223, 11440, 11656, 11873, 12052, 12139, 12226, 12313, 12400, 12487, 12574, 12663, 12752, 12841, 12930, 13020, 13109, 13133, 13065, 12996, 12928, 12859, 12791, 12722, 12517, 12308, 12098, 11889, 11680, 11470, 11167, 10782, 10396, 10010, 9624, 9238, 8840, 8319, 7797, 7276, 6755, 6233, 5712, 5260, 4846, 4432, 4019, 3605, 3191, 2843, 2750, 2656, 2562, 2468, 2374, 2281, 2316, 2391, 2465, 2539, 2614, 2688, 2739, 2740, 2742, 2743, 2745, 2746, 2747, 2649, 2537, 2425, 2314, 2202, 2090, 1980, 1870, 1761, 1651, 1542, 1433, 1324, 1289, 1255, 1220, 1186, 1151, 1117, 1059, 983, 906, 830, 754, 678, 566, 205, -156, -517, -878, -1239, -1600, -1883, -2130, -2377, -2625, -2872, -3119, -3264, -3092, -2921, -2750, -2578, -2407, -2235, -2093, -1957, -1822, -1686, -1551, -1415, -1372, -1489, -1606, -1723, -1840, -1958, -2075, -2123, -2165, -2208, -2250, -2293, -2336, -2374, -2407, -2440, -2473, -2506, -2540, -2586, -2909, -3232, -3556, -3879, -4202, -4526, -4914, -5345, -5776, -6206, -6637, -7068, -7468, -7713, -7958, -8203, -8447, -8692, -8937, -8992, -8975, -8957, -8940, -8922, -8905, -8894, -8899, -8905, -8910, -8915, -8921, -8926, -8904, -8877, -8850, -8823, -8796, -8770, -8698, -8561, -8424, -8287, -8150, -8013, -7876, -7577, -7272, -6967, -6662, -6357, -6052, -5765, -5496, -5226, -4956, -4686, -4417, -4176, -4253, -4330, -4407, -4484, -4561, -4639, -4796, -4999, -5202, -5405, -5608, -5811, -5960, -5898, -5837, -5775, -5713, -5652, -5590, -5425, -5227, -5029, -4831, -4633, -4435, -4276, -4199, -4122, -4045, -3968, -3891, -3814, -3683, -3544, -3405, -3267, -3128, -2989, -2775, -2465, -2155, -1845, -1535, -1225,

};

//Wave 3
PROGMEM prog_int16_t wave3 [1024]  = {
 
1112, 1448, 1784, 2120, 2455, 2791, 3127, 3401, 3561, 3721, 3880, 4040, 4199, 4359, 4404, 4400, 4396, 4391, 4387, 4383, 4376, 4311, 4246, 4181, 4116, 4051, 3986, 4079, 4405, 4732, 5058, 5384, 5711, 6037, 6273, 6479, 6685, 6891, 7097, 7303, 7460, 7196, 6933, 6669, 6405, 6141, 5878, 5720, 5690, 5661, 5631, 5601, 5571, 5541, 5856, 6255, 6654, 7053, 7453, 7852, 8202, 8293, 8383, 8473, 8563, 8654, 8744, 8767, 8724, 8682, 8640, 8598, 8555, 8513, 8635, 8785, 8934, 9084, 9233, 9383, 9529, 9664, 9798, 9933, 10067, 10202, 10336, 10458, 10569, 10681, 10792, 10903, 11015, 11126, 11148, 11162, 11175, 11189, 11203, 11216, 11183, 11017, 10850, 10684, 10517, 10351, 10185, 10044, 9921, 9797, 9673, 9549, 9425, 9302, 9316, 9335, 9355, 9374, 9394, 9413, 9387, 9260, 9134, 9007, 8880, 8753, 8627, 8432, 8204, 7975, 7746, 7518, 7289, 7063, 7057, 7051, 7045, 7039, 7034, 7028, 7074, 7210, 7347, 7484, 7621, 7758, 7894, 7935, 7937, 7940, 7942, 7944, 7947, 7939, 7782, 7626, 7469, 7313, 7156, 7000, 6898, 6872, 6846, 6820, 6795, 6769, 6743, 6916, 7149, 7383, 7616, 7850, 8083, 8299, 8380, 8461, 8542, 8623, 8704, 8785, 8768, 8641, 8514, 8387, 8259, 8132, 8005, 7899, 7798, 7697, 7596, 7495, 7394, 7323, 7394, 7465, 7537, 7608, 7679, 7751, 7772, 7748, 7723, 7698, 7674, 7649, 7625, 7407, 7160, 6914, 6667, 6421, 6174, 5916, 5616, 5316, 5016, 4716, 4416, 4117, 3920, 3801, 3682, 3563, 3444, 3324, 3205, 3251, 3310, 3369, 3428, 3487, 3546, 3543, 3372, 3202, 3032, 2861, 2691, 2521, 2253, 1927, 1601, 1275, 949, 623, 297, 230, 169, 109, 48, -13, -73, -51, 144, 339, 533, 728, 923, 1118, 1234, 1313, 1392, 1470, 1549, 1627, 1704, 1688, 1672, 1656, 1640, 1623, 1607, 1685, 1916, 2147, 2378, 2608, 2840, 3070, 3507, 4021, 4535, 5048, 5562, 6076, 6572, 6862, 7152, 7443, 7733, 8023, 8314, 8428, 8307, 8186, 8065, 7944, 7823, 7702, 7436, 7130, 6824, 6517, 6211, 5905, 5578, 5111, 4644, 4178, 3711, 3245, 2778, 2142, 1323, 504, -315, -1134, -1953, -2772, -3686, -4618, -5550, -6482, -7414, -8347, -9232, -9909, -10586, -11262, -11939, -12615, -13292, -13744, -13998, -14252, -14506, -14761, -15015, -15269, -15064, -14798, -14531, -14265, -13999, -13733, -13413, -12919, -12425, -11931, -11437, -10943, -10449, -9968, -9497, -9025, -8553, -8082, -7610, -7139, -6689, -6240, -5791, -5342, -4893, -4445, -4021, -3662, -3302, -2943, -2583, -2224, -1864, -1711, -1676, -1640, -1605, -1570, -1534, -1499, -1705, -1914, -2123, -2331, -2540, -2749, -2921, -3022, -3123, -3223, -3324, -3424, -3525, -3569, -3588, -3607, -3625, -3644, -3663, -3681, -3690, -3699, -3709, -3718, -3727, -3736, -3763, -3815, -3868, -3920, -3973, -4025, -4078, -4103, -4118, -4133, -4148, -4163, -4178, -4186, -4132, -4078, -4023, -3969, -3915, -3860, -3874, -3975, -4075, -4176, -4276, -4377, -4477, -4545, -4604, -4663, -4722, -4781, -4840, -4878, -4796, -4713, -4630, -4547, -4464, -4382, -4215, -3962, -3710, -3457, -3204, -2952, -2699, -2410, -2114, -1819, -1523, -1227, -931, -660, -492, -323, -155, 14, 182, 351, 536, 736, 935, 1135, 1334, 1533, 1733, 2076, 2436, 2796, 3156, 3516, 3876, 4189, 4362, 4535, 4708, 4880, 5053, 5226, 5196, 5030, 4864, 4697, 4531, 4365, 4199, 4150, 4108, 4065, 4023, 3980, 3938, 3885, 3807, 3729, 3652, 3574, 3496, 3419, 2995, 2384, 1773, 1163, 552, -59, -670, -1600, -2531, -3462, -4393, -5323, -6254, -7200, -8173, -9147, -10120, -11093, -12067, -13040, -13976, -14895, -15815, -16734, -17654, -18573, -19470, -19954, -20439, -20923, -21408, -21892, -22376, -22616, -22494, -22372, -22250, -22129, -22007, -21885, -21524, -21084, -20645, -20206, -19767, -19328, -18868, -18235, -17601, -16968, -16334, -15701, -15067, -14335, -13485, -12635, -11785, -10935, -10086, -9236, -8752, -8357, -7961, -7566, -7170, -6775, -6506, -6917, -7328, -7739, -8150, -8561, -8972, -9438, -9956, -10475, -10993, -11512, -12030, -12549, -12583, -12537, -12491, -12445, -12399, -12353, -12308, -12271, -12233, -12195, -12157, -12120, -12082, -12153, -12309, -12466, -12622, -12778, -12934, -13091, -12730, -12318, -11906, -11494, -11082, -10670, -10143, -9294, -8444, -7594, -6744, -5895, -5045, -4286, -3586, -2886, -2186, -1485, -785, -85, 53, 169, 284, 400, 516, 631, 595, 223, -149, -521, -893, -1265, -1637, -1800, -1858, -1915, -1973, -2030, -2088, -2138, -1629, -1121, -613, -105, 404, 912, 1173, 1003, 834, 664, 494, 325, 155, -540, -1444, -2348, -3252, -4156, -5060, -5905, -5912, -5919, -5926, -5933, -5940, -5947, -5730, -5198, -4665, -4133, -3601, -3069, -2537, -2553, -2735, -2917, -3100, -3282, -3465, -3665, -4000, -4335, -4670, -5005, -5340, -5675, -5835, -5799, -5762, -5725, -5689, -5652, -5615, -5246, -4804, -4362, -3919, -3477, -3035, -2544, -1816, -1088, -361, 367, 1095, 1823, 2302, 2553, 2804, 3054, 3305, 3556, 3806, 3429, 2959, 2489, 2018, 1548, 1078, 750, 924, 1098, 1272, 1446, 1620, 1793, 2510, 3634, 4757, 5880, 7003, 8126, 9249, 9597, 9880, 10163, 10446, 10730, 11013, 11091, 10625, 10159, 9694, 9228, 8762, 8296, 8379, 8791, 9204, 9617, 10029, 10442, 10854, 12014, 13193, 14371, 15550, 16729, 17908, 18710, 18734, 18758, 18782, 18806, 18829, 18853, 17964, 16638, 15312, 13986, 12660, 11334, 10026, 9354, 8682, 8009, 7337, 6665, 5993, 5683, 5968, 6254, 6540, 6826, 7112, 7398, 7507, 7551, 7595, 7639, 7682, 7726, 7734, 7319, 6904, 6489, 6074, 5659, 5244, 4802, 4322, 3843, 3364, 2885, 2405, 1926, 2071, 2392, 2713, 3033, 3354, 3675, 4075, 4999, 5923, 6846, 7770, 8694, 9618, 9922, 9559, 9196, 8832, 8469, 8106, 7743, 6317, 4677, 3037, 1397, -242, -1882, -3256, -3437, -3618, -3800, -3981, -4163, -4344, -3990, -3167, -2344, -1522, -699, 124, 946, 534, -40, -614, -1188, -1762, -2336, -2940, -3639, -4339, -5038, -5738, -6437, -7137, -7212, -6846, -6479, -6112, -5746, -5379, -5012, -4270, -3502, -2735, -1967, -1199, -431, 239, 667, 1095, 1523, 1951, 2379, 2807, 2859, 2697, 2535, 2373, 2211, 2049, 1887, 1369, 847, 325, -198, -720, -1242, -1522, -1329, -1137, -944, -751, -558, -365, 58, 585, 1113, 1640, 2167, 2694, 3178, 2614, 2050, 1487, 923, 359, -205, -859, -1653, -2447, -3241, -4035, -4829, -5623, -5780, -5715, -5650, -5585, -5520, -5455, -5350, -4859, -4368, -3877, -3386, -2895, -2404, -2166, -2247, -2328, -2409, -2490, -2571, -2652, -3167, -3795, -4423, -5052, -5680, -6308, -6855, -6921, -6987, -7053, -7118, -7184, -7250, -6951, -6279, -5607, -4935, -4263, -3592, -2920, -2626, -2402, -2177, -1953, -1729, -1504, -1431, -1975, -2520, -3064, -3609, -4154, -4698, -5097, -5374, -5652, -5930, -6207, -6485, -6762, -6391, -5946, -5500, -5055, -4609, -4164, -3733, -3347, -2960, -2574, -2187, -1801, -1414, -1443, -1750, -2058, -2365, -2672, -2980, -3287, -3719, -4158, -4597, -5036, -5475, -5914, -6083, -5618, -5154, -4690, -4226, -3762, -3298, -2829, -2357, -1886, -1414, -943, -1297,

};

//Wave 4
PROGMEM prog_int16_t wave4 [1024]  = {
1381, 1173, 964, 756, 548, 339, 143, -16, -176, -336, -495, -655, -621, -388, -156, 76, 308, 541, 761, 976, 1192, 1407, 1623, 1838, 1754, 1666, 1578, 1490, 1402, 1295, 1127, 959, 791, 622, 454, 390, 436, 482, 529, 575, 621, 887, 1234, 1581, 1928, 2275, 2622, 2808, 2991, 3173, 3356, 3538, 3667, 3612, 3557, 3502, 3447, 3392, 3523, 3860, 4198, 4536, 4873, 5211, 5791, 6465, 7139, 7813, 8487, 9161, 9536, 9900, 10264, 10628, 10992, 11295, 11372, 11449, 11526, 11603, 11680, 11772, 11880, 11988, 12096, 12204, 12313, 12413, 12509, 12606, 12702, 12799, 12895, 12922, 12945, 12968, 12990, 13013, 12990, 12783, 12577, 12371, 12164, 11958, 11715, 11426, 11138, 10850, 10562, 10274, 10187, 10188, 10188, 10189, 10189, 10190, 10221, 10254, 10287, 10320, 10353, 10336, 10108, 9880, 9653, 9425, 9197, 8960, 8711, 8461, 8212, 7962, 7712, 7591, 7528, 7464, 7401, 7338, 7275, 7310, 7352, 7394, 7436, 7478, 7496, 7405, 7315, 7225, 7134, 7044, 6895, 6668, 6440, 6213, 5985, 5758, 5643, 5583, 5523, 5464, 5404, 5344, 5359, 5380, 5402, 5423, 5444, 5425, 5207, 4989, 4771, 4553, 4334, 4070, 3742, 3413, 3084, 2756, 2427, 2143, 1881, 1619, 1357, 1096, 834, 585, 338, 91, -157, -404, -622, -682, -743, -803, -864, -924, -922, -829, -736, -643, -550, -457, -408, -381, -355, -328, -302, -275, -118, 55, 227, 399, 571, 758, 1032, 1307, 1581, 1855, 2130, 2331, 2420, 2510, 2599, 2688, 2778, 2773, 2715, 2657, 2599, 2542, 2484, 2367, 2242, 2118, 1993, 1869, 1748, 1657, 1565, 1474, 1382, 1291, 1258, 1319, 1380, 1441, 1502, 1563, 1600, 1623, 1646, 1669, 1691, 1714, 1667, 1611, 1555, 1498, 1442, 1408, 1531, 1654, 1777, 1900, 2022, 2177, 2385, 2593, 2801, 3009, 3217, 3350, 3437, 3524, 3611, 3698, 3785, 3812, 3829, 3846, 3863, 3880, 3897, 3920, 3943, 3966, 3989, 4012, 4067, 4178, 4290, 4401, 4513, 4624, 4747, 4878, 5008, 5138, 5269, 5399, 5396, 5371, 5345, 5319, 5294, 5265, 5212, 5159, 5105, 5052, 4999, 4984, 5041, 5098, 5155, 5212, 5269, 5306, 5328, 5350, 5373, 5395, 5418, 5346, 5257, 5168, 5079, 4990, 4907, 4876, 4846, 4816, 4786, 4755, 4777, 4899, 5021, 5144, 5266, 5388, 5532, 5691, 5849, 6008, 6167, 6326, 6444, 6553, 6662, 6772, 6881, 6989, 7081, 7172, 7264, 7356, 7447, 7551, 7679, 7806, 7934, 8062, 8190, 8313, 8433, 8552, 8672, 8792, 8912, 8987, 9052, 9117, 9183, 9248, 9310, 9327, 9344, 9362, 9379, 9396, 9409, 9415, 9420, 9426, 9431, 9436, 9464, 9510, 9555, 9601, 9646, 9692, 9719, 9742, 9764, 9787, 9810, 9828, 9767, 9705, 9644, 9583, 9521, 9477, 9472, 9467, 9462, 9457, 9452, 9496, 9581, 9666, 9751, 9836, 9921, 10012, 10105, 10198, 10291, 10383, 10479, 10620, 10762, 10904, 11046, 11187, 11334, 11491, 11649, 11806, 11964, 12121, 12235, 12311, 12387, 12462, 12538, 12614, 12564, 12480, 12396, 12311, 12227, 12134, 11806, 11478, 11150, 10822, 10494, 10087, 9478, 8870, 8261, 7652, 7043, 6352, 5586, 4821, 4055, 3290, 2524, 1839, 1176, 513, -150, -812, -1469, -1868, -2267, -2666, -3065, -3464, -3810, -4013, -4217, -4420, -4623, -4826, -4891, -4826, -4762, -4697, -4632, -4568, -4222, -3789, -3357, -2925, -2492, -2058, -1512, -966, -420, 127, 673, 1185, 1601, 2016, 2431, 2847, 3262, 3552, 3719, 3887, 4055, 4222, 4390, 4384, 4322, 4261, 4199, 4137, 4075, 3915, 3755, 3594, 3434, 3274, 3113, 2950, 2787, 2624, 2462, 2299, 2104, 1878, 1651, 1424, 1197, 970, 557, 78, -400, -878, -1356, -1834, -2262, -2689, -3117, -3544, -3971, -4327, -4451, -4576, -4700, -4825, -4950, -5104, -5290, -5477, -5663, -5849, -6035, -6343, -6696, -7048, -7400, -7753, -8105, -8147, -8182, -8218, -8253, -8288, -8195, -7664, -7133, -6602, -6071, -5540, -5043, -4584, -4125, -3666, -3206, -2747, -2510, -2357, -2205, -2053, -1901, -1749, -1484, -1215, -946, -677, -408, -149, 78, 304, 530, 757, 983, 1166, 1299, 1432, 1565, 1698, 1831, 1726, 1526, 1325, 1124, 923, 722, -214, -1183, -2151, -3119, -4088, -5059, -6042, -7024, -8007, -8990, -9972, -10772, -11351, -11929, -12507, -13086, -13664, -14486, -15414, -16342, -17269, -18197, -19124, -20344, -21579, -22815, -24051, -25287, -26401, -27008, -27615, -28222, -28829, -29436, -29658, -29390, -29122, -28855, -28587, -28320, -27680, -26871, -26062, -25253, -24444, -23635, -22677, -21708, -20739, -19771, -18802, -17846, -16947, -16049, -15150, -14252, -13353, -12466, -11594, -10723, -9851, -8979, -8107, -7531, -7095, -6659, -6223, -5787, -5351, -5409, -5508, -5607, -5706, -5805, -5943, -6268, -6594, -6919, -7245, -7571, -7999, -8569, -9140, -9710, -10281, -10851, -11207, -11453, -11700, -11947, -12194, -12441, -12033, -11563, -11093, -10623, -10153, -9673, -9143, -8612, -8081, -7551, -7020, -6515, -6047, -5580, -5112, -4644, -4177, -3626, -3031, -2436, -1841, -1246, -650, -392, -170, 52, 274, 497, 680, 642, 605, 567, 529, 492, 390, 193, -5, -203, -401, -598, -1055, -1655, -2255, -2854, -3454, -4054, -4295, -4492, -4689, -4886, -5082, -5190, -4736, -4282, -3828, -3374, -2920, -2620, -2568, -2515, -2462, -2409, -2356, -2624, -3077, -3531, -3985, -4439, -4893, -5144, -5367, -5591, -5814, -6037, -6227, -6181, -6135, -6089, -6043, -5998, -5997, -6071, -6146, -6220, -6295, -6369, -6664, -7092, -7521, -7949, -8378, -8806, -9098, -9370, -9642, -9914, -10186, -10356, -9746, -9136, -8527, -7917, -7307, -6607, -5746, -4886, -4026, -3166, -2306, -1769, -1440, -1111, -782, -453, -124, 111, 331, 550, 770, 990, 1224, 1583, 1941, 2300, 2659, 3017, 3352, 3641, 3930, 4219, 4508, 4797, 4922, 4936, 4950, 4965, 4979, 4993, 4646, 4234, 3821, 3409, 2996, 2582, 2146, 1711, 1276, 841, 405, 60, -113, -285, -458, -630, -803, -1131, -1568, -2005, -2442, -2879, -3316, -3998, -4728, -5458, -6188, -6918, -7623, -8049, -8475, -8901, -9327, -9753, -10064, -10139, -10214, -10289, -10364, -10439, -10352, -10146, -9939, -9733, -9526, -9320, -9045, -8754, -8464, -8174, -7883, -7596, -7344, -7093, -6841, -6589, -6338, -6022, -5569, -5116, -4662, -4209, -3756, -3289, -2810, -2332, -1854, -1376, -898, -823, -842, -861, -880, -899, -936, -1262, -1587, -1913, -2238, -2563, -2825, -2943, -3060, -3178, -3295, -3413, -3465, -3466, -3467, -3468, -3469, -3470, -3504, -3547, -3590, -3632, -3675, -3720, -3796, -3873, -3949, -4026, -4102, -4135, -4064, -3994, -3923, -3852, -3781, -3631, -3415, -3199, -2983, -2766, -2550, -2467, -2420, -2372, -2324, -2276, -2233, -2286, -2340, -2393, -2447, -2501, -2499, -2358, -2217, -2076, -1935, -1795, -1568, -1267, -966, -664, -363, -62, 270, 611, 953, 1294, 1635, 1973, 2223, 2473, 2722, 2972, 3222, 3443, 3589, 3734, 3880, 4025, 4171, 4309, 4440, 4571, 4702, 4833, 4964, 4856, 4675, 4494, 4314, 4133, 3949, 3522, 3095, 2668, 2241, 1814, 1428, 1155, 882, 609, 336, 64, -138, -270, -402, -534, -667, -799, -816, -796, -776, -756, -736,


};



// lookup table value location
unsigned long location; // this is a 32bit number
                        // the lower 8bits are the subsample fraction
                        // and the upper 24 bits contain the sample number 
                       

// create logarithmic frequency lookup table
// PROGMEM stores the values in the program memory
// it is automatically included with AudioCodec.h
PROGMEM  prog_uint16_t logtable[]  = {
  // this file is stored in AudioCodec.h and is a 256 value
  // sinewave lookup table of unsigned 16bit integers
  // you can replace it with your own table if you like
  #include <logtable.inc>
};


void setup() {
 
 
  ///MOVED THIS TO START OF SETUP WHICH ENABLES THE MCP4728 TO WORK////////////
    AudioCodec_init(); // setup codec and microcontroller registers
   
   
   
   
  //////////////////////4728 SETUP ////////////////////////////////
 
  dac.begin();  // initialize i2c interface
  dac.vdd(5000); // set VDD(mV) of MCP4728 for correct conversion between LSB and Vout

  dac.analogWrite(0,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(0, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(0, 1); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(0, 0); // Power down channel 3 ( no voltage out from channel 3 )
 
 dac.analogWrite(1,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(1, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(1, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(1, 0); // Power down channel 3 ( no voltage out from channel 3 )
   
   dac.analogWrite(2,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(2, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(2, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(2, 0); // Power down channel 3 ( no voltage out from channel 3 )
   
    dac.analogWrite(3,4000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(3, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(3, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(3, 0); // Power down channel 3 ( no voltage out from channel 3 )
 
    //////////////////////4728 SETUP ////////////////////////////////

 
}


 





void loop() {
    dac.analogWrite(0,mcpVoltOut);//write to input register of a DAC. Channel 0-3, Value 0-4095
     
     
  while (1); // reduces clock jitter
}

// timer1 interrupt routine - all data processed here
ISR(TIMER1_COMPA_vect, ISR_NAKED) { // dont store any registers

 counter=counter+1;  if (counter>80000){counter=0;};
 
 ////////IF YOU CHANGE THIS VALUE AND RELOAD THE SKETCH THEN IT UPDATES THE MCP4728//////
 mcpVoltOut = 1500;// writes to dac.analogWrite(0,mcpVoltOut); IN VOID LOOP
 
 /////////////////TRIED TYING THIS TO COUNTER USING////////////
 //mcpVoltOut = counter/20;
 //////////////BUT IT DOESN'T WORK UPDATE///////////
 
 
 
 if (location > 260000){//lets the wave form finish before switching to eliminate clicks i think
 
 if (counter > 0 && counter < 20000) {arraypointer = 0; };
 if (counter > 20000 && counter < 40000) {arraypointer = 1;};
  if (counter > 40000 && counter < 60000) {arraypointer = 2;};
   if (counter > 60000 && counter < 80000) {arraypointer = 3;};
 
  };  //EO to eliminate click I think
 
mcpVoltOut = 1500;

 if (arraypointer==0){ selection = &wave1[0];};

if (arraypointer==1){ selection = &wave2[1];};

if (arraypointer==2){ selection = &wave3[2];};

if (arraypointer==3){ selection = &wave4[3];};




  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
 
  // create some temporary variables
  // these tend to work faster than using the main data variables
  // as they arent fetched and stored all the time
  unsigned int temp1;
  unsigned int temp2;
  unsigned int temp3;

 
  // convert input signal to unsigned integer
  // input is inverted, so it needs to be flipped as well
  temp1 = 0x8000 - left_in;
  // fetch lookup table entry to convert CV to frequency
  temp2 = pgm_read_word_near(logtable + (temp1 >> 8));
  // fetch next value to do interpolation
  temp3 = pgm_read_word_near(logtable + ((temp1 >> 8) + 1));
  // interpolate result
 
  unsigned char frac = (temp1 & 0x00ff); // fetch the lower 8b
  // we are done with temp1, so we can reuse it here
  MultiU16X8toH16(temp1, temp3, frac);
  // scaled sample 2 is now in temp1, and since we are done with
  // temp3, we can reuse it for the next result
  MultiU16X8toH16(temp3, temp2, 0xff - frac);
  // temp3 now has the scaled sample 1
  temp1 += temp3; // add samples together to get an average
  // our frequency value is now in temp1
 
  // create a variable frequency sinewave
  // step through table at rate determined by temp1
  location += temp1;
  // if weve gone over the table boundary -> loop back
  location &= 0x0003ffff; // fast way for 2^n values
  // fetch a sample from the lookup table
  temp1 = location >> 8;  // bit shift it
  temp2 = pgm_read_word_near(selection + temp1);
  // get next value for interpolation
  temp3 = pgm_read_word_near(selection + ((temp1 + 1) & 0x03ff));
  // interpolate result
  frac = (location & 0x000000ff); // fetch the lower 8b
  // we are done with temp1, so we can reuse it here
  MultiSU16X8toH16(temp1, temp3, frac);
  // scaled sample 2 is now in temp1, and since we are done with
  // temp3, we can reuse it for the next result
  MultiSU16X8toH16(temp3, temp2, 0xff - frac);
  // temp3 now has the scaled sample 1
  temp1 += temp3; // add samples together to get an average
  // our sinewave value is now in temp1
 
  left_out = temp1; // put sinusoid out on left channel
  right_out = -temp1; // put inverted version out on right chanel
 

  reti(); // dont forget to return from the interrupt
}



michaelmartin2758
 
Posts: 4
Joined: Fri Aug 09, 2013 10:56 pm

Re: VCO

Postby michaelmartin2758 » Tue Aug 27, 2013 10:26 pm

apologies

had 2 instances of mcpVoltOut = 1500; in the ISR

but this still doesn't change anything ...still very stuck ;-(




Code: Select all

    // setup codec parameters
    // must be done before #includes
    // see readme file in libraries folder for explanations
    #define SAMPLE_RATE 44 // 44.1kHz sample rate
    #define ADCS 0 // dont use ADCs
    #define ADCHPD 1 // high pass filter disabled -> DC coupled



    // include necessary libraries
    #include <Wire.h>
    #include <SPI.h>
    #include <AudioCodec.h>
    #include "mcp4728.h"    // Mcp4728
     mcp4728 dac = mcp4728(1); // instantiate mcp4728 object, Device ID = 1



    // create data variables for audio transfer
    // even though there is no input needed, the codec requires stereo data
    int left_in = 0; // in from codec (LINE_IN)
    int right_in = 0;
    int left_out = 0; // out to codec (HP_OUT)
    int right_out = 0;

    int *selection; //Array selection
    int arraypointer = 0; //array pointer
    unsigned long counter = 0; //counter for wave switcher
    unsigned long mcpVoltOut = 4000;




    //Wave 1
      PROGMEM prog_int16_t wave1 [1024]  = {

    1105, 1401, 1696, 1992, 2288, 2583, 2879, 3128, 3289, 3451, 3613, 3775, 3936, 4098, 4246, 4387, 4529, 4670, 4812, 4954, 5093, 5197, 5302, 5406, 5510, 5614, 5718, 5895, 6179, 6464, 6749, 7033, 7318, 7603, 7988, 8406, 8825, 9243, 9661, 10079, 10479, 10721, 10963, 11205, 11447, 11688, 11930, 12240, 12631, 13021, 13412, 13803, 14194, 14585, 15067, 15571, 16076, 16580, 17085, 17589, 18039, 18193, 18347, 18501, 18655, 18809, 18963, 19042, 19049, 19055, 19062, 19069, 19075, 19082, 19109, 19140, 19170, 19201, 19231, 19262, 19258, 19121, 18985, 18849, 18712, 18576, 18440, 18219, 17933, 17646, 17359, 17072, 16785, 16498, 16451, 16428, 16404, 16381, 16357, 16334, 16272, 16101, 15930, 15759, 15589, 15418, 15247, 14947, 14565, 14183, 13800, 13418, 13036, 12654, 12417, 12185, 11954, 11723, 11491, 11260, 11073, 10984, 10895, 10805, 10716, 10627, 10538, 10452, 10367, 10282, 10198, 10113, 10029, 9942, 9693, 9445, 9196, 8947, 8699, 8450, 8209, 7981, 7753, 7526, 7298, 7070, 6843, 6701, 6593, 6486, 6378, 6271, 6163, 6073, 6234, 6394, 6555, 6715, 6876, 7037, 7207, 7393, 7579, 7764, 7950, 8135, 8321, 8413, 8476, 8539, 8602, 8665, 8728, 8790, 8846, 8902, 8958, 9014, 9070, 9125, 9276, 9534, 9792, 10050, 10308, 10565, 10823, 11101, 11384, 11667, 11949, 12232, 12514, 12772, 12910, 13047, 13185, 13323, 13460, 13598, 13648, 13616, 13585, 13554, 13522, 13491, 13459, 13532, 13621, 13709, 13798, 13886, 13974, 14078, 14237, 14395, 14554, 14712, 14870, 15029, 15176, 15314, 15453, 15591, 15730, 15868, 16007, 16154, 16302, 16450, 16598, 16746, 16894, 16990, 16947, 16903, 16860, 16817, 16774, 16730, 16637, 16514, 16391, 16269, 16146, 16023, 15900, 15578, 15250, 14923, 14595, 14268, 13940, 13553, 13043, 12532, 12021, 11511, 11000, 10490, 9904, 9281, 8659, 8037, 7415, 6792, 6172, 5615, 5058, 4500, 3943, 3386, 2829, 2317, 1879, 1441, 1003, 565, 128, -310, -519, -643, -766, -890, -1013, -1137, -1238, -1082, -925, -769, -612, -456, -299, -144, 8, 161, 313, 466, 618, 771, 844, 894, 944, 995, 1045, 1095, 1158, 1304, 1449, 1595, 1741, 1886, 2032, 2139, 2204, 2270, 2336, 2401, 2467, 2532, 2379, 2182, 1985, 1788, 1590, 1393, 1199, 1022, 845, 667, 490, 313, 136, -61, -276, -490, -704, -918, -1132, -1346, -1573, -1802, -2031, -2259, -2488, -2717, -2894, -2902, -2911, -2919, -2927, -2936, -2944, -2852, -2689, -2526, -2363, -2199, -2036, -1873, -1757, -1644, -1530, -1417, -1304, -1191, -1108, -1096, -1085, -1074, -1063, -1051, -1040, -948, -809, -670, -531, -392, -254, -115, 518, 1157, 1796, 2435, 3074, 3713, 4236, 4533, 4831, 5128, 5426, 5723, 6020, 5867, 5511, 5155, 4798, 4442, 4085, 3733, 3480, 3227, 2974, 2721, 2468, 2215, 2078, 2122, 2166, 2210, 2253, 2297, 2341, 2409, 2485, 2561, 2637, 2713, 2789, 2818, 2380, 1943, 1506, 1069, 632, 194, -366, -1081, -1797, -2513, -3228, -3944, -4659, -4952, -5133, -5314, -5496, -5677, -5859, -5931, -5349, -4767, -4185, -3603, -3021, -2439, -2010, -1737, -1464, -1191, -919, -646, -373, -724, -1191, -1657, -2123, -2589, -3055, -3571, -4290, -5010, -5729, -6449, -7169, -7888, -8441, -8857, -9272, -9687, -10102, -10518, -10933, -10742, -10481, -10221, -9960, -9700, -9439, -9238, -9219, -9200, -9181, -9162, -9143, -9124, -9828, -11016, -12205, -13394, -14582, -15771, -16960, -18127, -19293, -20459, -21625, -22792, -23958, -24556, -23823, -23091, -22358, -21626, -20893, -20161, -19332, -18451, -17570, -16689, -15808, -14927, -14046, -13680, -13314, -12947, -12581, -12215, -11848, -11610, -11608, -11606, -11604, -11601, -11599, -11597, -12075, -12756, -13437, -14118, -14799, -15480, -16068, -14973, -13879, -12785, -11690, -10596, -9502, -8273, -6844, -5415, -3986, -2558, -1129, 300, -293, -1546, -2799, -4052, -5305, -6558, -7789, -8830, -9872, -10914, -11956, -12997, -14039, -14119, -13046, -11974, -10901, -9829, -8756, -7684, -6779, -5914, -5049, -4185, -3320, -2455, -1760, -1979, -2198, -2418, -2637, -2856, -3075, -3112, -2974, -2835, -2696, -2557, -2418, -2280, -1586, -800, -14, 772, 1558, 2343, 3010, 3222, 3434, 3647, 3859, 4071, 4283, 4437, 4543, 4649, 4756, 4862, 4969, 5075, 4810, 4508, 4206, 3904, 3602, 3301, 2993, 2668, 2344, 2019, 1695, 1370, 1046, 1105, 1408, 1711, 2014, 2317, 2620, 2923, 2684, 2424, 2164, 1904, 1644, 1384, 1067, 626, 184, -257, -699, -1140, -1582, -1645, -1517, -1389, -1261, -1133, -1005, -875, -602, -328, -55, 219, 492, 766, 908, 822, 736, 650, 564, 478, 393, 329, 275, 221, 167, 113, 59, 36, 446, 856, 1266, 1675, 2085, 2495, 2928, 3394, 3860, 4325, 4791, 5257, 5722, 5804, 5769, 5734, 5699, 5664, 5630, 5581, 5432, 5283, 5134, 4984, 4835, 4686, 4688, 4861, 5033, 5206, 5379, 5552, 5725, 5823, 5904, 5986, 6068, 6149, 6231, 6274, 6130, 5986, 5841, 5697, 5553, 5409, 5317, 5272, 5228, 5184, 5140, 5096, 5052, 4835, 4592, 4349, 4107, 3864, 3621, 3471, 3645, 3819, 3993, 4167, 4342, 4516, 4912, 5474, 6036, 6598, 7160, 7723, 8285, 8026, 7698, 7371, 7043, 6716, 6388, 5924, 5095, 4266, 3437, 2608, 1780, 951, 513, 310, 107, -95, -298, -501, -704, -556, -400, -243, -87, 70, 226, 285, 140, -4, -148, -293, -437, -582, -813, -1087, -1361, -1634, -1908, -2182, -2457, -2815, -3173, -3530, -3888, -4245, -4603, -4864, -4966, -5069, -5171, -5273, -5375, -5478, -5342, -5118, -4894, -4670, -4446, -4222, -4052, -4516, -4980, -5444, -5907, -6371, -6835, -7557, -8623, -9689, -10755, -11821, -12887, -13953, -14360, -14582, -14804, -15026, -15248, -15470, -15651, -15565, -15478, -15392, -15306, -15219, -15133, -15432, -16147, -16862, -17577, -18292, -19007, -19722, -20197, -20624, -21052, -21479, -21906, -22333, -22565, -21925, -21284, -20644, -20004, -19364, -18723, -18273, -17989, -17704, -17420, -17135, -16851, -16567, -16869, -17248, -17627, -18006, -18385, -18764, -19014, -18844, -18673, -18503, -18333, -18162, -17992, -17721, -17378, -17036, -16693, -16351, -16008, -15666, -15487, -15319, -15151, -14982, -14814, -14646, -14489, -14358, -14226, -14095, -13963, -13832, -13701, -13852, -14165, -14478, -14790, -15103, -15415, -15728, -15897, -16065, -16232, -16399, -16567, -16734, -16716, -16337, -15958, -15579, -15199, -14820, -14441, -14127, -13841, -13556, -13271, -12986, -12701, -12425, -12371, -12317, -12263, -12209, -12156, -12102, -11947, -11637, -11326, -11015, -10704, -10393, -10083, -9647, -9168, -8689, -8210, -7730, -7251, -6787, -6468, -6150, -5832, -5513, -5195, -4876, -4627, -4465, -4303, -4140, -3978, -3816, -3654, -3644, -3673, -3703, -3732, -3762, -3791, -3810, -3765, -3720, -3675, -3631, -3586, -3541, -3612, -3802, -3992, -4182, -4372, -4562, -4752, -4913, -5068, -5224, -5379, -5535, -5690, -5734, -5321, -4908, -4496, -4083, -3670, -3257, -2979, -2814, -2648, -2482, -2317, -2151, -1986, -2188, -2433, -2677, -2922, -3166, -3411, -3582, -3530, -3477, -3425, -3373, -3321, -3269, -3157, -3007, -2856, -2705, -2555, -2404, -2253, -2163, -2076, -1989, -1902, -1816, -1729, -1559, -1198, -836, -475, -113, 248, 610, 819, 947, 1075, 1202, 1330, 1458,

    };


    //Wave 2
     PROGMEM prog_int16_t wave2 [1024]  = {

    3144, 3388, 3631, 3875, 4118, 4362, 4606, 4848, 5089, 5330, 5571, 5812, 6053, 6287, 6472, 6657, 6842, 7027, 7211, 7396, 7542, 7669, 7796, 7922, 8049, 8176, 8307, 8451, 8594, 8737, 8881, 9024, 9168, 9270, 9362, 9454, 9547, 9639, 9731, 9852, 10025, 10198, 10371, 10544, 10716, 10889, 11162, 11444, 11726, 12008, 12289, 12571, 12840, 13096, 13351, 13606, 13862, 14117, 14367, 14469, 14572, 14674, 14777, 14879, 14982, 15094, 15213, 15332, 15451, 15570, 15689, 15811, 15948, 16085, 16222, 16360, 16497, 16634, 16495, 16247, 15999, 15751, 15503, 15255, 14914, 14331, 13747, 13164, 12580, 11996, 11413, 10809, 10201, 9593, 8985, 8377, 7769, 7242, 6837, 6432, 6027, 5622, 5218, 4813, 4494, 4179, 3865, 3550, 3235, 2921, 2672, 2485, 2297, 2110, 1923, 1736, 1587, 1915, 2243, 2570, 2898, 3225, 3553, 4019, 4564, 5109, 5654, 6199, 6745, 7268, 7704, 8139, 8574, 9010, 9445, 9880, 10149, 10362, 10576, 10790, 11004, 11218, 11345, 11284, 11223, 11162, 11101, 11040, 10979, 10859, 10731, 10603, 10475, 10347, 10218, 9999, 9659, 9320, 8981, 8641, 8302, 7963, 7418, 6872, 6326, 5780, 5234, 4688, 4297, 4030, 3764, 3498, 3231, 2965, 2706, 2502, 2298, 2093, 1889, 1685, 1481, 1104, 644, 184, -276, -737, -1197, -1639, -2022, -2405, -2788, -3171, -3554, -3937, -4246, -4534, -4823, -5112, -5401, -5690, -6008, -6380, -6751, -7123, -7495, -7867, -8238, -8480, -8710, -8939, -9168, -9398, -9627, -9629, -9376, -9123, -8870, -8617, -8364, -8111, -7888, -7665, -7441, -7218, -6995, -6772, -6680, -6679, -6678, -6677, -6677, -6676, -6668, -6624, -6579, -6535, -6490, -6446, -6402, -6552, -6782, -7012, -7242, -7473, -7703, -8058, -8752, -9446, -10140, -10834, -11528, -12222, -13274, -14399, -15524, -16649, -17774, -18899, -20030, -21172, -22313, -23454, -24595, -25736, -26877, -27434, -27959, -28484, -29009, -29535, -30060, -30285, -30222, -30159, -30096, -30033, -29969, -29895, -29670, -29446, -29221, -28996, -28771, -28547, -28139, -27623, -27107, -26590, -26074, -25558, -24923, -23775, -22626, -21478, -20330, -19182, -18033, -16851, -15657, -14464, -13270, -12076, -10882, -9884, -9323, -8761, -8200, -7639, -7078, -6517, -6454, -6468, -6481, -6494, -6508, -6521, -6578, -6692, -6807, -6921, -7036, -7151, -7265, -7242, -7217, -7191, -7166, -7141, -7116, -7193, -7354, -7515, -7676, -7837, -7998, -8174, -8482, -8790, -9098, -9406, -9714, -10022, -10111, -10092, -10073, -10053, -10034, -10015, -9893, -9420, -8948, -8476, -8004, -7532, -7059, -6548, -6025, -5503, -4981, -4458, -3936, -3446, -3017, -2587, -2158, -1729, -1300, -871, -438, -5, 427, 860, 1293, 1726, 2042, 2224, 2406, 2588, 2770, 2952, 3125, 2944, 2763, 2582, 2401, 2220, 2039, 1908, 1813, 1717, 1621, 1525, 1430, 1368, 1508, 1647, 1787, 1927, 2067, 2206, 2126, 1954, 1782, 1609, 1437, 1265, 1026, 600, 174, -251, -677, -1103, -1528, -1597, -1589, -1581, -1573, -1565, -1557, -1407, -1029, -651, -273, 105, 483, 861, 1257, 1654, 2051, 2449, 2846, 3243, 3548, 3762, 3976, 4189, 4403, 4616, 4815, 4785, 4755, 4725, 4696, 4666, 4636, 4592, 4540, 4488, 4436, 4384, 4332, 4360, 4748, 5135, 5523, 5910, 6298, 6685, 7065, 7442, 7819, 8197, 8574, 8951, 9224, 9258, 9292, 9326, 9360, 9394, 9428, 9577, 9744, 9911, 10078, 10245, 10412, 10721, 11225, 11730, 12234, 12739, 13243, 13747, 14262, 14777, 15293, 15808, 16323, 16838, 17108, 17170, 17232, 17294, 17357, 17419, 17448, 17178, 16908, 16638, 16368, 16098, 15828, 15120, 14186, 13253, 12319, 11385, 10452, 9529, 8647, 7764, 6882, 6000, 5117, 4235, 3657, 3166, 2675, 2184, 1692, 1201, 692, 148, -396, -939, -1483, -2027, -2571, -3196, -3830, -4464, -5098, -5732, -6366, -6747, -6829, -6911, -6993, -7075, -7157, -7224, -6490, -5756, -5022, -4289, -3555, -2821, -2330, -2016, -1702, -1388, -1074, -759, -533, -850, -1167, -1484, -1802, -2119, -2436, -2838, -3276, -3714, -4152, -4590, -5028, -5413, -5643, -5873, -6104, -6334, -6565, -6795, -7151, -7536, -7920, -8305, -8689, -9073, -9455, -9833, -10211, -10588, -10966, -11344, -11721, -11788, -11834, -11879, -11925, -11971, -12017, -11892, -11596, -11300, -11004, -10708, -10412, -10101, -9554, -9007, -8460, -7913, -7366, -6818, -6296, -5789, -5282, -4776, -4269, -3762, -3286, -2955, -2625, -2294, -1964, -1633, -1302, -1072, -877, -683, -488, -293, -99, 84, 239, 394, 549, 704, 859, 1014, 797, 518, 238, -41, -321, -600, -849, -1054, -1258, -1463, -1668, -1873, -2077, -1938, -1789, -1641, -1492, -1343, -1195, -1125, -1122, -1120, -1117, -1115, -1112, -1140, -1450, -1761, -2072, -2383, -2694, -3004, -3198, -3329, -3461, -3592, -3724, -3855, -3964, -3989, -4015, -4040, -4066, -4091, -4117, -4281, -4485, -4690, -4895, -5099, -5304, -5512, -5728, -5944, -6161, -6377, -6593, -6809, -7040, -7272, -7505, -7738, -7970, -8203, -8338, -8354, -8370, -8387, -8403, -8420, -8434, -8259, -8085, -7911, -7736, -7562, -7388, -7073, -6652, -6232, -5812, -5392, -4972, -4528, -3929, -3330, -2731, -2132, -1533, -934, -307, 331, 969, 1608, 2246, 2884, 3491, 4004, 4516, 5028, 5541, 6054, 6566, 6977, 7364, 7752, 8139, 8526, 8914, 9268, 9566, 9864, 10162, 10460, 10758, 11056, 11129, 11185, 11242, 11298, 11354, 11410, 11329, 11104, 10879, 10655, 10430, 10206, 9984, 9818, 9653, 9487, 9321, 9156, 8990, 8952, 8995, 9038, 9082, 9125, 9168, 9241, 9463, 9685, 9907, 10128, 10350, 10572, 10790, 11006, 11223, 11440, 11656, 11873, 12052, 12139, 12226, 12313, 12400, 12487, 12574, 12663, 12752, 12841, 12930, 13020, 13109, 13133, 13065, 12996, 12928, 12859, 12791, 12722, 12517, 12308, 12098, 11889, 11680, 11470, 11167, 10782, 10396, 10010, 9624, 9238, 8840, 8319, 7797, 7276, 6755, 6233, 5712, 5260, 4846, 4432, 4019, 3605, 3191, 2843, 2750, 2656, 2562, 2468, 2374, 2281, 2316, 2391, 2465, 2539, 2614, 2688, 2739, 2740, 2742, 2743, 2745, 2746, 2747, 2649, 2537, 2425, 2314, 2202, 2090, 1980, 1870, 1761, 1651, 1542, 1433, 1324, 1289, 1255, 1220, 1186, 1151, 1117, 1059, 983, 906, 830, 754, 678, 566, 205, -156, -517, -878, -1239, -1600, -1883, -2130, -2377, -2625, -2872, -3119, -3264, -3092, -2921, -2750, -2578, -2407, -2235, -2093, -1957, -1822, -1686, -1551, -1415, -1372, -1489, -1606, -1723, -1840, -1958, -2075, -2123, -2165, -2208, -2250, -2293, -2336, -2374, -2407, -2440, -2473, -2506, -2540, -2586, -2909, -3232, -3556, -3879, -4202, -4526, -4914, -5345, -5776, -6206, -6637, -7068, -7468, -7713, -7958, -8203, -8447, -8692, -8937, -8992, -8975, -8957, -8940, -8922, -8905, -8894, -8899, -8905, -8910, -8915, -8921, -8926, -8904, -8877, -8850, -8823, -8796, -8770, -8698, -8561, -8424, -8287, -8150, -8013, -7876, -7577, -7272, -6967, -6662, -6357, -6052, -5765, -5496, -5226, -4956, -4686, -4417, -4176, -4253, -4330, -4407, -4484, -4561, -4639, -4796, -4999, -5202, -5405, -5608, -5811, -5960, -5898, -5837, -5775, -5713, -5652, -5590, -5425, -5227, -5029, -4831, -4633, -4435, -4276, -4199, -4122, -4045, -3968, -3891, -3814, -3683, -3544, -3405, -3267, -3128, -2989, -2775, -2465, -2155, -1845, -1535, -1225,

    };

    //Wave 3
    PROGMEM prog_int16_t wave3 [1024]  = {
     
    1112, 1448, 1784, 2120, 2455, 2791, 3127, 3401, 3561, 3721, 3880, 4040, 4199, 4359, 4404, 4400, 4396, 4391, 4387, 4383, 4376, 4311, 4246, 4181, 4116, 4051, 3986, 4079, 4405, 4732, 5058, 5384, 5711, 6037, 6273, 6479, 6685, 6891, 7097, 7303, 7460, 7196, 6933, 6669, 6405, 6141, 5878, 5720, 5690, 5661, 5631, 5601, 5571, 5541, 5856, 6255, 6654, 7053, 7453, 7852, 8202, 8293, 8383, 8473, 8563, 8654, 8744, 8767, 8724, 8682, 8640, 8598, 8555, 8513, 8635, 8785, 8934, 9084, 9233, 9383, 9529, 9664, 9798, 9933, 10067, 10202, 10336, 10458, 10569, 10681, 10792, 10903, 11015, 11126, 11148, 11162, 11175, 11189, 11203, 11216, 11183, 11017, 10850, 10684, 10517, 10351, 10185, 10044, 9921, 9797, 9673, 9549, 9425, 9302, 9316, 9335, 9355, 9374, 9394, 9413, 9387, 9260, 9134, 9007, 8880, 8753, 8627, 8432, 8204, 7975, 7746, 7518, 7289, 7063, 7057, 7051, 7045, 7039, 7034, 7028, 7074, 7210, 7347, 7484, 7621, 7758, 7894, 7935, 7937, 7940, 7942, 7944, 7947, 7939, 7782, 7626, 7469, 7313, 7156, 7000, 6898, 6872, 6846, 6820, 6795, 6769, 6743, 6916, 7149, 7383, 7616, 7850, 8083, 8299, 8380, 8461, 8542, 8623, 8704, 8785, 8768, 8641, 8514, 8387, 8259, 8132, 8005, 7899, 7798, 7697, 7596, 7495, 7394, 7323, 7394, 7465, 7537, 7608, 7679, 7751, 7772, 7748, 7723, 7698, 7674, 7649, 7625, 7407, 7160, 6914, 6667, 6421, 6174, 5916, 5616, 5316, 5016, 4716, 4416, 4117, 3920, 3801, 3682, 3563, 3444, 3324, 3205, 3251, 3310, 3369, 3428, 3487, 3546, 3543, 3372, 3202, 3032, 2861, 2691, 2521, 2253, 1927, 1601, 1275, 949, 623, 297, 230, 169, 109, 48, -13, -73, -51, 144, 339, 533, 728, 923, 1118, 1234, 1313, 1392, 1470, 1549, 1627, 1704, 1688, 1672, 1656, 1640, 1623, 1607, 1685, 1916, 2147, 2378, 2608, 2840, 3070, 3507, 4021, 4535, 5048, 5562, 6076, 6572, 6862, 7152, 7443, 7733, 8023, 8314, 8428, 8307, 8186, 8065, 7944, 7823, 7702, 7436, 7130, 6824, 6517, 6211, 5905, 5578, 5111, 4644, 4178, 3711, 3245, 2778, 2142, 1323, 504, -315, -1134, -1953, -2772, -3686, -4618, -5550, -6482, -7414, -8347, -9232, -9909, -10586, -11262, -11939, -12615, -13292, -13744, -13998, -14252, -14506, -14761, -15015, -15269, -15064, -14798, -14531, -14265, -13999, -13733, -13413, -12919, -12425, -11931, -11437, -10943, -10449, -9968, -9497, -9025, -8553, -8082, -7610, -7139, -6689, -6240, -5791, -5342, -4893, -4445, -4021, -3662, -3302, -2943, -2583, -2224, -1864, -1711, -1676, -1640, -1605, -1570, -1534, -1499, -1705, -1914, -2123, -2331, -2540, -2749, -2921, -3022, -3123, -3223, -3324, -3424, -3525, -3569, -3588, -3607, -3625, -3644, -3663, -3681, -3690, -3699, -3709, -3718, -3727, -3736, -3763, -3815, -3868, -3920, -3973, -4025, -4078, -4103, -4118, -4133, -4148, -4163, -4178, -4186, -4132, -4078, -4023, -3969, -3915, -3860, -3874, -3975, -4075, -4176, -4276, -4377, -4477, -4545, -4604, -4663, -4722, -4781, -4840, -4878, -4796, -4713, -4630, -4547, -4464, -4382, -4215, -3962, -3710, -3457, -3204, -2952, -2699, -2410, -2114, -1819, -1523, -1227, -931, -660, -492, -323, -155, 14, 182, 351, 536, 736, 935, 1135, 1334, 1533, 1733, 2076, 2436, 2796, 3156, 3516, 3876, 4189, 4362, 4535, 4708, 4880, 5053, 5226, 5196, 5030, 4864, 4697, 4531, 4365, 4199, 4150, 4108, 4065, 4023, 3980, 3938, 3885, 3807, 3729, 3652, 3574, 3496, 3419, 2995, 2384, 1773, 1163, 552, -59, -670, -1600, -2531, -3462, -4393, -5323, -6254, -7200, -8173, -9147, -10120, -11093, -12067, -13040, -13976, -14895, -15815, -16734, -17654, -18573, -19470, -19954, -20439, -20923, -21408, -21892, -22376, -22616, -22494, -22372, -22250, -22129, -22007, -21885, -21524, -21084, -20645, -20206, -19767, -19328, -18868, -18235, -17601, -16968, -16334, -15701, -15067, -14335, -13485, -12635, -11785, -10935, -10086, -9236, -8752, -8357, -7961, -7566, -7170, -6775, -6506, -6917, -7328, -7739, -8150, -8561, -8972, -9438, -9956, -10475, -10993, -11512, -12030, -12549, -12583, -12537, -12491, -12445, -12399, -12353, -12308, -12271, -12233, -12195, -12157, -12120, -12082, -12153, -12309, -12466, -12622, -12778, -12934, -13091, -12730, -12318, -11906, -11494, -11082, -10670, -10143, -9294, -8444, -7594, -6744, -5895, -5045, -4286, -3586, -2886, -2186, -1485, -785, -85, 53, 169, 284, 400, 516, 631, 595, 223, -149, -521, -893, -1265, -1637, -1800, -1858, -1915, -1973, -2030, -2088, -2138, -1629, -1121, -613, -105, 404, 912, 1173, 1003, 834, 664, 494, 325, 155, -540, -1444, -2348, -3252, -4156, -5060, -5905, -5912, -5919, -5926, -5933, -5940, -5947, -5730, -5198, -4665, -4133, -3601, -3069, -2537, -2553, -2735, -2917, -3100, -3282, -3465, -3665, -4000, -4335, -4670, -5005, -5340, -5675, -5835, -5799, -5762, -5725, -5689, -5652, -5615, -5246, -4804, -4362, -3919, -3477, -3035, -2544, -1816, -1088, -361, 367, 1095, 1823, 2302, 2553, 2804, 3054, 3305, 3556, 3806, 3429, 2959, 2489, 2018, 1548, 1078, 750, 924, 1098, 1272, 1446, 1620, 1793, 2510, 3634, 4757, 5880, 7003, 8126, 9249, 9597, 9880, 10163, 10446, 10730, 11013, 11091, 10625, 10159, 9694, 9228, 8762, 8296, 8379, 8791, 9204, 9617, 10029, 10442, 10854, 12014, 13193, 14371, 15550, 16729, 17908, 18710, 18734, 18758, 18782, 18806, 18829, 18853, 17964, 16638, 15312, 13986, 12660, 11334, 10026, 9354, 8682, 8009, 7337, 6665, 5993, 5683, 5968, 6254, 6540, 6826, 7112, 7398, 7507, 7551, 7595, 7639, 7682, 7726, 7734, 7319, 6904, 6489, 6074, 5659, 5244, 4802, 4322, 3843, 3364, 2885, 2405, 1926, 2071, 2392, 2713, 3033, 3354, 3675, 4075, 4999, 5923, 6846, 7770, 8694, 9618, 9922, 9559, 9196, 8832, 8469, 8106, 7743, 6317, 4677, 3037, 1397, -242, -1882, -3256, -3437, -3618, -3800, -3981, -4163, -4344, -3990, -3167, -2344, -1522, -699, 124, 946, 534, -40, -614, -1188, -1762, -2336, -2940, -3639, -4339, -5038, -5738, -6437, -7137, -7212, -6846, -6479, -6112, -5746, -5379, -5012, -4270, -3502, -2735, -1967, -1199, -431, 239, 667, 1095, 1523, 1951, 2379, 2807, 2859, 2697, 2535, 2373, 2211, 2049, 1887, 1369, 847, 325, -198, -720, -1242, -1522, -1329, -1137, -944, -751, -558, -365, 58, 585, 1113, 1640, 2167, 2694, 3178, 2614, 2050, 1487, 923, 359, -205, -859, -1653, -2447, -3241, -4035, -4829, -5623, -5780, -5715, -5650, -5585, -5520, -5455, -5350, -4859, -4368, -3877, -3386, -2895, -2404, -2166, -2247, -2328, -2409, -2490, -2571, -2652, -3167, -3795, -4423, -5052, -5680, -6308, -6855, -6921, -6987, -7053, -7118, -7184, -7250, -6951, -6279, -5607, -4935, -4263, -3592, -2920, -2626, -2402, -2177, -1953, -1729, -1504, -1431, -1975, -2520, -3064, -3609, -4154, -4698, -5097, -5374, -5652, -5930, -6207, -6485, -6762, -6391, -5946, -5500, -5055, -4609, -4164, -3733, -3347, -2960, -2574, -2187, -1801, -1414, -1443, -1750, -2058, -2365, -2672, -2980, -3287, -3719, -4158, -4597, -5036, -5475, -5914, -6083, -5618, -5154, -4690, -4226, -3762, -3298, -2829, -2357, -1886, -1414, -943, -1297,

    };

    //Wave 4
    PROGMEM prog_int16_t wave4 [1024]  = {
    1381, 1173, 964, 756, 548, 339, 143, -16, -176, -336, -495, -655, -621, -388, -156, 76, 308, 541, 761, 976, 1192, 1407, 1623, 1838, 1754, 1666, 1578, 1490, 1402, 1295, 1127, 959, 791, 622, 454, 390, 436, 482, 529, 575, 621, 887, 1234, 1581, 1928, 2275, 2622, 2808, 2991, 3173, 3356, 3538, 3667, 3612, 3557, 3502, 3447, 3392, 3523, 3860, 4198, 4536, 4873, 5211, 5791, 6465, 7139, 7813, 8487, 9161, 9536, 9900, 10264, 10628, 10992, 11295, 11372, 11449, 11526, 11603, 11680, 11772, 11880, 11988, 12096, 12204, 12313, 12413, 12509, 12606, 12702, 12799, 12895, 12922, 12945, 12968, 12990, 13013, 12990, 12783, 12577, 12371, 12164, 11958, 11715, 11426, 11138, 10850, 10562, 10274, 10187, 10188, 10188, 10189, 10189, 10190, 10221, 10254, 10287, 10320, 10353, 10336, 10108, 9880, 9653, 9425, 9197, 8960, 8711, 8461, 8212, 7962, 7712, 7591, 7528, 7464, 7401, 7338, 7275, 7310, 7352, 7394, 7436, 7478, 7496, 7405, 7315, 7225, 7134, 7044, 6895, 6668, 6440, 6213, 5985, 5758, 5643, 5583, 5523, 5464, 5404, 5344, 5359, 5380, 5402, 5423, 5444, 5425, 5207, 4989, 4771, 4553, 4334, 4070, 3742, 3413, 3084, 2756, 2427, 2143, 1881, 1619, 1357, 1096, 834, 585, 338, 91, -157, -404, -622, -682, -743, -803, -864, -924, -922, -829, -736, -643, -550, -457, -408, -381, -355, -328, -302, -275, -118, 55, 227, 399, 571, 758, 1032, 1307, 1581, 1855, 2130, 2331, 2420, 2510, 2599, 2688, 2778, 2773, 2715, 2657, 2599, 2542, 2484, 2367, 2242, 2118, 1993, 1869, 1748, 1657, 1565, 1474, 1382, 1291, 1258, 1319, 1380, 1441, 1502, 1563, 1600, 1623, 1646, 1669, 1691, 1714, 1667, 1611, 1555, 1498, 1442, 1408, 1531, 1654, 1777, 1900, 2022, 2177, 2385, 2593, 2801, 3009, 3217, 3350, 3437, 3524, 3611, 3698, 3785, 3812, 3829, 3846, 3863, 3880, 3897, 3920, 3943, 3966, 3989, 4012, 4067, 4178, 4290, 4401, 4513, 4624, 4747, 4878, 5008, 5138, 5269, 5399, 5396, 5371, 5345, 5319, 5294, 5265, 5212, 5159, 5105, 5052, 4999, 4984, 5041, 5098, 5155, 5212, 5269, 5306, 5328, 5350, 5373, 5395, 5418, 5346, 5257, 5168, 5079, 4990, 4907, 4876, 4846, 4816, 4786, 4755, 4777, 4899, 5021, 5144, 5266, 5388, 5532, 5691, 5849, 6008, 6167, 6326, 6444, 6553, 6662, 6772, 6881, 6989, 7081, 7172, 7264, 7356, 7447, 7551, 7679, 7806, 7934, 8062, 8190, 8313, 8433, 8552, 8672, 8792, 8912, 8987, 9052, 9117, 9183, 9248, 9310, 9327, 9344, 9362, 9379, 9396, 9409, 9415, 9420, 9426, 9431, 9436, 9464, 9510, 9555, 9601, 9646, 9692, 9719, 9742, 9764, 9787, 9810, 9828, 9767, 9705, 9644, 9583, 9521, 9477, 9472, 9467, 9462, 9457, 9452, 9496, 9581, 9666, 9751, 9836, 9921, 10012, 10105, 10198, 10291, 10383, 10479, 10620, 10762, 10904, 11046, 11187, 11334, 11491, 11649, 11806, 11964, 12121, 12235, 12311, 12387, 12462, 12538, 12614, 12564, 12480, 12396, 12311, 12227, 12134, 11806, 11478, 11150, 10822, 10494, 10087, 9478, 8870, 8261, 7652, 7043, 6352, 5586, 4821, 4055, 3290, 2524, 1839, 1176, 513, -150, -812, -1469, -1868, -2267, -2666, -3065, -3464, -3810, -4013, -4217, -4420, -4623, -4826, -4891, -4826, -4762, -4697, -4632, -4568, -4222, -3789, -3357, -2925, -2492, -2058, -1512, -966, -420, 127, 673, 1185, 1601, 2016, 2431, 2847, 3262, 3552, 3719, 3887, 4055, 4222, 4390, 4384, 4322, 4261, 4199, 4137, 4075, 3915, 3755, 3594, 3434, 3274, 3113, 2950, 2787, 2624, 2462, 2299, 2104, 1878, 1651, 1424, 1197, 970, 557, 78, -400, -878, -1356, -1834, -2262, -2689, -3117, -3544, -3971, -4327, -4451, -4576, -4700, -4825, -4950, -5104, -5290, -5477, -5663, -5849, -6035, -6343, -6696, -7048, -7400, -7753, -8105, -8147, -8182, -8218, -8253, -8288, -8195, -7664, -7133, -6602, -6071, -5540, -5043, -4584, -4125, -3666, -3206, -2747, -2510, -2357, -2205, -2053, -1901, -1749, -1484, -1215, -946, -677, -408, -149, 78, 304, 530, 757, 983, 1166, 1299, 1432, 1565, 1698, 1831, 1726, 1526, 1325, 1124, 923, 722, -214, -1183, -2151, -3119, -4088, -5059, -6042, -7024, -8007, -8990, -9972, -10772, -11351, -11929, -12507, -13086, -13664, -14486, -15414, -16342, -17269, -18197, -19124, -20344, -21579, -22815, -24051, -25287, -26401, -27008, -27615, -28222, -28829, -29436, -29658, -29390, -29122, -28855, -28587, -28320, -27680, -26871, -26062, -25253, -24444, -23635, -22677, -21708, -20739, -19771, -18802, -17846, -16947, -16049, -15150, -14252, -13353, -12466, -11594, -10723, -9851, -8979, -8107, -7531, -7095, -6659, -6223, -5787, -5351, -5409, -5508, -5607, -5706, -5805, -5943, -6268, -6594, -6919, -7245, -7571, -7999, -8569, -9140, -9710, -10281, -10851, -11207, -11453, -11700, -11947, -12194, -12441, -12033, -11563, -11093, -10623, -10153, -9673, -9143, -8612, -8081, -7551, -7020, -6515, -6047, -5580, -5112, -4644, -4177, -3626, -3031, -2436, -1841, -1246, -650, -392, -170, 52, 274, 497, 680, 642, 605, 567, 529, 492, 390, 193, -5, -203, -401, -598, -1055, -1655, -2255, -2854, -3454, -4054, -4295, -4492, -4689, -4886, -5082, -5190, -4736, -4282, -3828, -3374, -2920, -2620, -2568, -2515, -2462, -2409, -2356, -2624, -3077, -3531, -3985, -4439, -4893, -5144, -5367, -5591, -5814, -6037, -6227, -6181, -6135, -6089, -6043, -5998, -5997, -6071, -6146, -6220, -6295, -6369, -6664, -7092, -7521, -7949, -8378, -8806, -9098, -9370, -9642, -9914, -10186, -10356, -9746, -9136, -8527, -7917, -7307, -6607, -5746, -4886, -4026, -3166, -2306, -1769, -1440, -1111, -782, -453, -124, 111, 331, 550, 770, 990, 1224, 1583, 1941, 2300, 2659, 3017, 3352, 3641, 3930, 4219, 4508, 4797, 4922, 4936, 4950, 4965, 4979, 4993, 4646, 4234, 3821, 3409, 2996, 2582, 2146, 1711, 1276, 841, 405, 60, -113, -285, -458, -630, -803, -1131, -1568, -2005, -2442, -2879, -3316, -3998, -4728, -5458, -6188, -6918, -7623, -8049, -8475, -8901, -9327, -9753, -10064, -10139, -10214, -10289, -10364, -10439, -10352, -10146, -9939, -9733, -9526, -9320, -9045, -8754, -8464, -8174, -7883, -7596, -7344, -7093, -6841, -6589, -6338, -6022, -5569, -5116, -4662, -4209, -3756, -3289, -2810, -2332, -1854, -1376, -898, -823, -842, -861, -880, -899, -936, -1262, -1587, -1913, -2238, -2563, -2825, -2943, -3060, -3178, -3295, -3413, -3465, -3466, -3467, -3468, -3469, -3470, -3504, -3547, -3590, -3632, -3675, -3720, -3796, -3873, -3949, -4026, -4102, -4135, -4064, -3994, -3923, -3852, -3781, -3631, -3415, -3199, -2983, -2766, -2550, -2467, -2420, -2372, -2324, -2276, -2233, -2286, -2340, -2393, -2447, -2501, -2499, -2358, -2217, -2076, -1935, -1795, -1568, -1267, -966, -664, -363, -62, 270, 611, 953, 1294, 1635, 1973, 2223, 2473, 2722, 2972, 3222, 3443, 3589, 3734, 3880, 4025, 4171, 4309, 4440, 4571, 4702, 4833, 4964, 4856, 4675, 4494, 4314, 4133, 3949, 3522, 3095, 2668, 2241, 1814, 1428, 1155, 882, 609, 336, 64, -138, -270, -402, -534, -667, -799, -816, -796, -776, -756, -736,


    };



    // lookup table value location
    unsigned long location; // this is a 32bit number
                            // the lower 8bits are the subsample fraction
                            // and the upper 24 bits contain the sample number
                           

    // create logarithmic frequency lookup table
    // PROGMEM stores the values in the program memory
    // it is automatically included with AudioCodec.h
    PROGMEM  prog_uint16_t logtable[]  = {
      // this file is stored in AudioCodec.h and is a 256 value
      // sinewave lookup table of unsigned 16bit integers
      // you can replace it with your own table if you like
      #include <logtable.inc>
    };


    void setup() {
     
     
      ///MOVED THIS TO START OF SETUP WHICH ENABLES THE MCP4728 TO WORK////////////
        AudioCodec_init(); // setup codec and microcontroller registers
       
       
       
       
      //////////////////////4728 SETUP ////////////////////////////////
     
      dac.begin();  // initialize i2c interface
      dac.vdd(5000); // set VDD(mV) of MCP4728 for correct conversion between LSB and Vout

      dac.analogWrite(0,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
      dac.setVref(0, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
      dac.setGain(0, 1); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
      dac.setPowerDown(0, 0); // Power down channel 3 ( no voltage out from channel 3 )
     
     dac.analogWrite(1,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
      dac.setVref(1, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
      dac.setGain(1, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
      dac.setPowerDown(1, 0); // Power down channel 3 ( no voltage out from channel 3 )
       
       dac.analogWrite(2,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
      dac.setVref(2, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
      dac.setGain(2, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
      dac.setPowerDown(2, 0); // Power down channel 3 ( no voltage out from channel 3 )
       
        dac.analogWrite(3,4000); // write to input register of a DAC. Channel 0-3, Value 0-4095
      dac.setVref(3, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
      dac.setGain(3, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
      dac.setPowerDown(3, 0); // Power down channel 3 ( no voltage out from channel 3 )
     
        //////////////////////4728 SETUP ////////////////////////////////

     
    }


     





    void loop() {
        dac.analogWrite(0,mcpVoltOut);//write to input register of a DAC. Channel 0-3, Value 0-4095
         
         
      while (1); // reduces clock jitter
    }

    // timer1 interrupt routine - all data processed here
    ISR(TIMER1_COMPA_vect, ISR_NAKED) { // dont store any registers

     counter=counter+1;  if (counter>80000){counter=0;};
     
     ////////IF YOU CHANGE THIS VALUE AND RELOAD THE SKETCH THEN IT UPDATES THE MCP4728//////
     mcpVoltOut = 1500;// writes to dac.analogWrite(0,mcpVoltOut); IN VOID LOOP
     
     /////////////////TRIED TYING THIS TO COUNTER USING////////////
     //mcpVoltOut = counter/20;
     //////////////BUT IT DOESN'T WORK UPDATE///////////
     
     
     
     if (location > 260000){//lets the wave form finish before switching to eliminate clicks i think
     
     if (counter > 0 && counter < 20000) {arraypointer = 0; };
     if (counter > 20000 && counter < 40000) {arraypointer = 1;};
      if (counter > 40000 && counter < 60000) {arraypointer = 2;};
       if (counter > 60000 && counter < 80000) {arraypointer = 3;};
     
      };  //EO to eliminate click I think
     
   

     if (arraypointer==0){ selection = &wave1[0];};

    if (arraypointer==1){ selection = &wave2[1];};

    if (arraypointer==2){ selection = &wave3[2];};

    if (arraypointer==3){ selection = &wave4[3];};




      // &'s are necessary on data_in variables
      AudioCodec_data(&left_in, &right_in, left_out, right_out);
     
      // create some temporary variables
      // these tend to work faster than using the main data variables
      // as they arent fetched and stored all the time
      unsigned int temp1;
      unsigned int temp2;
      unsigned int temp3;

     
      // convert input signal to unsigned integer
      // input is inverted, so it needs to be flipped as well
      temp1 = 0x8000 - left_in;
      // fetch lookup table entry to convert CV to frequency
      temp2 = pgm_read_word_near(logtable + (temp1 >> 8));
      // fetch next value to do interpolation
      temp3 = pgm_read_word_near(logtable + ((temp1 >> 8) + 1));
      // interpolate result
     
      unsigned char frac = (temp1 & 0x00ff); // fetch the lower 8b
      // we are done with temp1, so we can reuse it here
      MultiU16X8toH16(temp1, temp3, frac);
      // scaled sample 2 is now in temp1, and since we are done with
      // temp3, we can reuse it for the next result
      MultiU16X8toH16(temp3, temp2, 0xff - frac);
      // temp3 now has the scaled sample 1
      temp1 += temp3; // add samples together to get an average
      // our frequency value is now in temp1
     
      // create a variable frequency sinewave
      // step through table at rate determined by temp1
      location += temp1;
      // if weve gone over the table boundary -> loop back
      location &= 0x0003ffff; // fast way for 2^n values
      // fetch a sample from the lookup table
      temp1 = location >> 8;  // bit shift it
      temp2 = pgm_read_word_near(selection + temp1);
      // get next value for interpolation
      temp3 = pgm_read_word_near(selection + ((temp1 + 1) & 0x03ff));
      // interpolate result
      frac = (location & 0x000000ff); // fetch the lower 8b
      // we are done with temp1, so we can reuse it here
      MultiSU16X8toH16(temp1, temp3, frac);
      // scaled sample 2 is now in temp1, and since we are done with
      // temp3, we can reuse it for the next result
      MultiSU16X8toH16(temp3, temp2, 0xff - frac);
      // temp3 now has the scaled sample 1
      temp1 += temp3; // add samples together to get an average
      // our sinewave value is now in temp1
     
      left_out = temp1; // put sinusoid out on left channel
      right_out = -temp1; // put inverted version out on right chanel
     

      reti(); // dont forget to return from the interrupt
    }






michaelmartin2758
 
Posts: 4
Joined: Fri Aug 09, 2013 10:56 pm

Re: VCO

Postby guest » Wed Aug 28, 2013 7:37 am

sorry, totally missed the end of your last post. i made the following modifications:

1. got rid of NAKED, which makes it so interrupts can work concurrently with stuff in main
2. got rid of reti, which is not needed if not using NAKED
3. declared your variable volatile, which lets the compiler know it is being modified someplace it has no knowledge of - the interrupt.

this may not work, though, as the codec uses the SPI bus, so there will be a conflict. there is a chip select line on the codec, so you might be able to toggle between them.

Code: Select all
// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1kHz sample rate
#define ADCS 0 // dont use ADCs
#define ADCHPD 1 // high pass filter disabled -> DC coupled



// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>
#include "mcp4728.h"    // Mcp4728
 mcp4728 dac = mcp4728(1); // instantiate mcp4728 object, Device ID = 1



// create data variables for audio transfer
// even though there is no input needed, the codec requires stereo data
int left_in = 0; // in from codec (LINE_IN)
int right_in = 0;
int left_out = 0; // out to codec (HP_OUT)
int right_out = 0;

int *selection; //Array selection
int arraypointer = 0; //array pointer
unsigned long counter = 0; //counter for wave switcher
volatile unsigned long mcpVoltOut = 4000; // anything changed in an interrupt
//which gets accessed in loop must be declared volatile




//Wave 1
  PROGMEM prog_int16_t wave1 [1024]  = {

1105, 1401, 1696, 1992, 2288, 2583, 2879, 3128, 3289, 3451, 3613, 3775, 3936, 4098, 4246, 4387, 4529, 4670, 4812, 4954, 5093, 5197, 5302, 5406, 5510, 5614, 5718, 5895, 6179, 6464, 6749, 7033, 7318, 7603, 7988, 8406, 8825, 9243, 9661, 10079, 10479, 10721, 10963, 11205, 11447, 11688, 11930, 12240, 12631, 13021, 13412, 13803, 14194, 14585, 15067, 15571, 16076, 16580, 17085, 17589, 18039, 18193, 18347, 18501, 18655, 18809, 18963, 19042, 19049, 19055, 19062, 19069, 19075, 19082, 19109, 19140, 19170, 19201, 19231, 19262, 19258, 19121, 18985, 18849, 18712, 18576, 18440, 18219, 17933, 17646, 17359, 17072, 16785, 16498, 16451, 16428, 16404, 16381, 16357, 16334, 16272, 16101, 15930, 15759, 15589, 15418, 15247, 14947, 14565, 14183, 13800, 13418, 13036, 12654, 12417, 12185, 11954, 11723, 11491, 11260, 11073, 10984, 10895, 10805, 10716, 10627, 10538, 10452, 10367, 10282, 10198, 10113, 10029, 9942, 9693, 9445, 9196, 8947, 8699, 8450, 8209, 7981, 7753, 7526, 7298, 7070, 6843, 6701, 6593, 6486, 6378, 6271, 6163, 6073, 6234, 6394, 6555, 6715, 6876, 7037, 7207, 7393, 7579, 7764, 7950, 8135, 8321, 8413, 8476, 8539, 8602, 8665, 8728, 8790, 8846, 8902, 8958, 9014, 9070, 9125, 9276, 9534, 9792, 10050, 10308, 10565, 10823, 11101, 11384, 11667, 11949, 12232, 12514, 12772, 12910, 13047, 13185, 13323, 13460, 13598, 13648, 13616, 13585, 13554, 13522, 13491, 13459, 13532, 13621, 13709, 13798, 13886, 13974, 14078, 14237, 14395, 14554, 14712, 14870, 15029, 15176, 15314, 15453, 15591, 15730, 15868, 16007, 16154, 16302, 16450, 16598, 16746, 16894, 16990, 16947, 16903, 16860, 16817, 16774, 16730, 16637, 16514, 16391, 16269, 16146, 16023, 15900, 15578, 15250, 14923, 14595, 14268, 13940, 13553, 13043, 12532, 12021, 11511, 11000, 10490, 9904, 9281, 8659, 8037, 7415, 6792, 6172, 5615, 5058, 4500, 3943, 3386, 2829, 2317, 1879, 1441, 1003, 565, 128, -310, -519, -643, -766, -890, -1013, -1137, -1238, -1082, -925, -769, -612, -456, -299, -144, 8, 161, 313, 466, 618, 771, 844, 894, 944, 995, 1045, 1095, 1158, 1304, 1449, 1595, 1741, 1886, 2032, 2139, 2204, 2270, 2336, 2401, 2467, 2532, 2379, 2182, 1985, 1788, 1590, 1393, 1199, 1022, 845, 667, 490, 313, 136, -61, -276, -490, -704, -918, -1132, -1346, -1573, -1802, -2031, -2259, -2488, -2717, -2894, -2902, -2911, -2919, -2927, -2936, -2944, -2852, -2689, -2526, -2363, -2199, -2036, -1873, -1757, -1644, -1530, -1417, -1304, -1191, -1108, -1096, -1085, -1074, -1063, -1051, -1040, -948, -809, -670, -531, -392, -254, -115, 518, 1157, 1796, 2435, 3074, 3713, 4236, 4533, 4831, 5128, 5426, 5723, 6020, 5867, 5511, 5155, 4798, 4442, 4085, 3733, 3480, 3227, 2974, 2721, 2468, 2215, 2078, 2122, 2166, 2210, 2253, 2297, 2341, 2409, 2485, 2561, 2637, 2713, 2789, 2818, 2380, 1943, 1506, 1069, 632, 194, -366, -1081, -1797, -2513, -3228, -3944, -4659, -4952, -5133, -5314, -5496, -5677, -5859, -5931, -5349, -4767, -4185, -3603, -3021, -2439, -2010, -1737, -1464, -1191, -919, -646, -373, -724, -1191, -1657, -2123, -2589, -3055, -3571, -4290, -5010, -5729, -6449, -7169, -7888, -8441, -8857, -9272, -9687, -10102, -10518, -10933, -10742, -10481, -10221, -9960, -9700, -9439, -9238, -9219, -9200, -9181, -9162, -9143, -9124, -9828, -11016, -12205, -13394, -14582, -15771, -16960, -18127, -19293, -20459, -21625, -22792, -23958, -24556, -23823, -23091, -22358, -21626, -20893, -20161, -19332, -18451, -17570, -16689, -15808, -14927, -14046, -13680, -13314, -12947, -12581, -12215, -11848, -11610, -11608, -11606, -11604, -11601, -11599, -11597, -12075, -12756, -13437, -14118, -14799, -15480, -16068, -14973, -13879, -12785, -11690, -10596, -9502, -8273, -6844, -5415, -3986, -2558, -1129, 300, -293, -1546, -2799, -4052, -5305, -6558, -7789, -8830, -9872, -10914, -11956, -12997, -14039, -14119, -13046, -11974, -10901, -9829, -8756, -7684, -6779, -5914, -5049, -4185, -3320, -2455, -1760, -1979, -2198, -2418, -2637, -2856, -3075, -3112, -2974, -2835, -2696, -2557, -2418, -2280, -1586, -800, -14, 772, 1558, 2343, 3010, 3222, 3434, 3647, 3859, 4071, 4283, 4437, 4543, 4649, 4756, 4862, 4969, 5075, 4810, 4508, 4206, 3904, 3602, 3301, 2993, 2668, 2344, 2019, 1695, 1370, 1046, 1105, 1408, 1711, 2014, 2317, 2620, 2923, 2684, 2424, 2164, 1904, 1644, 1384, 1067, 626, 184, -257, -699, -1140, -1582, -1645, -1517, -1389, -1261, -1133, -1005, -875, -602, -328, -55, 219, 492, 766, 908, 822, 736, 650, 564, 478, 393, 329, 275, 221, 167, 113, 59, 36, 446, 856, 1266, 1675, 2085, 2495, 2928, 3394, 3860, 4325, 4791, 5257, 5722, 5804, 5769, 5734, 5699, 5664, 5630, 5581, 5432, 5283, 5134, 4984, 4835, 4686, 4688, 4861, 5033, 5206, 5379, 5552, 5725, 5823, 5904, 5986, 6068, 6149, 6231, 6274, 6130, 5986, 5841, 5697, 5553, 5409, 5317, 5272, 5228, 5184, 5140, 5096, 5052, 4835, 4592, 4349, 4107, 3864, 3621, 3471, 3645, 3819, 3993, 4167, 4342, 4516, 4912, 5474, 6036, 6598, 7160, 7723, 8285, 8026, 7698, 7371, 7043, 6716, 6388, 5924, 5095, 4266, 3437, 2608, 1780, 951, 513, 310, 107, -95, -298, -501, -704, -556, -400, -243, -87, 70, 226, 285, 140, -4, -148, -293, -437, -582, -813, -1087, -1361, -1634, -1908, -2182, -2457, -2815, -3173, -3530, -3888, -4245, -4603, -4864, -4966, -5069, -5171, -5273, -5375, -5478, -5342, -5118, -4894, -4670, -4446, -4222, -4052, -4516, -4980, -5444, -5907, -6371, -6835, -7557, -8623, -9689, -10755, -11821, -12887, -13953, -14360, -14582, -14804, -15026, -15248, -15470, -15651, -15565, -15478, -15392, -15306, -15219, -15133, -15432, -16147, -16862, -17577, -18292, -19007, -19722, -20197, -20624, -21052, -21479, -21906, -22333, -22565, -21925, -21284, -20644, -20004, -19364, -18723, -18273, -17989, -17704, -17420, -17135, -16851, -16567, -16869, -17248, -17627, -18006, -18385, -18764, -19014, -18844, -18673, -18503, -18333, -18162, -17992, -17721, -17378, -17036, -16693, -16351, -16008, -15666, -15487, -15319, -15151, -14982, -14814, -14646, -14489, -14358, -14226, -14095, -13963, -13832, -13701, -13852, -14165, -14478, -14790, -15103, -15415, -15728, -15897, -16065, -16232, -16399, -16567, -16734, -16716, -16337, -15958, -15579, -15199, -14820, -14441, -14127, -13841, -13556, -13271, -12986, -12701, -12425, -12371, -12317, -12263, -12209, -12156, -12102, -11947, -11637, -11326, -11015, -10704, -10393, -10083, -9647, -9168, -8689, -8210, -7730, -7251, -6787, -6468, -6150, -5832, -5513, -5195, -4876, -4627, -4465, -4303, -4140, -3978, -3816, -3654, -3644, -3673, -3703, -3732, -3762, -3791, -3810, -3765, -3720, -3675, -3631, -3586, -3541, -3612, -3802, -3992, -4182, -4372, -4562, -4752, -4913, -5068, -5224, -5379, -5535, -5690, -5734, -5321, -4908, -4496, -4083, -3670, -3257, -2979, -2814, -2648, -2482, -2317, -2151, -1986, -2188, -2433, -2677, -2922, -3166, -3411, -3582, -3530, -3477, -3425, -3373, -3321, -3269, -3157, -3007, -2856, -2705, -2555, -2404, -2253, -2163, -2076, -1989, -1902, -1816, -1729, -1559, -1198, -836, -475, -113, 248, 610, 819, 947, 1075, 1202, 1330, 1458,

};


//Wave 2
 PROGMEM prog_int16_t wave2 [1024]  = {

3144, 3388, 3631, 3875, 4118, 4362, 4606, 4848, 5089, 5330, 5571, 5812, 6053, 6287, 6472, 6657, 6842, 7027, 7211, 7396, 7542, 7669, 7796, 7922, 8049, 8176, 8307, 8451, 8594, 8737, 8881, 9024, 9168, 9270, 9362, 9454, 9547, 9639, 9731, 9852, 10025, 10198, 10371, 10544, 10716, 10889, 11162, 11444, 11726, 12008, 12289, 12571, 12840, 13096, 13351, 13606, 13862, 14117, 14367, 14469, 14572, 14674, 14777, 14879, 14982, 15094, 15213, 15332, 15451, 15570, 15689, 15811, 15948, 16085, 16222, 16360, 16497, 16634, 16495, 16247, 15999, 15751, 15503, 15255, 14914, 14331, 13747, 13164, 12580, 11996, 11413, 10809, 10201, 9593, 8985, 8377, 7769, 7242, 6837, 6432, 6027, 5622, 5218, 4813, 4494, 4179, 3865, 3550, 3235, 2921, 2672, 2485, 2297, 2110, 1923, 1736, 1587, 1915, 2243, 2570, 2898, 3225, 3553, 4019, 4564, 5109, 5654, 6199, 6745, 7268, 7704, 8139, 8574, 9010, 9445, 9880, 10149, 10362, 10576, 10790, 11004, 11218, 11345, 11284, 11223, 11162, 11101, 11040, 10979, 10859, 10731, 10603, 10475, 10347, 10218, 9999, 9659, 9320, 8981, 8641, 8302, 7963, 7418, 6872, 6326, 5780, 5234, 4688, 4297, 4030, 3764, 3498, 3231, 2965, 2706, 2502, 2298, 2093, 1889, 1685, 1481, 1104, 644, 184, -276, -737, -1197, -1639, -2022, -2405, -2788, -3171, -3554, -3937, -4246, -4534, -4823, -5112, -5401, -5690, -6008, -6380, -6751, -7123, -7495, -7867, -8238, -8480, -8710, -8939, -9168, -9398, -9627, -9629, -9376, -9123, -8870, -8617, -8364, -8111, -7888, -7665, -7441, -7218, -6995, -6772, -6680, -6679, -6678, -6677, -6677, -6676, -6668, -6624, -6579, -6535, -6490, -6446, -6402, -6552, -6782, -7012, -7242, -7473, -7703, -8058, -8752, -9446, -10140, -10834, -11528, -12222, -13274, -14399, -15524, -16649, -17774, -18899, -20030, -21172, -22313, -23454, -24595, -25736, -26877, -27434, -27959, -28484, -29009, -29535, -30060, -30285, -30222, -30159, -30096, -30033, -29969, -29895, -29670, -29446, -29221, -28996, -28771, -28547, -28139, -27623, -27107, -26590, -26074, -25558, -24923, -23775, -22626, -21478, -20330, -19182, -18033, -16851, -15657, -14464, -13270, -12076, -10882, -9884, -9323, -8761, -8200, -7639, -7078, -6517, -6454, -6468, -6481, -6494, -6508, -6521, -6578, -6692, -6807, -6921, -7036, -7151, -7265, -7242, -7217, -7191, -7166, -7141, -7116, -7193, -7354, -7515, -7676, -7837, -7998, -8174, -8482, -8790, -9098, -9406, -9714, -10022, -10111, -10092, -10073, -10053, -10034, -10015, -9893, -9420, -8948, -8476, -8004, -7532, -7059, -6548, -6025, -5503, -4981, -4458, -3936, -3446, -3017, -2587, -2158, -1729, -1300, -871, -438, -5, 427, 860, 1293, 1726, 2042, 2224, 2406, 2588, 2770, 2952, 3125, 2944, 2763, 2582, 2401, 2220, 2039, 1908, 1813, 1717, 1621, 1525, 1430, 1368, 1508, 1647, 1787, 1927, 2067, 2206, 2126, 1954, 1782, 1609, 1437, 1265, 1026, 600, 174, -251, -677, -1103, -1528, -1597, -1589, -1581, -1573, -1565, -1557, -1407, -1029, -651, -273, 105, 483, 861, 1257, 1654, 2051, 2449, 2846, 3243, 3548, 3762, 3976, 4189, 4403, 4616, 4815, 4785, 4755, 4725, 4696, 4666, 4636, 4592, 4540, 4488, 4436, 4384, 4332, 4360, 4748, 5135, 5523, 5910, 6298, 6685, 7065, 7442, 7819, 8197, 8574, 8951, 9224, 9258, 9292, 9326, 9360, 9394, 9428, 9577, 9744, 9911, 10078, 10245, 10412, 10721, 11225, 11730, 12234, 12739, 13243, 13747, 14262, 14777, 15293, 15808, 16323, 16838, 17108, 17170, 17232, 17294, 17357, 17419, 17448, 17178, 16908, 16638, 16368, 16098, 15828, 15120, 14186, 13253, 12319, 11385, 10452, 9529, 8647, 7764, 6882, 6000, 5117, 4235, 3657, 3166, 2675, 2184, 1692, 1201, 692, 148, -396, -939, -1483, -2027, -2571, -3196, -3830, -4464, -5098, -5732, -6366, -6747, -6829, -6911, -6993, -7075, -7157, -7224, -6490, -5756, -5022, -4289, -3555, -2821, -2330, -2016, -1702, -1388, -1074, -759, -533, -850, -1167, -1484, -1802, -2119, -2436, -2838, -3276, -3714, -4152, -4590, -5028, -5413, -5643, -5873, -6104, -6334, -6565, -6795, -7151, -7536, -7920, -8305, -8689, -9073, -9455, -9833, -10211, -10588, -10966, -11344, -11721, -11788, -11834, -11879, -11925, -11971, -12017, -11892, -11596, -11300, -11004, -10708, -10412, -10101, -9554, -9007, -8460, -7913, -7366, -6818, -6296, -5789, -5282, -4776, -4269, -3762, -3286, -2955, -2625, -2294, -1964, -1633, -1302, -1072, -877, -683, -488, -293, -99, 84, 239, 394, 549, 704, 859, 1014, 797, 518, 238, -41, -321, -600, -849, -1054, -1258, -1463, -1668, -1873, -2077, -1938, -1789, -1641, -1492, -1343, -1195, -1125, -1122, -1120, -1117, -1115, -1112, -1140, -1450, -1761, -2072, -2383, -2694, -3004, -3198, -3329, -3461, -3592, -3724, -3855, -3964, -3989, -4015, -4040, -4066, -4091, -4117, -4281, -4485, -4690, -4895, -5099, -5304, -5512, -5728, -5944, -6161, -6377, -6593, -6809, -7040, -7272, -7505, -7738, -7970, -8203, -8338, -8354, -8370, -8387, -8403, -8420, -8434, -8259, -8085, -7911, -7736, -7562, -7388, -7073, -6652, -6232, -5812, -5392, -4972, -4528, -3929, -3330, -2731, -2132, -1533, -934, -307, 331, 969, 1608, 2246, 2884, 3491, 4004, 4516, 5028, 5541, 6054, 6566, 6977, 7364, 7752, 8139, 8526, 8914, 9268, 9566, 9864, 10162, 10460, 10758, 11056, 11129, 11185, 11242, 11298, 11354, 11410, 11329, 11104, 10879, 10655, 10430, 10206, 9984, 9818, 9653, 9487, 9321, 9156, 8990, 8952, 8995, 9038, 9082, 9125, 9168, 9241, 9463, 9685, 9907, 10128, 10350, 10572, 10790, 11006, 11223, 11440, 11656, 11873, 12052, 12139, 12226, 12313, 12400, 12487, 12574, 12663, 12752, 12841, 12930, 13020, 13109, 13133, 13065, 12996, 12928, 12859, 12791, 12722, 12517, 12308, 12098, 11889, 11680, 11470, 11167, 10782, 10396, 10010, 9624, 9238, 8840, 8319, 7797, 7276, 6755, 6233, 5712, 5260, 4846, 4432, 4019, 3605, 3191, 2843, 2750, 2656, 2562, 2468, 2374, 2281, 2316, 2391, 2465, 2539, 2614, 2688, 2739, 2740, 2742, 2743, 2745, 2746, 2747, 2649, 2537, 2425, 2314, 2202, 2090, 1980, 1870, 1761, 1651, 1542, 1433, 1324, 1289, 1255, 1220, 1186, 1151, 1117, 1059, 983, 906, 830, 754, 678, 566, 205, -156, -517, -878, -1239, -1600, -1883, -2130, -2377, -2625, -2872, -3119, -3264, -3092, -2921, -2750, -2578, -2407, -2235, -2093, -1957, -1822, -1686, -1551, -1415, -1372, -1489, -1606, -1723, -1840, -1958, -2075, -2123, -2165, -2208, -2250, -2293, -2336, -2374, -2407, -2440, -2473, -2506, -2540, -2586, -2909, -3232, -3556, -3879, -4202, -4526, -4914, -5345, -5776, -6206, -6637, -7068, -7468, -7713, -7958, -8203, -8447, -8692, -8937, -8992, -8975, -8957, -8940, -8922, -8905, -8894, -8899, -8905, -8910, -8915, -8921, -8926, -8904, -8877, -8850, -8823, -8796, -8770, -8698, -8561, -8424, -8287, -8150, -8013, -7876, -7577, -7272, -6967, -6662, -6357, -6052, -5765, -5496, -5226, -4956, -4686, -4417, -4176, -4253, -4330, -4407, -4484, -4561, -4639, -4796, -4999, -5202, -5405, -5608, -5811, -5960, -5898, -5837, -5775, -5713, -5652, -5590, -5425, -5227, -5029, -4831, -4633, -4435, -4276, -4199, -4122, -4045, -3968, -3891, -3814, -3683, -3544, -3405, -3267, -3128, -2989, -2775, -2465, -2155, -1845, -1535, -1225,

};

//Wave 3
PROGMEM prog_int16_t wave3 [1024]  = {
 
1112, 1448, 1784, 2120, 2455, 2791, 3127, 3401, 3561, 3721, 3880, 4040, 4199, 4359, 4404, 4400, 4396, 4391, 4387, 4383, 4376, 4311, 4246, 4181, 4116, 4051, 3986, 4079, 4405, 4732, 5058, 5384, 5711, 6037, 6273, 6479, 6685, 6891, 7097, 7303, 7460, 7196, 6933, 6669, 6405, 6141, 5878, 5720, 5690, 5661, 5631, 5601, 5571, 5541, 5856, 6255, 6654, 7053, 7453, 7852, 8202, 8293, 8383, 8473, 8563, 8654, 8744, 8767, 8724, 8682, 8640, 8598, 8555, 8513, 8635, 8785, 8934, 9084, 9233, 9383, 9529, 9664, 9798, 9933, 10067, 10202, 10336, 10458, 10569, 10681, 10792, 10903, 11015, 11126, 11148, 11162, 11175, 11189, 11203, 11216, 11183, 11017, 10850, 10684, 10517, 10351, 10185, 10044, 9921, 9797, 9673, 9549, 9425, 9302, 9316, 9335, 9355, 9374, 9394, 9413, 9387, 9260, 9134, 9007, 8880, 8753, 8627, 8432, 8204, 7975, 7746, 7518, 7289, 7063, 7057, 7051, 7045, 7039, 7034, 7028, 7074, 7210, 7347, 7484, 7621, 7758, 7894, 7935, 7937, 7940, 7942, 7944, 7947, 7939, 7782, 7626, 7469, 7313, 7156, 7000, 6898, 6872, 6846, 6820, 6795, 6769, 6743, 6916, 7149, 7383, 7616, 7850, 8083, 8299, 8380, 8461, 8542, 8623, 8704, 8785, 8768, 8641, 8514, 8387, 8259, 8132, 8005, 7899, 7798, 7697, 7596, 7495, 7394, 7323, 7394, 7465, 7537, 7608, 7679, 7751, 7772, 7748, 7723, 7698, 7674, 7649, 7625, 7407, 7160, 6914, 6667, 6421, 6174, 5916, 5616, 5316, 5016, 4716, 4416, 4117, 3920, 3801, 3682, 3563, 3444, 3324, 3205, 3251, 3310, 3369, 3428, 3487, 3546, 3543, 3372, 3202, 3032, 2861, 2691, 2521, 2253, 1927, 1601, 1275, 949, 623, 297, 230, 169, 109, 48, -13, -73, -51, 144, 339, 533, 728, 923, 1118, 1234, 1313, 1392, 1470, 1549, 1627, 1704, 1688, 1672, 1656, 1640, 1623, 1607, 1685, 1916, 2147, 2378, 2608, 2840, 3070, 3507, 4021, 4535, 5048, 5562, 6076, 6572, 6862, 7152, 7443, 7733, 8023, 8314, 8428, 8307, 8186, 8065, 7944, 7823, 7702, 7436, 7130, 6824, 6517, 6211, 5905, 5578, 5111, 4644, 4178, 3711, 3245, 2778, 2142, 1323, 504, -315, -1134, -1953, -2772, -3686, -4618, -5550, -6482, -7414, -8347, -9232, -9909, -10586, -11262, -11939, -12615, -13292, -13744, -13998, -14252, -14506, -14761, -15015, -15269, -15064, -14798, -14531, -14265, -13999, -13733, -13413, -12919, -12425, -11931, -11437, -10943, -10449, -9968, -9497, -9025, -8553, -8082, -7610, -7139, -6689, -6240, -5791, -5342, -4893, -4445, -4021, -3662, -3302, -2943, -2583, -2224, -1864, -1711, -1676, -1640, -1605, -1570, -1534, -1499, -1705, -1914, -2123, -2331, -2540, -2749, -2921, -3022, -3123, -3223, -3324, -3424, -3525, -3569, -3588, -3607, -3625, -3644, -3663, -3681, -3690, -3699, -3709, -3718, -3727, -3736, -3763, -3815, -3868, -3920, -3973, -4025, -4078, -4103, -4118, -4133, -4148, -4163, -4178, -4186, -4132, -4078, -4023, -3969, -3915, -3860, -3874, -3975, -4075, -4176, -4276, -4377, -4477, -4545, -4604, -4663, -4722, -4781, -4840, -4878, -4796, -4713, -4630, -4547, -4464, -4382, -4215, -3962, -3710, -3457, -3204, -2952, -2699, -2410, -2114, -1819, -1523, -1227, -931, -660, -492, -323, -155, 14, 182, 351, 536, 736, 935, 1135, 1334, 1533, 1733, 2076, 2436, 2796, 3156, 3516, 3876, 4189, 4362, 4535, 4708, 4880, 5053, 5226, 5196, 5030, 4864, 4697, 4531, 4365, 4199, 4150, 4108, 4065, 4023, 3980, 3938, 3885, 3807, 3729, 3652, 3574, 3496, 3419, 2995, 2384, 1773, 1163, 552, -59, -670, -1600, -2531, -3462, -4393, -5323, -6254, -7200, -8173, -9147, -10120, -11093, -12067, -13040, -13976, -14895, -15815, -16734, -17654, -18573, -19470, -19954, -20439, -20923, -21408, -21892, -22376, -22616, -22494, -22372, -22250, -22129, -22007, -21885, -21524, -21084, -20645, -20206, -19767, -19328, -18868, -18235, -17601, -16968, -16334, -15701, -15067, -14335, -13485, -12635, -11785, -10935, -10086, -9236, -8752, -8357, -7961, -7566, -7170, -6775, -6506, -6917, -7328, -7739, -8150, -8561, -8972, -9438, -9956, -10475, -10993, -11512, -12030, -12549, -12583, -12537, -12491, -12445, -12399, -12353, -12308, -12271, -12233, -12195, -12157, -12120, -12082, -12153, -12309, -12466, -12622, -12778, -12934, -13091, -12730, -12318, -11906, -11494, -11082, -10670, -10143, -9294, -8444, -7594, -6744, -5895, -5045, -4286, -3586, -2886, -2186, -1485, -785, -85, 53, 169, 284, 400, 516, 631, 595, 223, -149, -521, -893, -1265, -1637, -1800, -1858, -1915, -1973, -2030, -2088, -2138, -1629, -1121, -613, -105, 404, 912, 1173, 1003, 834, 664, 494, 325, 155, -540, -1444, -2348, -3252, -4156, -5060, -5905, -5912, -5919, -5926, -5933, -5940, -5947, -5730, -5198, -4665, -4133, -3601, -3069, -2537, -2553, -2735, -2917, -3100, -3282, -3465, -3665, -4000, -4335, -4670, -5005, -5340, -5675, -5835, -5799, -5762, -5725, -5689, -5652, -5615, -5246, -4804, -4362, -3919, -3477, -3035, -2544, -1816, -1088, -361, 367, 1095, 1823, 2302, 2553, 2804, 3054, 3305, 3556, 3806, 3429, 2959, 2489, 2018, 1548, 1078, 750, 924, 1098, 1272, 1446, 1620, 1793, 2510, 3634, 4757, 5880, 7003, 8126, 9249, 9597, 9880, 10163, 10446, 10730, 11013, 11091, 10625, 10159, 9694, 9228, 8762, 8296, 8379, 8791, 9204, 9617, 10029, 10442, 10854, 12014, 13193, 14371, 15550, 16729, 17908, 18710, 18734, 18758, 18782, 18806, 18829, 18853, 17964, 16638, 15312, 13986, 12660, 11334, 10026, 9354, 8682, 8009, 7337, 6665, 5993, 5683, 5968, 6254, 6540, 6826, 7112, 7398, 7507, 7551, 7595, 7639, 7682, 7726, 7734, 7319, 6904, 6489, 6074, 5659, 5244, 4802, 4322, 3843, 3364, 2885, 2405, 1926, 2071, 2392, 2713, 3033, 3354, 3675, 4075, 4999, 5923, 6846, 7770, 8694, 9618, 9922, 9559, 9196, 8832, 8469, 8106, 7743, 6317, 4677, 3037, 1397, -242, -1882, -3256, -3437, -3618, -3800, -3981, -4163, -4344, -3990, -3167, -2344, -1522, -699, 124, 946, 534, -40, -614, -1188, -1762, -2336, -2940, -3639, -4339, -5038, -5738, -6437, -7137, -7212, -6846, -6479, -6112, -5746, -5379, -5012, -4270, -3502, -2735, -1967, -1199, -431, 239, 667, 1095, 1523, 1951, 2379, 2807, 2859, 2697, 2535, 2373, 2211, 2049, 1887, 1369, 847, 325, -198, -720, -1242, -1522, -1329, -1137, -944, -751, -558, -365, 58, 585, 1113, 1640, 2167, 2694, 3178, 2614, 2050, 1487, 923, 359, -205, -859, -1653, -2447, -3241, -4035, -4829, -5623, -5780, -5715, -5650, -5585, -5520, -5455, -5350, -4859, -4368, -3877, -3386, -2895, -2404, -2166, -2247, -2328, -2409, -2490, -2571, -2652, -3167, -3795, -4423, -5052, -5680, -6308, -6855, -6921, -6987, -7053, -7118, -7184, -7250, -6951, -6279, -5607, -4935, -4263, -3592, -2920, -2626, -2402, -2177, -1953, -1729, -1504, -1431, -1975, -2520, -3064, -3609, -4154, -4698, -5097, -5374, -5652, -5930, -6207, -6485, -6762, -6391, -5946, -5500, -5055, -4609, -4164, -3733, -3347, -2960, -2574, -2187, -1801, -1414, -1443, -1750, -2058, -2365, -2672, -2980, -3287, -3719, -4158, -4597, -5036, -5475, -5914, -6083, -5618, -5154, -4690, -4226, -3762, -3298, -2829, -2357, -1886, -1414, -943, -1297,

};

//Wave 4
PROGMEM prog_int16_t wave4 [1024]  = {
1381, 1173, 964, 756, 548, 339, 143, -16, -176, -336, -495, -655, -621, -388, -156, 76, 308, 541, 761, 976, 1192, 1407, 1623, 1838, 1754, 1666, 1578, 1490, 1402, 1295, 1127, 959, 791, 622, 454, 390, 436, 482, 529, 575, 621, 887, 1234, 1581, 1928, 2275, 2622, 2808, 2991, 3173, 3356, 3538, 3667, 3612, 3557, 3502, 3447, 3392, 3523, 3860, 4198, 4536, 4873, 5211, 5791, 6465, 7139, 7813, 8487, 9161, 9536, 9900, 10264, 10628, 10992, 11295, 11372, 11449, 11526, 11603, 11680, 11772, 11880, 11988, 12096, 12204, 12313, 12413, 12509, 12606, 12702, 12799, 12895, 12922, 12945, 12968, 12990, 13013, 12990, 12783, 12577, 12371, 12164, 11958, 11715, 11426, 11138, 10850, 10562, 10274, 10187, 10188, 10188, 10189, 10189, 10190, 10221, 10254, 10287, 10320, 10353, 10336, 10108, 9880, 9653, 9425, 9197, 8960, 8711, 8461, 8212, 7962, 7712, 7591, 7528, 7464, 7401, 7338, 7275, 7310, 7352, 7394, 7436, 7478, 7496, 7405, 7315, 7225, 7134, 7044, 6895, 6668, 6440, 6213, 5985, 5758, 5643, 5583, 5523, 5464, 5404, 5344, 5359, 5380, 5402, 5423, 5444, 5425, 5207, 4989, 4771, 4553, 4334, 4070, 3742, 3413, 3084, 2756, 2427, 2143, 1881, 1619, 1357, 1096, 834, 585, 338, 91, -157, -404, -622, -682, -743, -803, -864, -924, -922, -829, -736, -643, -550, -457, -408, -381, -355, -328, -302, -275, -118, 55, 227, 399, 571, 758, 1032, 1307, 1581, 1855, 2130, 2331, 2420, 2510, 2599, 2688, 2778, 2773, 2715, 2657, 2599, 2542, 2484, 2367, 2242, 2118, 1993, 1869, 1748, 1657, 1565, 1474, 1382, 1291, 1258, 1319, 1380, 1441, 1502, 1563, 1600, 1623, 1646, 1669, 1691, 1714, 1667, 1611, 1555, 1498, 1442, 1408, 1531, 1654, 1777, 1900, 2022, 2177, 2385, 2593, 2801, 3009, 3217, 3350, 3437, 3524, 3611, 3698, 3785, 3812, 3829, 3846, 3863, 3880, 3897, 3920, 3943, 3966, 3989, 4012, 4067, 4178, 4290, 4401, 4513, 4624, 4747, 4878, 5008, 5138, 5269, 5399, 5396, 5371, 5345, 5319, 5294, 5265, 5212, 5159, 5105, 5052, 4999, 4984, 5041, 5098, 5155, 5212, 5269, 5306, 5328, 5350, 5373, 5395, 5418, 5346, 5257, 5168, 5079, 4990, 4907, 4876, 4846, 4816, 4786, 4755, 4777, 4899, 5021, 5144, 5266, 5388, 5532, 5691, 5849, 6008, 6167, 6326, 6444, 6553, 6662, 6772, 6881, 6989, 7081, 7172, 7264, 7356, 7447, 7551, 7679, 7806, 7934, 8062, 8190, 8313, 8433, 8552, 8672, 8792, 8912, 8987, 9052, 9117, 9183, 9248, 9310, 9327, 9344, 9362, 9379, 9396, 9409, 9415, 9420, 9426, 9431, 9436, 9464, 9510, 9555, 9601, 9646, 9692, 9719, 9742, 9764, 9787, 9810, 9828, 9767, 9705, 9644, 9583, 9521, 9477, 9472, 9467, 9462, 9457, 9452, 9496, 9581, 9666, 9751, 9836, 9921, 10012, 10105, 10198, 10291, 10383, 10479, 10620, 10762, 10904, 11046, 11187, 11334, 11491, 11649, 11806, 11964, 12121, 12235, 12311, 12387, 12462, 12538, 12614, 12564, 12480, 12396, 12311, 12227, 12134, 11806, 11478, 11150, 10822, 10494, 10087, 9478, 8870, 8261, 7652, 7043, 6352, 5586, 4821, 4055, 3290, 2524, 1839, 1176, 513, -150, -812, -1469, -1868, -2267, -2666, -3065, -3464, -3810, -4013, -4217, -4420, -4623, -4826, -4891, -4826, -4762, -4697, -4632, -4568, -4222, -3789, -3357, -2925, -2492, -2058, -1512, -966, -420, 127, 673, 1185, 1601, 2016, 2431, 2847, 3262, 3552, 3719, 3887, 4055, 4222, 4390, 4384, 4322, 4261, 4199, 4137, 4075, 3915, 3755, 3594, 3434, 3274, 3113, 2950, 2787, 2624, 2462, 2299, 2104, 1878, 1651, 1424, 1197, 970, 557, 78, -400, -878, -1356, -1834, -2262, -2689, -3117, -3544, -3971, -4327, -4451, -4576, -4700, -4825, -4950, -5104, -5290, -5477, -5663, -5849, -6035, -6343, -6696, -7048, -7400, -7753, -8105, -8147, -8182, -8218, -8253, -8288, -8195, -7664, -7133, -6602, -6071, -5540, -5043, -4584, -4125, -3666, -3206, -2747, -2510, -2357, -2205, -2053, -1901, -1749, -1484, -1215, -946, -677, -408, -149, 78, 304, 530, 757, 983, 1166, 1299, 1432, 1565, 1698, 1831, 1726, 1526, 1325, 1124, 923, 722, -214, -1183, -2151, -3119, -4088, -5059, -6042, -7024, -8007, -8990, -9972, -10772, -11351, -11929, -12507, -13086, -13664, -14486, -15414, -16342, -17269, -18197, -19124, -20344, -21579, -22815, -24051, -25287, -26401, -27008, -27615, -28222, -28829, -29436, -29658, -29390, -29122, -28855, -28587, -28320, -27680, -26871, -26062, -25253, -24444, -23635, -22677, -21708, -20739, -19771, -18802, -17846, -16947, -16049, -15150, -14252, -13353, -12466, -11594, -10723, -9851, -8979, -8107, -7531, -7095, -6659, -6223, -5787, -5351, -5409, -5508, -5607, -5706, -5805, -5943, -6268, -6594, -6919, -7245, -7571, -7999, -8569, -9140, -9710, -10281, -10851, -11207, -11453, -11700, -11947, -12194, -12441, -12033, -11563, -11093, -10623, -10153, -9673, -9143, -8612, -8081, -7551, -7020, -6515, -6047, -5580, -5112, -4644, -4177, -3626, -3031, -2436, -1841, -1246, -650, -392, -170, 52, 274, 497, 680, 642, 605, 567, 529, 492, 390, 193, -5, -203, -401, -598, -1055, -1655, -2255, -2854, -3454, -4054, -4295, -4492, -4689, -4886, -5082, -5190, -4736, -4282, -3828, -3374, -2920, -2620, -2568, -2515, -2462, -2409, -2356, -2624, -3077, -3531, -3985, -4439, -4893, -5144, -5367, -5591, -5814, -6037, -6227, -6181, -6135, -6089, -6043, -5998, -5997, -6071, -6146, -6220, -6295, -6369, -6664, -7092, -7521, -7949, -8378, -8806, -9098, -9370, -9642, -9914, -10186, -10356, -9746, -9136, -8527, -7917, -7307, -6607, -5746, -4886, -4026, -3166, -2306, -1769, -1440, -1111, -782, -453, -124, 111, 331, 550, 770, 990, 1224, 1583, 1941, 2300, 2659, 3017, 3352, 3641, 3930, 4219, 4508, 4797, 4922, 4936, 4950, 4965, 4979, 4993, 4646, 4234, 3821, 3409, 2996, 2582, 2146, 1711, 1276, 841, 405, 60, -113, -285, -458, -630, -803, -1131, -1568, -2005, -2442, -2879, -3316, -3998, -4728, -5458, -6188, -6918, -7623, -8049, -8475, -8901, -9327, -9753, -10064, -10139, -10214, -10289, -10364, -10439, -10352, -10146, -9939, -9733, -9526, -9320, -9045, -8754, -8464, -8174, -7883, -7596, -7344, -7093, -6841, -6589, -6338, -6022, -5569, -5116, -4662, -4209, -3756, -3289, -2810, -2332, -1854, -1376, -898, -823, -842, -861, -880, -899, -936, -1262, -1587, -1913, -2238, -2563, -2825, -2943, -3060, -3178, -3295, -3413, -3465, -3466, -3467, -3468, -3469, -3470, -3504, -3547, -3590, -3632, -3675, -3720, -3796, -3873, -3949, -4026, -4102, -4135, -4064, -3994, -3923, -3852, -3781, -3631, -3415, -3199, -2983, -2766, -2550, -2467, -2420, -2372, -2324, -2276, -2233, -2286, -2340, -2393, -2447, -2501, -2499, -2358, -2217, -2076, -1935, -1795, -1568, -1267, -966, -664, -363, -62, 270, 611, 953, 1294, 1635, 1973, 2223, 2473, 2722, 2972, 3222, 3443, 3589, 3734, 3880, 4025, 4171, 4309, 4440, 4571, 4702, 4833, 4964, 4856, 4675, 4494, 4314, 4133, 3949, 3522, 3095, 2668, 2241, 1814, 1428, 1155, 882, 609, 336, 64, -138, -270, -402, -534, -667, -799, -816, -796, -776, -756, -736,


};



// lookup table value location
unsigned long location; // this is a 32bit number
                        // the lower 8bits are the subsample fraction
                        // and the upper 24 bits contain the sample number
                       

// create logarithmic frequency lookup table
// PROGMEM stores the values in the program memory
// it is automatically included with AudioCodec.h
PROGMEM  prog_uint16_t logtable[]  = {
  // this file is stored in AudioCodec.h and is a 256 value
  // sinewave lookup table of unsigned 16bit integers
  // you can replace it with your own table if you like
  #include <logtable.inc>
};


void setup() {
 
 
  ///MOVED THIS TO START OF SETUP WHICH ENABLES THE MCP4728 TO WORK////////////
    AudioCodec_init(); // setup codec and microcontroller registers
   
   
   
   
  //////////////////////4728 SETUP ////////////////////////////////
 
  dac.begin();  // initialize i2c interface
  dac.vdd(5000); // set VDD(mV) of MCP4728 for correct conversion between LSB and Vout

  dac.analogWrite(0,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(0, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(0, 1); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(0, 0); // Power down channel 3 ( no voltage out from channel 3 )
 
 dac.analogWrite(1,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(1, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(1, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(1, 0); // Power down channel 3 ( no voltage out from channel 3 )
   
   dac.analogWrite(2,2000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(2, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(2, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(2, 0); // Power down channel 3 ( no voltage out from channel 3 )
   
    dac.analogWrite(3,4000); // write to input register of a DAC. Channel 0-3, Value 0-4095
  dac.setVref(3, 0); // set to use external voltage reference (=VDD, 2.7 - 5.5V)
  dac.setGain(3, 0); // set the gain of internal voltage reference ( 2.048V x 2 = 4.096V )
  dac.setPowerDown(3, 0); // Power down channel 3 ( no voltage out from channel 3 )
 
    //////////////////////4728 SETUP ////////////////////////////////

 
}


 





void loop() {
    dac.analogWrite(0,mcpVoltOut);//write to input register of a DAC. Channel 0-3, Value 0-4095
     
     
//  while (1); dont use this by itself, it just causes the code to hang
}

// timer1 interrupt routine - all data processed here
ISR(TIMER1_COMPA_vect) //, ISR_NAKED) cant use naked if there is stuff in loop

 counter=counter+1;  if (counter>80000){counter=0;};
 
 ////////IF YOU CHANGE THIS VALUE AND RELOAD THE SKETCH THEN IT UPDATES THE MCP4728//////
 mcpVoltOut = 1500;// writes to dac.analogWrite(0,mcpVoltOut); IN VOID LOOP
 
 /////////////////TRIED TYING THIS TO COUNTER USING////////////
 //mcpVoltOut = counter/20;
 //////////////BUT IT DOESN'T WORK UPDATE///////////
 
 
 
 if (location > 260000){//lets the wave form finish before switching to eliminate clicks i think
 
 if (counter > 0 && counter < 20000) {arraypointer = 0; };
 if (counter > 20000 && counter < 40000) {arraypointer = 1;};
  if (counter > 40000 && counter < 60000) {arraypointer = 2;};
   if (counter > 60000 && counter < 80000) {arraypointer = 3;};
 
  };  //EO to eliminate click I think
 
 

 if (arraypointer==0){ selection = &wave1[0];};

if (arraypointer==1){ selection = &wave2[1];};

if (arraypointer==2){ selection = &wave3[2];};

if (arraypointer==3){ selection = &wave4[3];};




  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
 
  // create some temporary variables
  // these tend to work faster than using the main data variables
  // as they arent fetched and stored all the time
  unsigned int temp1;
  unsigned int temp2;
  unsigned int temp3;

 
  // convert input signal to unsigned integer
  // input is inverted, so it needs to be flipped as well
  temp1 = 0x8000 - left_in;
  // fetch lookup table entry to convert CV to frequency
  temp2 = pgm_read_word_near(logtable + (temp1 >> 8));
  // fetch next value to do interpolation
  temp3 = pgm_read_word_near(logtable + ((temp1 >> 8) + 1));
  // interpolate result
 
  unsigned char frac = (temp1 & 0x00ff); // fetch the lower 8b
  // we are done with temp1, so we can reuse it here
  MultiU16X8toH16(temp1, temp3, frac);
  // scaled sample 2 is now in temp1, and since we are done with
  // temp3, we can reuse it for the next result
  MultiU16X8toH16(temp3, temp2, 0xff - frac);
  // temp3 now has the scaled sample 1
  temp1 += temp3; // add samples together to get an average
  // our frequency value is now in temp1
 
  // create a variable frequency sinewave
  // step through table at rate determined by temp1
  location += temp1;
  // if weve gone over the table boundary -> loop back
  location &= 0x0003ffff; // fast way for 2^n values
  // fetch a sample from the lookup table
  temp1 = location >> 8;  // bit shift it
  temp2 = pgm_read_word_near(selection + temp1);
  // get next value for interpolation
  temp3 = pgm_read_word_near(selection + ((temp1 + 1) & 0x03ff));
  // interpolate result
  frac = (location & 0x000000ff); // fetch the lower 8b
  // we are done with temp1, so we can reuse it here
  MultiSU16X8toH16(temp1, temp3, frac);
  // scaled sample 2 is now in temp1, and since we are done with
  // temp3, we can reuse it for the next result
  MultiSU16X8toH16(temp3, temp2, 0xff - frac);
  // temp3 now has the scaled sample 1
  temp1 += temp3; // add samples together to get an average
  // our sinewave value is now in temp1
 
  left_out = temp1; // put sinusoid out on left channel
  right_out = -temp1; // put inverted version out on right chanel
 

//  reti(); dont do this if NOT using ISR_NAKED
}

guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm


Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron