The Speed Control Software
The
Pic source code is written in C using the Hi-Tech C compiler. The free
version of this compiler can program quite a few of the Pic
microcontrollers, including the Pic12F675. You can use the compiler on
its own (with a Dos IDE) or integrate it into Microchip's MPLAB (www.microchip.com)
Download Hi-Tech C it from: www.htsoft.com
If you don't want to change the software, you don't need the C compiler
and can just download the file: 'speedcontrol.hex' to the Pic
microcontroller.
There are a lot of programmers on the internet to program Pic's, I use the P16Pro. Check it out at: www.picallw.com
The configuration bits for the Pic is as follows:
Watchdog timer = Off
Powerup timer = Off
Brownout-detect = Off
Oscillator = Internal RC
Clockout = Disabled
Software Description
All the speed control code (except measuring the battery voltage) runs in an interrupt.
The code is well documented, so you can read through it and make
modifications if you want. The constants you'll most probably want to
change is:
MAX_VOLTAGE - defines the maximum output of the speed control
MIN_VOLTAGE - if the measured voltage is below this value, the speed control will shut down.
To calculate a value for the above:
* The ADC has a range of 10 bits, thus the maximum value is 2^10 = 1024 (okay, 2^10-1 = 1023 if you want to be technical!)
* We use Vdd (the positive 5V supply) as a reference, thus a value of 0 from the ADC
will be 0V and a value of 1023 will be 5V. Every 205 (1023/5V) counts represent one volt.
* Our voltage divider will give the following voltage to the ADC input:
Vadc = Vbat* 2k2/(4k7+2k2)
Convert this to an ADC value:
ADCval = (Vbat*205)*2k2/(4k7+2k2)
ADCval = Vbat*65
For example, to make the speed control shut down at 5.5V:
ADCval = 5.5 * 65 = 358
thus: MIN_VOLTAGE = 358
If you don't use the ADC circuit, delete (or comment) the following line:
#define
VOLTAGE_DETECT
Please feel free to improve the source code and put it on the forum if you think other people might find it useful.
The source code can be downloaded here.
<< Previous
|