Shaojie Wang
/
singenerator
sinwave
sin.cpp
- Committer:
- bmdlh
- Date:
- 2014-02-15
- Revision:
- 0:1c98216d18eb
File content as of revision 0:1c98216d18eb:
#include "mbed.h" AnalogOut DA(PTE30); //AnalogIn AD(PTB1); Serial pc(USBTX, USBRX); // tx, rx float D2A; float sineTable[] = {0, 0.01745, 0.0349, 0.05234, 0.06976, 0.08716, 0.10453, 0.12187, 0.13917, 0.15643, 0.17365, 0.19081, 0.20791, 0.22495, 0.24192, 0.25882, 0.27564, 0.29237, 0.30902, 0.32557, 0.34202, 0.35837, 0.37461, 0.39073, 0.40674, 0.42262, 0.43837, 0.45399, 0.46947, 0.48481, 0.5, 0.51504, 0.52992, 0.54464, 0.55919, 0.57358, 0.58779, 0.60182, 0.61566, 0.62932, 0.64279, 0.65606, 0.66913, 0.682, 0.69466, 0.70711, 0.71934, 0.73135, 0.74314, 0.75471, 0.76604, 0.77715, 0.78801, 0.79864, 0.80902, 0.81915, 0.82904, 0.83867, 0.84805, 0.85717, 0.86603, 0.87462, 0.88295, 0.89101, 0.89879, 0.90631, 0.91355, 0.9205, 0.92718, 0.93358, 0.93969, 0.94552, 0.95106, 0.9563, 0.96126, 0.96593, 0.9703, 0.97437, 0.97815, 0.98163, 0.98481, 0.98769, 0.99027, 0.99255, 0.99452, 0.99619, 0.99756, 0.99863, 0.99939, 0.99985, 1}; // 0 to 90 degree int TableLength = sizeof(sineTable)/sizeof(sineTable[0]); int main(void) { //pc.printf("T-length=%d\n",TableLength); //Timer t; while(1){ //t.start(); for (int i=0; i<360; i++) { if(i<91){ D2A = sineTable[i]; } else if(i<181){ D2A = sineTable[181-i]; } else if(i<271){ D2A = - sineTable[i-181]; } else{ D2A = - sineTable[360-i]; } D2A = 0.5* (D2A + 1.0); DA.write(D2A); wait(0.01); pc.printf("%f ",D2A); } //t.stop(); //pc.printf("The time taken was %f seconds\n", t.read()); } }