Code:
int delval; // globale Variablendeklaration
int i;
int k;
float rate;
int Sinustabele[128] = {
0 , 0 , 0 , 1 , 2 , 3 , 5 , 7 , 9 , 12 , 14 , 17 , 21 , 24 , 28 , 32,
36 , 41 , 46 , 51 , 56 , 61 , 66 , 72 , 78 , 83 , 89 , 95 , 101 , 107 , 114 , 120,
127 , 133 , 139 , 145 , 151 , 157 , 163 , 169 , 175 , 181 , 186 , 192 , 197 , 202 , 207 , 212,
216 , 221 , 225 , 228 , 232 , 235 , 238 , 241 , 244 , 246 , 248 , 250 , 251 , 252 , 253 , 253,
253 , 253 , 253 , 252 , 251 , 250 , 248 , 246 , 244 , 241 , 239 , 236 , 232 , 229 , 225 , 221,
216 , 212 , 207 , 202 , 197 , 192 , 187 , 181 , 175 , 169 , 164 , 158 , 151 , 145 , 139 , 133,
127 , 120 , 114 , 108 , 102 , 96 , 90 , 84 , 78 , 72 , 67 , 61 , 56 , 51 , 46 , 41,
37 , 33 , 28 , 25 , 21 , 18 , 15 , 12 , 9 , 7 , 5 , 3 , 2 , 1 , 0 , 0};
#define Led1 5
void main(void)
{
Port_DataDirBit(Led1,1);
Port_WriteBit(Led1,1);
rate = 6;
while(1)
{
Sound(35.3,1500); //vermutlich 700 Hz
Sound(6,1500);
}
Port_WriteBit(Led1,0);
}
void Sound(float Rate, int Time)
{
for(k=0; k<(1/(128/Rate))*Time; k++) // Berechne zyklen
{
for(i=0; i<128; i=i+Rate)
{
Timer_T0PWM(Sinustabele[i],PS0_8);
}
}
}
Kann sich einer Vortstellen wie man die Frequenz berechnen kann?
Lesezeichen