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.
Fork of PRACTICA3 by
main.cpp
00001 #include "mbed.h" 00002 #define period 1/5000 00003 #define sizeVector 100 00004 #define Constant (0.000001661707484) 00005 //USER_BUTTON o PC_13 00006 00007 InterruptIn button(PC_13); 00008 00009 uint32_t vA[sizeVector]; 00010 uint32_t vB[sizeVector]; 00011 00012 AnalogIn valors(A0); 00013 00014 int counter=0; 00015 int flag=0; 00016 int whatVector=0; 00017 uint64_t sum_values=0; 00018 float RMS_value=0; 00019 float Vpp_value=0; 00020 float Max_value=0; 00021 float Min_value=1000; 00022 int state=0; 00023 00024 Ticker sample; 00025 Ticker visualize; 00026 00027 void fsample() //?? 00028 { 00029 if (whatVector) { 00030 vB[counter]=(valors.read_u16()+valors.read_u16()+valors.read_u16()+valors.read_u16())/4; 00031 } 00032 else { 00033 vA[counter]=(valors.read_u16()+valors.read_u16()+valors.read_u16()+valors.read_u16())/4; 00034 } 00035 counter++; 00036 if (counter==100) { 00037 counter=1; 00038 flag=1; 00039 whatVector=!whatVector; //?? 00040 } 00041 } 00042 void change() //?? 00043 { 00044 state=!state; 00045 } 00046 void visualiza() 00047 { 00048 if(state){ 00049 printf("RMS value is =%f",RMS_value); 00050 } 00051 else { 00052 printf("Vpp value is =%f",Vpp_value); 00053 } 00054 } 00055 00056 int main() 00057 { 00058 uint32_t temp; 00059 sample.attach(&fsample,period); //& para llamar a la función 00060 visualize.attach(&visualiza,1); 00061 button.rise(&change); 00062 while(1) { 00063 if (flag) { 00064 flag=0; 00065 sum_values=0; 00066 if(whatVector) { 00067 00068 for(int n=0; n<99; n++) { 00069 temp=vA[n]; 00070 sum_values=sum_values+temp; 00071 00072 if(Max_value<temp) { 00073 Max_value=temp; 00074 } 00075 if(Min_value>temp) { 00076 Min_value=temp; 00077 } 00078 } 00079 } 00080 else { 00081 00082 for(int n=0; n<99; n++) { 00083 temp=vB[n]; 00084 sum_values=sum_values+temp; 00085 00086 if(Max_value<temp) { 00087 Max_value=temp; 00088 } 00089 if(Min_value>temp) { 00090 Min_value=temp; 00091 } 00092 } 00093 } 00094 RMS_value=sqrt(Constant*(float)sum_values); 00095 Vpp_value=Max_value-Min_value; 00096 00097 } 00098 } 00099 }
Generated on Tue Jul 12 2022 21:56:51 by
1.7.2
