Everything started when I saw this version of uni-directional ESC (Libstock projects - rc-motor-control-cmos-output-version). Deserved credits to the original poster!
I used the same method to measure the pulse width as the original poster. The difference is that my design is a full-bridge mode.
The PIC is a 16F690, with a P-N H-bridge attached to it. Probably will drive 10-15A continuously. The Mosfet driver can drive much bigger Mosfets. See the datasheet linked below.
It drives the motor from 0 to 100% in forward direction for PPM signal between 1.6 to 2ms, it stops the motor (free coast) between 1.4 and 1.6ms, and it drives the motor from 0 to 100% in reverse direction from 1.4 to 1ms.
Mainly, I use the linear interpolation to calculate the Duty Cycle the PWM will be driven. For details see the comments in the code and this Wiki link (Linear interpolation). I made all needed calculations so the PIC will have to do the minimum of calculations (i.e. I considered 0-100 as being -100, and arranged the formula I put in the code), for a quicker execution of the code in the PIC.
As the mikroBasic PRO does not have a library for the full-bridge I had to add some additional code (the present PWM library "knows" to output the PWM signal on the designated pin of the PIC in single-mode PWM - which is good enough for many applications!).
Here is how I did it (if you read the datasheet, you'll see why):
PWM initialisation:
'Init PWM
CCP1CON = 0X4E ' CCP ON mode, FWD (default)
' P1A/C active "L"
' modulated P1B/D active "H"
CCPR1L = 0x00
T2CON = 0x05 ' TMR2 ON, 1:4 prescaler
PR2 = 0xFA ' f=498Hz
TMR2 = 0
CCP1CON = 0X4E ' CCP ON mode, FWD (default)
' P1A/C active "L"
' modulated P1B/D active "H"
CCPR1L = 0x00
T2CON = 0x05 ' TMR2 ON, 1:4 prescaler
PR2 = 0xFA ' f=498Hz
TMR2 = 0
'End init PWM
Direction change:
SetBit(CCP1CON,7) for Reverse or ClearBit(CCP1CON,7) for Forward.
At "zero position" I simply put the Duty Cycle at 0, regardless the direction bit.
Duty Cycle set-up:
CCPR1L = something (where "something" is calculated based on the PPM pulse width).
The schematic is the following:
CLICK TO ZOOM! |
The schematic is self-explanatory, but I will add some wording:
- It is based on the 16F690 PIC (I used the SOIC package this time).
- The PIC supply is by a 7805 regulator (as the circuit power supply is 12Vdc). I put a diode as a "fool-proof" protection.
- The Mosfet driver is a TC446x (where x is 8 or 9 and you set-up the jumper JMP1 accordingly: "1" for 4468, "0" for 4469). It is shown a 4468 but the 4469 has the same pin #s, except one input is negated (see datasheet TC446x). The mosfets are STD30PF03 (P-ch 0.025ohm, 24A) and STD35NF3LL (N-ch 0.014ohm 35A) in DPAK packages (ideal RDSon indicated ;)).
On the PPM input put a 10k resistor to ground, it will help by preventing input floating (this is helping the Loss Of Signal fix).
On the PPM input put a 10k resistor to ground, it will help by preventing input floating (this is helping the Loss Of Signal fix).
The PCB (not the perfect one, as it is a single layer and needs wire jumpers...). I suggest you do your own for a better layout, you can add the ICSP (I temporarily solder some wires for software update). But, as a sample here you have it. You can use the free version of Eagle, but you may need to create yourself some components.
PCB |
Note that the code contains also the LCD connections. The version on breadboard (using a DIP package PIC) had a LCD connected to continuously show the pulse width and the Duty Cycle (needed for small adjustments). You do not need that, and you can remove that part from the code. It will not interfere with the full-bridge functionality.
Source, HEX and schematics are here! And on LIBSTOCK (mikroElektronika community sharing website) here!
Enjoy and comment, you can help to improve this design!
Mircea