Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: LUTs/LUTS.cpp
- Revision:
- 11:6ae098535da9
- Parent:
- 10:258a1eca02cc
- Child:
- 14:9cfe0041cc4e
--- a/LUTs/LUTS.cpp Wed May 06 19:51:22 2020 +0000
+++ b/LUTs/LUTS.cpp Thu May 07 12:22:39 2020 +0000
@@ -9,12 +9,13 @@
}
volatile uint16_t sin_wavtable[1024];
volatile uint16_t tri_wavtable[1024];
-
+volatile uint16_t pulse_wavtable[1024];
void LUTs::initial_wavetables()
{
sin_wavetable();
tri_wavetable(50);
+ pulse_wavetable(50);
}
void LUTs::sin_wavetable()
@@ -48,20 +49,38 @@
printf("Generating Tri-wavetable\n");
tri_wavtable[0]=0;
rise_t=(pulsewidth*1024/100);
- fall_t=1-rise_t;
+ rise_tu=(uint16_t)rise_t;
+ fall_tu=1-rise_tu;
dif=65536/rise_t;
dif_u=(uint16_t)dif;
- for (int i=1; i<rise_t; i++) {
+ for (int i=1; i<=rise_tu; i++) {
tri_wavtable[i]=tri_wavtable[i-1]+dif_u;
}
- dif=65536/fall_t;
+ dif=65536/fall_tu;
dif_u=(uint16_t)dif;
- for (int i=rise_t; i<1024; i++) {
+ for (int i=rise_t+1; i<1024; i++) {
tri_wavtable[i]=tri_wavtable[i-1]-dif_u;
}
}
+void LUTs::pulse_wavetable(int pulsewidth)
+{
+ printf("Generating Pulse-wavetable\n");
+ up_t=(pulsewidth*1024/100);
+ up_tu=(uint16_t)up_t;
+ for (int i=0; i<=up_tu; i++) {
+ pulse_wavtable[i]=65535;
+ //printf("up itt = %d\n",i);
+ }
+
+ for (int i=up_tu+1; i<1024; i++) {
+ pulse_wavtable[i]=0;
+ //printf("down itt = %d\n",i);
+ }
+}
+
+
/*
uint16_t get_sin(int i)
{