Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
if (tempbyte=='a'){ int adc[100]; int cn1; int servo_load=0; //take the reading : 100 readings, 1 microsecond each, save in array adc for (cn1=0; cn1<100; cn1=cn1+1) { adc[cn1]=a2dReadMv(ADC0); delay_ms(0.001); } //let's find the first pulse, i.e. non-zero area. And measure how long it is. For my setup, longest is about 50 us, so I make 50 us -> 100 % load cn1=0; if (adc[cn1]==0) { while (adc[cn1]==0) { cn1=cn1+1; } while (adc[cn1]>0) { servo_load=servo_load+1; cn1=cn1+1; } } else { while (adc[cn1]>0) { cn1=cn1+1; } while (adc[cn1]==0) { cn1=cn1+1; } while (adc[cn1]>0) { servo_load=servo_load+1; cn1=cn1+1; } } printf("Servo load is %d, \r", servo_load*2);