// Author: Andrew Wilson // Date: 6/28/2006 // Description: This program will control a stepper motor driver circuit. // it will monitor two inputs: analog potentiometer, and digital rpm sensor // the program will ramp the speed output of the motor depending on the // position of the potentiomenter. the rpm sensor will be used to ensure the // correct speed is maintained. #include <18F2520.h> #include "stepper_driver.h" #fuses INTRC, NOWDT, NOLVP #use delay(clock=8000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=PC) int main() { int16 v_reading; //the pic18f2550 has a 10-bit A-to-D converter //this gives 1024 possible steps printf("Stepper Motor Interface v1, brought to you by:\n\r"); printf("Andrew Wilson\n\r"); printf("reconnsworld.com\n\r"); //this sets up PIN A0 as an analog-in pin. //it is OR'd with VSS_VDD which forces the pic to use // ground and VDD as reference voltages setup_adc_ports(AN0_TO_AN1 || VSS_VDD); //this (i think) sets the ADC to clock via the internal //instruction clock setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(1); //we will only be using this channel //no need to set it again. while(1) { v_reading = read_adc(); printf("Reading is: %4lu; for an approximate voltage of: %5f\n\r", v_reading, (5.0*(((float)v_reading)/((float)MAX_READING)))); delay_ms(100); output_toggle(PIN_A0); } return 1; }