![](/media/cache/group/Display_Nokia_Insper_v01.jpg.50x50_q85.jpg)
gerador senoidal com look-up table 8 bit
Dependencies: mbed SeeedShieldBot BluetoothSerial
main.cpp@0:66bb2be784c0, 2021-06-07 (annotated)
- Committer:
- afm76
- Date:
- Mon Jun 07 16:27:58 2021 +0000
- Revision:
- 0:66bb2be784c0
Gerador senoidal com Look-up table
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
afm76 | 0:66bb2be784c0 | 1 | //-------------------------------------------------------------------------- |
afm76 | 0:66bb2be784c0 | 2 | // 2021-06 |
afm76 | 0:66bb2be784c0 | 3 | // Esse programa gera uma senoide com um conversor R2R e uma tabela de senos |
afm76 | 0:66bb2be784c0 | 4 | // a tabela foi construida no Excel para 90 passos de 1 grau, assim o valor |
afm76 | 0:66bb2be784c0 | 5 | // dos senos de 0 a 90 graus sera rebatido para 90 a 180, bem como 180 a 270 |
afm76 | 0:66bb2be784c0 | 6 | // e 270 a 360 graus |
afm76 | 0:66bb2be784c0 | 7 | // ------------------------------------------------------------------------- |
afm76 | 0:66bb2be784c0 | 8 | |
afm76 | 0:66bb2be784c0 | 9 | #include "mbed.h" |
afm76 | 0:66bb2be784c0 | 10 | |
afm76 | 0:66bb2be784c0 | 11 | float sinus[]{ |
afm76 | 0:66bb2be784c0 | 12 | 0, |
afm76 | 0:66bb2be784c0 | 13 | 0.017452406, |
afm76 | 0:66bb2be784c0 | 14 | 0.034899497, |
afm76 | 0:66bb2be784c0 | 15 | 0.052335956, |
afm76 | 0:66bb2be784c0 | 16 | 0.069756474, |
afm76 | 0:66bb2be784c0 | 17 | 0.087155743, |
afm76 | 0:66bb2be784c0 | 18 | 0.104528463, |
afm76 | 0:66bb2be784c0 | 19 | 0.121869343, |
afm76 | 0:66bb2be784c0 | 20 | 0.139173101, |
afm76 | 0:66bb2be784c0 | 21 | 0.156434465, |
afm76 | 0:66bb2be784c0 | 22 | 0.173648178, |
afm76 | 0:66bb2be784c0 | 23 | 0.190808995, |
afm76 | 0:66bb2be784c0 | 24 | 0.207911691, |
afm76 | 0:66bb2be784c0 | 25 | 0.224951054, |
afm76 | 0:66bb2be784c0 | 26 | 0.241921896, |
afm76 | 0:66bb2be784c0 | 27 | 0.258819045, |
afm76 | 0:66bb2be784c0 | 28 | 0.275637356, |
afm76 | 0:66bb2be784c0 | 29 | 0.292371705, |
afm76 | 0:66bb2be784c0 | 30 | 0.309016994, |
afm76 | 0:66bb2be784c0 | 31 | 0.325568154, |
afm76 | 0:66bb2be784c0 | 32 | 0.342020143, |
afm76 | 0:66bb2be784c0 | 33 | 0.35836795, |
afm76 | 0:66bb2be784c0 | 34 | 0.374606593, |
afm76 | 0:66bb2be784c0 | 35 | 0.390731128, |
afm76 | 0:66bb2be784c0 | 36 | 0.406736643, |
afm76 | 0:66bb2be784c0 | 37 | 0.422618262, |
afm76 | 0:66bb2be784c0 | 38 | 0.438371147, |
afm76 | 0:66bb2be784c0 | 39 | 0.4539905, |
afm76 | 0:66bb2be784c0 | 40 | 0.469471563, |
afm76 | 0:66bb2be784c0 | 41 | 0.48480962, |
afm76 | 0:66bb2be784c0 | 42 | 0.5, |
afm76 | 0:66bb2be784c0 | 43 | 0.515038075, |
afm76 | 0:66bb2be784c0 | 44 | 0.529919264, |
afm76 | 0:66bb2be784c0 | 45 | 0.544639035, |
afm76 | 0:66bb2be784c0 | 46 | 0.559192903, |
afm76 | 0:66bb2be784c0 | 47 | 0.573576436, |
afm76 | 0:66bb2be784c0 | 48 | 0.587785252, |
afm76 | 0:66bb2be784c0 | 49 | 0.601815023, |
afm76 | 0:66bb2be784c0 | 50 | 0.615661475, |
afm76 | 0:66bb2be784c0 | 51 | 0.629320391, |
afm76 | 0:66bb2be784c0 | 52 | 0.64278761, |
afm76 | 0:66bb2be784c0 | 53 | 0.656059029, |
afm76 | 0:66bb2be784c0 | 54 | 0.669130606, |
afm76 | 0:66bb2be784c0 | 55 | 0.68199836, |
afm76 | 0:66bb2be784c0 | 56 | 0.69465837, |
afm76 | 0:66bb2be784c0 | 57 | 0.707106781, |
afm76 | 0:66bb2be784c0 | 58 | 0.7193398, |
afm76 | 0:66bb2be784c0 | 59 | 0.731353702, |
afm76 | 0:66bb2be784c0 | 60 | 0.743144825, |
afm76 | 0:66bb2be784c0 | 61 | 0.75470958, |
afm76 | 0:66bb2be784c0 | 62 | 0.766044443, |
afm76 | 0:66bb2be784c0 | 63 | 0.777145961, |
afm76 | 0:66bb2be784c0 | 64 | 0.788010754, |
afm76 | 0:66bb2be784c0 | 65 | 0.79863551, |
afm76 | 0:66bb2be784c0 | 66 | 0.809016994, |
afm76 | 0:66bb2be784c0 | 67 | 0.819152044, |
afm76 | 0:66bb2be784c0 | 68 | 0.829037573, |
afm76 | 0:66bb2be784c0 | 69 | 0.838670568, |
afm76 | 0:66bb2be784c0 | 70 | 0.848048096, |
afm76 | 0:66bb2be784c0 | 71 | 0.857167301, |
afm76 | 0:66bb2be784c0 | 72 | 0.866025404, |
afm76 | 0:66bb2be784c0 | 73 | 0.874619707, |
afm76 | 0:66bb2be784c0 | 74 | 0.882947593, |
afm76 | 0:66bb2be784c0 | 75 | 0.891006524, |
afm76 | 0:66bb2be784c0 | 76 | 0.898794046, |
afm76 | 0:66bb2be784c0 | 77 | 0.906307787, |
afm76 | 0:66bb2be784c0 | 78 | 0.913545458, |
afm76 | 0:66bb2be784c0 | 79 | 0.920504853, |
afm76 | 0:66bb2be784c0 | 80 | 0.927183855, |
afm76 | 0:66bb2be784c0 | 81 | 0.933580426, |
afm76 | 0:66bb2be784c0 | 82 | 0.939692621, |
afm76 | 0:66bb2be784c0 | 83 | 0.945518576, |
afm76 | 0:66bb2be784c0 | 84 | 0.951056516, |
afm76 | 0:66bb2be784c0 | 85 | 0.956304756, |
afm76 | 0:66bb2be784c0 | 86 | 0.961261696, |
afm76 | 0:66bb2be784c0 | 87 | 0.965925826, |
afm76 | 0:66bb2be784c0 | 88 | 0.970295726, |
afm76 | 0:66bb2be784c0 | 89 | 0.974370065, |
afm76 | 0:66bb2be784c0 | 90 | 0.978147601, |
afm76 | 0:66bb2be784c0 | 91 | 0.981627183, |
afm76 | 0:66bb2be784c0 | 92 | 0.984807753, |
afm76 | 0:66bb2be784c0 | 93 | 0.987688341, |
afm76 | 0:66bb2be784c0 | 94 | 0.990268069, |
afm76 | 0:66bb2be784c0 | 95 | 0.992546152, |
afm76 | 0:66bb2be784c0 | 96 | 0.994521895, |
afm76 | 0:66bb2be784c0 | 97 | 0.996194698, |
afm76 | 0:66bb2be784c0 | 98 | 0.99756405, |
afm76 | 0:66bb2be784c0 | 99 | 0.998629535, |
afm76 | 0:66bb2be784c0 | 100 | 0.999390827, |
afm76 | 0:66bb2be784c0 | 101 | 0.999847695, |
afm76 | 0:66bb2be784c0 | 102 | 1, |
afm76 | 0:66bb2be784c0 | 103 | }; |
afm76 | 0:66bb2be784c0 | 104 | |
afm76 | 0:66bb2be784c0 | 105 | float VCC,t,T,tos; |
afm76 | 0:66bb2be784c0 | 106 | int f,freq; //, T; |
afm76 | 0:66bb2be784c0 | 107 | BusOut saida(D4, D5, D6, D7, D8, D9, D10, D11); |
afm76 | 0:66bb2be784c0 | 108 | |
afm76 | 0:66bb2be784c0 | 109 | int main() |
afm76 | 0:66bb2be784c0 | 110 | { |
afm76 | 0:66bb2be784c0 | 111 | VCC = 3.3; //used for determing offset voltage |
afm76 | 0:66bb2be784c0 | 112 | freq = 60; //freq. in Hz |
afm76 | 0:66bb2be784c0 | 113 | tos = 15.5; //time off-set in us (5.6ms / 350 = 15.5us) |
afm76 | 0:66bb2be784c0 | 114 | t = 30; |
afm76 | 0:66bb2be784c0 | 115 | T = t - tos; //T = 30; //(1/freq)/360; //time slice in seconds for the sinusoid routine |
afm76 | 0:66bb2be784c0 | 116 | |
afm76 | 0:66bb2be784c0 | 117 | while (true) |
afm76 | 0:66bb2be784c0 | 118 | { |
afm76 | 0:66bb2be784c0 | 119 | for (int i=0; i < 90; i++) //0 to 90 degree |
afm76 | 0:66bb2be784c0 | 120 | { |
afm76 | 0:66bb2be784c0 | 121 | f=74*((sinus[i]*VCC/2)+VCC/2)+10; //59 and 60 are adj for 1/4 of the FFh range(8bit) according to Vref |
afm76 | 0:66bb2be784c0 | 122 | saida = f; |
afm76 | 0:66bb2be784c0 | 123 | // printf("%1.3f", j); |
afm76 | 0:66bb2be784c0 | 124 | wait_us(T);//wait(T); |
afm76 | 0:66bb2be784c0 | 125 | } |
afm76 | 0:66bb2be784c0 | 126 | |
afm76 | 0:66bb2be784c0 | 127 | for (int i=90; i > 0; i--) //90 to 180 degree |
afm76 | 0:66bb2be784c0 | 128 | { |
afm76 | 0:66bb2be784c0 | 129 | f=74*((sinus[i]*VCC/2)+VCC/2)+10; |
afm76 | 0:66bb2be784c0 | 130 | saida = f; |
afm76 | 0:66bb2be784c0 | 131 | // printf("%1.3f", j); |
afm76 | 0:66bb2be784c0 | 132 | wait_us(T);//wait(T); |
afm76 | 0:66bb2be784c0 | 133 | } |
afm76 | 0:66bb2be784c0 | 134 | |
afm76 | 0:66bb2be784c0 | 135 | for (int i=0; i < 90; i++) //180 to 270 degree |
afm76 | 0:66bb2be784c0 | 136 | { |
afm76 | 0:66bb2be784c0 | 137 | f=74*((-sinus[i]*VCC/2)+VCC/2)+10; |
afm76 | 0:66bb2be784c0 | 138 | saida = f; |
afm76 | 0:66bb2be784c0 | 139 | // printf("%1.3f", j); |
afm76 | 0:66bb2be784c0 | 140 | wait_us(T);//wait(T); |
afm76 | 0:66bb2be784c0 | 141 | } |
afm76 | 0:66bb2be784c0 | 142 | |
afm76 | 0:66bb2be784c0 | 143 | for (int i=90; i > 0; i--) //270 to 360 degree |
afm76 | 0:66bb2be784c0 | 144 | { |
afm76 | 0:66bb2be784c0 | 145 | f=74*((-sinus[i]*VCC/2)+VCC/2)+10; |
afm76 | 0:66bb2be784c0 | 146 | saida = f; |
afm76 | 0:66bb2be784c0 | 147 | // printf("%1.3f", j); |
afm76 | 0:66bb2be784c0 | 148 | wait_us(T);//wait(T); |
afm76 | 0:66bb2be784c0 | 149 | } |
afm76 | 0:66bb2be784c0 | 150 | |
afm76 | 0:66bb2be784c0 | 151 | } |
afm76 | 0:66bb2be784c0 | 152 | } |