Andy Kunz wrote: > At 11:42 PM 12/30/97 +1100, you wrote: > >Hi > >I am thinking of designing an electronic speed controller for a remote > control car using a PIC. I have a number of ideas at the moment, but my > favourite is to use the microchip application notes for creating a pwm > (an654) with the 16f84, then convert the incoming pulse into a pwm stream. > > That makes your entire program about 20 lines or so of C. I think you'll find it isn't quite as simple as that. Timing the length of a 0.5 to 2 ms pulse occurring anywhere between 50 and 400 times a second (more usually 50Hz, but depends how many channels the reciever has) is pretty processor intensive. Trying to do that at the same time as generating a PWM output on a PIC which doesn't have hardware PWM will probably be tricky, and I doubt a C compiler would be intelligent enough to get the two processes working together properly. I think I would do it by connecting the output from the reciever to the INT pin, and whenever an interrupt is generated, reset TMR0, wait till the input goes low again, then read the timer. I would then generate the PWM (which does not need to be as accurate as measuring the input) in the main routine, using software delay counters (we are already using TMR 0 for something else) to measure the PWM. Just ignore the errors introduced into the PWM whenever an interrupt occurs, as it will never last longer than about 2.5ms, which should not be too important as long as your PWM frequency is very slow. You then have to think about the problem of calibrating the device, the maximum, minimum, and centre pulse lengths. I should store the calibration values in EEPROM, and either incorporate intelligent 'self calibrating' code, or allow a way for the user to program the EEPROM memory of the device. Remember to include a 'dead band' in the middle of the range where the motor is turned off even if the input signal is not quite on centre. ----------------------------------------------------------------------- : Alex Holden- Electronics student, Caver, and Land Rover enthusiast. : : http://www.geocities.com/CapeCanaveral/Lab/1532/ : ------------ Linux- The choice of a GNU generation. -----------------