engineerelectrical
Newbie level 6
I am using a PIC18F6722 microcontroller. I have hooked up a function generator to pin A1 to get the various values for the sinewave. I want to write code to find the amplitude of the sine wave. How should I go about doing this? So, far this is my code:
I am new to programming so any help would be much appreciated! Thanks in advance.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #include <18F6722.h> #device ICD = TRUE #fuses HS, NOLVP, NOWDT #use delay (clock=20000000) #USE rs232 (baud=9600, xmit = PIN_C6, rcv=PIN_C7) #include<utility.c> #include<math.h> void main() { int reading, i; int8 imin = 255; int8 imax = 0; float array[10]; float Volts; float a = 5.0, b = 255.0; int ctr = 0; setup_adc_ports(AN0_TO_AN1); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(1); while(TRUE) { for(i=0; i<=9; i++) { reading = read_adc(); Volts = reading*(a/b); array[i] = Volts; printf("\r\n%f", array[i]); } if(ctr==9) break; ctr++; } for(i=0; i<=9; i++) { if(array[i]<imin) imin=array[i]; if(array[i]>imax) imax=array[i]; } }
I am new to programming so any help would be much appreciated! Thanks in advance.
Last edited by a moderator: