0% encontró este documento útil (0 votos)
58 vistas4 páginas

Generador de señales con DAC en ESP32

Este documento describe un proyecto para generar señales utilizando un ESP32. Define funciones para generar diferentes formas de onda como senoidal, diente de sierra, cuadrada, triangular, tren de pulsos y exponencial creciente/decreciente. Estas señales se envían a un DAC a través de los pines 25 y 26 y se controlan mediante botones para cambiar entre cada forma de onda.

Cargado por

Ifran Sierra
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
58 vistas4 páginas

Generador de señales con DAC en ESP32

Este documento describe un proyecto para generar señales utilizando un ESP32. Define funciones para generar diferentes formas de onda como senoidal, diente de sierra, cuadrada, triangular, tren de pulsos y exponencial creciente/decreciente. Estas señales se envían a un DAC a través de los pines 25 y 26 y se controlan mediante botones para cambiar entre cada forma de onda.

Cargado por

Ifran Sierra
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd

// Proyecto: Generador de se�ales.

// Description: Esp32 has two "gpio" with DAC and they are: dac1; 25, dac2; 26.
// Output DAC => example: dacWrite is the function that controls the output of the
DAC, it receives two dacWrite input parameters (pin, int (function)), the DAC has
an 8 bit resolution ...
int a=0;
float y = 0;
int counter = 0;
int buttonNext=23;
int buttonBack=22;

int FRECUENCIA = 12;


int tomaFrecuencia = 0;
float w=10; //FRECUENCIA W

void setup() {
pinMode(FRECUENCIA, INPUT);
[Link](115200);
pinMode(buttonNext, INPUT);
pinMode(buttonBack, INPUT);
}

void loop() {

//dacWrite(25, int(128)); // I initialize the DAC at 128 my reference at "0",


which would be half the power range in resolution 256 of the DAC
//touchValue = touchRead(touchPin);
//[Link](touchValue);

//if(touchValue <= 55){


// delay(1000);
// counter = counter + 1;
// [Link](counter);
//}else {
// [Link]("SIN FUNCION");
//}

if(digitalRead(buttonNext) == 1 ){
delay(1000);
counter = counter + 1;
//[Link](counter);
}else if(digitalRead(buttonBack)== 1){
delay(1000);
counter = counter - 1;
}

switch(counter){
case 1: senosoidal(); break; // [Link]("SENOSOIDAL"); ok
case 2: dienteSierra(); break; // [Link]("DIENTE CIERAA"); ok
case 3: cuadrada(); break; // [Link]("CUADRADA"); // ok
case 4: triangular(); break; // [Link]("TRIANGULAR"); ok
case 5: trenPulso(); break; // [Link]("TREN PULSO"); ok

case 6: exponencialCreciente(); break; // [Link]("EXPONENCIAL


CRECIENTE"); // todo@santiago: ok
case 7: exponencialDecreciente(); break; // [Link]("EXPONENCIAL
CRECIENTE"); // todo@santiago: ok
default: counter = 0; break; // [Link]("REINICIANDO...");
}
}

//CALCULAR FRECUENCIA
void calcularFrecuencia(){
tomaFrecuencia = analogRead(FRECUENCIA);
if(tomaFrecuencia > w+110 || tomaFrecuencia < w-110){
w=((tomaFrecuencia-10)/3)+10;

} else {
}
// }
}

//LOGIC EXTRACT HEAVISIDE IN MATLAB AND CLASS


int heaviside( float x ){
if(x<0){
return 0;
}else{
return 1;
}
}

//SENOSOIDAL FUNCTION 1
void senosoidal(){
calcularFrecuencia();
for(float t=0;t<10;t=t+0.01){
//for(int t=0;t<720;t++){
dacWrite(26, int(126 + 125 *(sin(t*w)) ));
[Link](126+125*(sin(t*w)));
}
}

//SE�AL DIENTE DE SIERRA ok


void dienteSierra(){
calcularFrecuencia();
while(a<255){
dacWrite(26, (0 + a*(w/10)));
//dacWrite(25, (0 + Fx));
//dacWrite(25, int(128 + Fxa));
[Link](a);
a++;
}
a=0;
}

//SE�AL CUADRADA // ok
void cuadrada(){
calcularFrecuencia();
for(float t=-w*0.5;t<=w*0.5;t=t+1){
//for(float t=-w;t<=w;t=t+(w/100)){
//for(int t=-255;t<255;t++){
y= heaviside(t);
dacWrite(26, int(0 + 255 *(y)));
[Link](0+255*(y));
}
}

//CUADRADA FUNCTION
//void cuadrada(){
//for(int t=-100;t<100;t++){
//y= heaviside(t);
//dacWrite(25, int(128 + 100 *(y) ));
//[Link](128+100*(y));
//}
//}

//SE�AL TRIANGULAR //ok


void triangular(){
calcularFrecuencia();
while(a<(w/2)){
//dacWrite(25, (0 + Fx*(w/1000)));
dacWrite(26, (0 + a));
[Link](0+a);
a++;
//Fx=Fx+0.5;
}
//Fx=199;
do{
//Fx=Fx-0.5;
a--;
//dacWrite(25, int(0 + Fx*(w/1000)));
dacWrite(26, int(0 + a));
[Link](0+a);
} while(a>1);
}

//TREN DE PULSOS ok
void trenPulso(){
calcularFrecuencia();
for(int t=-w;t<1;t++){
y= heaviside(t);
dacWrite(26, int(0 + 255 *(y)));
[Link](0+255*(y));
}
}

//ESCALON UNITARIO FUNCTION


void escalonUnitario() {
for(float t=-10;t<10; t=t+0.1){
y=heaviside(t);
dacWrite(26, int(128 + 120 *(y)));
[Link](128 + 120 *(y));
}
}

//SE�AL EXPONENCIAL CRECIENTE


void exponencialDecreciente(){
calcularFrecuencia();
for(float t=0;t<10; t=t+0.01){
y=exp((-w/1000)*t);
dacWrite(26, int(0 + 255 *(y)));
[Link](0 + 255 *(y));
}
}

//SE�AL EXPONENCIAL CRECIENTE


void exponencialCreciente(){
calcularFrecuencia();
for(float t=0;t<10; t=t+0.01){
y=exp(0.2*t);
dacWrite(26, int(0 + 255 *(y*(w/9090))));
[Link](0 + 255 *(y*(w/900)));
}
}

También podría gustarte