'---------------Title-------------- ' File......multiplex_rx3y.pbp ' Started....9/1/12 ' Microcontroller used: Microchip Technology PIC16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' The program receives an 8-bit digital value (0 to 255) ' of y and from a fiber-optic receiver and converts the value ' of y into a PWM signal to a dc motor. '------------Schematic------------- ' See schematic at: ' http://cornerstonerobotics.org/schematics/control5_multiplex_tx_rx3.pdf '----------Related Lesson---------- ' http://cornerstonerobotics.org/curriculum/lessons_year3/eriii23_control_navigation6.pdf '-----New PicBasic Pro Commands---- ' The PicBasic Pro Compiler Manual is on line at: ' http://www.microengineeringlabs.com/resources/index.htm#Manuals '------------Variables------------- x var byte ' Byte for potentiometer 1 input y var byte ' Byte for potentiometer 2 input z var byte '----------Initialization---------- define OSC 8 ' Defines oscillator setting at 8 MHz. ' For SEROUT2, an oscillator speed ' faster than 4MHZ may be required ' for reliable operation at 9600 baud ' and above. Define HSER_RCSTA 90h ' Set receive register to receive ' enabled Define HSER_TXSTA 20h ' Set transmit register to transmitter ' enabled DEFINE HSER_BAUD 9600 ' Set baud rate to 9600 DEFINE CCP1_REG PORTB ' Set PORTB for CCP1 ' (Capture/Compare/PWM) Channel 1. DEFINE CCP1_BIT 0 ' Set Set bit 0 for CCP1 ' (Capture/Compare/PWM) Channel 1. ANSEL = 0 ' Changes analog bits to digital. OSCCON = $70 ' Sets the internal oscillator in the ' 16F88 OSCCON register to 8 MHz TRISB = %00000100 ' Set PIC receive pin to input PORTB = %00100000 ' Set PIC transmit pin RB5 to HIGH '-------------Main Code------------ start: hSerin[WAIT("B0"), x, y] ' Serial input, B0 is start bit, x and y ' are data bits. This PIC only uses the ' value for y. z = y/2 + 125 ' Changes range of PWM values from 0-255 ' to 125-252. hpwm 1, z, 20000 ' Output PWM pulse on Channel 1 ' (Pin RB0 specified above) at duty cycle ' "z" [0 (OFF all the time) to ' 255 (ON all the time)]) at frequency ' of 20,000 Hz. goto start