Michael, There are UV eraseable versions of most PICs, designed to be used for development, but they are several times the price of the regular OTP (One Time Programmable) PICs. That is one reason why the 16C84 and 16F84 are so darn popular. They are relatively inexpensive and you can program them many times. Once you have the code working, you can sometimes migrate the design to a cheaper PIC with just a little re-work. Do not worry about the fact that the 16F84 does not have an analog input. For your application you do not need one! You can easily control small DC motors with the PIC. You can use what is called PWM (Pulse Width Modulated) control of a motor using just one bit of one port. The output of the PIC is used to drive a power FET or power bipolar transistor, usually through a gate or base resistor of from 220 ohms to 4.7K. The idea is to always have the motor receiving either all or nothing. If the motor receives current 0% of the time it is off. If it receives current 100% of the time it will run at full speed. If you feed it a square wave current drive that is on 50% of the time, the motor will run at half speed. If you give it a 20% duty cycle, it runs at 20% speed. Etc. The PWM signal normally has a fixed frequency, but a variable duty cycle. A PIC running at 4 Mhz would have a 1Mhz cycle rate. The TMR0 can be programmed to prescale the 1Mhz rate by any value from 1 to 256. Perhaps the simplest and easiest to understand PWM technique is as follows: Assume a prescaler rate of 1. (i.e. prescaller is assigned to the Watch Dog Timer). Assume the WDT is disabled. If we do nothing special, TMR0 will count up to 255 and then roll over to 0 every 256 clock cycles. We can change this behavior by loading TMR0 with 100-3 (0x61) every time interrupt occurs. This causes an interrupt rate of 10,000 interrupts per second. Inside the interrupt routine you also update a master_pwm counter by incrementing it. If it is at 100 (0x64), then clear it to zero and turn on the output bits for pwm_1 and pwm_2 (unless they are 0 too). Each time the interrupt occurs you increment master pwm. After doing the check for master_pwm=0 you compare the contents of master_pwm with pwm_1. If it is the SAME, then you turn pwm_1 bit off. (If the bits are NOT the same, then we just leave things as they are). You then compare the contents of master_pwm with pwm_2. If it is the SAME, then you turn pwm_2 bit off. (If the bits are NOT the same, then we just leave things as they are). Clear the interrupt bit T0IF and execute a RETFIE. << Try to program the interrupt routine to use the absolute minimum number of cycles to perform control of the registers and the port bits. Remember that this sucker is called 10,000 times per second. If you use more than about 94 cycles of operating time per interrupt, the PIC will spend all of its time in the interrupt routine, and no other work will get done! Any time you want to initiate a new duty cycle, just load the value into the proper register (pwm_1 or pwm_2). If you are the paranoid type, you can also turn off the appropriate pwm bit (bcf porta,pwm_1). The effect of the extra instruction is MINOR in the case of a motor. Please note that as shown the routine expects a value in pwm_1 and pwm_2 of from 0 to 99 (0x0 to 0x63). That is so that the routine operates directly in 1% increments, and works FASTER than if you used a duty cycle control word that ranged from 0 to 255. There are other approaches to PWM control. This one is definitely not an optimal implementation, but should work fine in your application. The primary advantage of this particular technique is that the main program only has to load speed values from 0 to 100 into the pwm_1 and pwm_2 registers to affect total speed control and steering. This makes the programming of the main robot control program a piece of cake. Note that the PWM frequency above is 100 Hz, with 100 1% steps. Each step is .0001 second wide. A 47 mfd electrolytic capacitor across the motor leads will help smooth out the motor response. In this application there is no need for motor reversal, so its use is OK. The PIC can go about reading sensors and based on the readings it can load values for pwm_1 and pwm_2 that will cause the motors to fine adjust their speed. This will cause the robot to steer smoothly. If you are a crafty dude you can program the logic so that the robot always attempts to move at the highest velocity possible. For example, turning can be done by either slowing one motor or increasing the other, or doing both at once. The movement algorithm can be adjusted so that minor corrections are always done preferentially by increasing the speed of one motor. Whenever a new value is loaded into pwm_1 or pwm_2, you can check to see whether it is currently bigger or smaller than the master_pwm count, and then use BSF or BCF to ensure that it gets turned off or on immediately, so there is no delay waiting for the master_pwm to cycle. Sorry I did not provide you with actual code. I am getting ready to go on a two week leave, so I am busy with packing and the like. Hope this helps. Fr. Tom McGahee ---------- > From: Michael Hearn > To: PICLIST@MITVMA.MIT.EDU > Subject: Blow only once with not PIC16C84? Is it true? > Date: Tuesday, June 23, 1998 9:58 AM > > Dear all, > > I just want to check whether it is true that the PIC models that can > deal with analogue ports can only be blown once. > I am doing a project at school that involves making a robot that can follow > a white line made of masking tape (MicroMouse by the IEE) and I was > wondering what sort of motor we should use. We have a choice between DC and > stepper motors but it seems to us that the 16C84 (the chip we use at the > moment) cannot deal with analogue signals. Is this true and what other > chips can do this? Also, is it true that the chips that can do this are > blow once? I just wanted to clear up a few inconsistencies. > > Anyone know about this? Anyone? At all? > > Michael