Practica 2 Ejercicio 1 DSP
Dependencies: mbed mydsc_sampling_example mydsc
main.cpp
00001 /* Sampling example for My Digital Signal Controller library 00002 * Copyright (c) 2019, Gastón H. SALAZAR-SILVA 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * 00008 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00012 * either express or implied. 00013 * 00014 * See the License for the specific language governing permissions and limitations under the License. 00015 */ 00016 00017 /* 00018 * This program is an example of how to sample an analog input. 00019 * 00020 * # Interface # 00021 * 00022 * The connections are for a Nucleo f446re board. PC_1 and PA_4 should be physically connected. 00023 * PC_1 (A4) <---> PA_4 (A2) 00024 */ 00025 00026 #include "mbed.h" 00027 #include "mydsc_ring_buffer.h" 00028 00029 AnalogOut analog_out_1(PA_4); ///< Generated signal by the own board. Assigned to the pin PA_4. 00030 AnalogIn analog_in(PC_1); ///< Input to be sampled, assigned to the pin PC_1. PC_1 and PA_4 should be physically connected. 00031 AnalogOut analog_out_2(PA_5); ///< Analog output 2, connected to the pin PA_5, which is also connected to USER_LED. 00032 00033 const double PI = 3.14159265358979323846; 00034 const uint32_t SIZE = 1024; ///< Buffer size - 1 00035 const float H = 1.0/(SIZE); ///< Sampling period 00036 const int32_t PHI = -256; ///< Phase shift 00037 00038 mydsc_ring_buffer_t rb; ///< circular queue or ring buffer. 00039 Ticker ticker; //Variable ticker 00040 00041 void ticker_isr() { 00042 static unsigned int k = 0; //Dato no accesado desde otra funcion 00043 00044 analog_out_1 = ( 1.0 + sin(2*PI*k*H)) / 2.0; //Genera su salida analogica. Salida senoidal 00045 mydsc_ring_buffer_push(&rb, analog_in); //Apuntador RB e inserta el balor en PHI 00046 analog_out_2 = *mydsc_ring_buffer_sample(&rb, PHI); //Emular un arreglo, lee el valor con un apuntador 00047 k++; 00048 } 00049 00050 int main() { 00051 // Setup 00052 Serial tty(USBTX, USBRX); //Clase para el puerto Serial 00053 00054 mydsc_ring_buffer_init(&rb, SIZE); //Se inicializa y se da el tamaño de memoria 00055 ticker.attach(&ticker_isr, H); 00056 tty.baud(115200); //Velocidad a 115200 Baudios para el plotter 00057 00058 while(1) { 00059 // Loop 00060 tty.printf("%f\t%f\n", (*mydsc_ring_buffer_sample(&rb, 0)),(*mydsc_ring_buffer_sample(&rb, PHI))); // 00061 } 00062 } 00063
Generated on Fri Jul 29 2022 14:00:52 by
1.7.2