void main() { int values[10], value, i; int count1, count2; count1 = count2 = 0; brdInit(); // initialize I/O drivers pwmOut(1, 512); // provide input voltage by // connecting DA1 to AD0) while (count1<10) { // read voltage 10 times costate { waitfordone { value=cof_anaIn(0); // execute one step } if (value == -1) { // this typically means that AD0 is disconnected printf("value out of range?\n"); exit(1); } if (value > 0) { // is value "good"? values[count1] = value; // yes - store it count1++; // otherwise repeat } } costate { count2++; // 2nd costate (does // nothing here) } } pwmOut(1, 0); // turn off output for (i=0; i<10; i++) // print values printf("values[%4d] = %6d\n", i, values[i]); printf("1st costate (cos_anaIn) executed %d times\n", count1); printf("2nd costate (nothing) executed %d times\n", count2); }
main () { auto int channel, value1, value2; auto float voltage, volts1, volts2; auto unsigned int rawdata, gaincode; auto char buffer[64]; brdInit(); while (1) { printf("\n\nChoose the 0 for DA0 or 1 for DA1 ..... "); gets(buffer); channel = atoi(buffer); pwmOut(channel, LOCOUNT); printf("\nEnter first voltage reading from meter = "); gets(buffer); volts1 = atof(buffer); pwmOut(channel, HICOUNT); printf("\nEnter second voltage reading from meter = "); gets(buffer); volts2 = atof(buffer); anaOutCalib(channel, LOCOUNT, volts1, HICOUNT, volts2); printf("\nstore constants to flash\n"); anaOutEEWr(channel); printf("\nread back constants\n"); anaOutEERd(channel); while (strcmp(buffer,"q") && strcmp(buffer,"Q")) { printf("\nType a desired voltage (0 to 3.2 Volts) or Q to exit "); voltage = atof(gets(buffer)); printf("Observe voltage on meter.....\n"); pwmOutVolts(channel, voltage); } } }
void doPWM(unsigned pin,unsigned period,unsigned duty) { pwmOut(pin,period,duty); }