' Name : brushless_converter.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2010 ' : All Rights Reserved ' Date : 19 May 2010 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' This code reads the gate input on the FETs on a Draganfly brushed quadcopter, ' and scales the 0 to 5.8 ms high pulse to a servo nominal 1..2 ms PWM. ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - PWM 1..2 ms output ' Pin6 = GPIO.1 - i/o - ' Pin5 = GPIO.2 - i/o - ' Pin4 = GPIO.3 - input only - FET gate #1 - tie to FET via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - ' Pin2 = GPIO.5 - i/o - ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal(4 MHz) xtal = 4 PULSIN_MAXIMUM = 1200 ' wait a maximum of 12 ms for a pulse Dim S1 aS wORD Dim Scaled_S1 AS Word Clear ' set all variables = 0 Start: S1 = Pulsin GPIO.3, High ' should be in range 0 to 580 (0 ... 5.8 ms) if S1 > 580 Then S1 = 580 Scaled_S1 = (S1 * 100) / 580 ' scale to 0 .. 100 (0 ... 1 ms) Low GPIO.0 ' set the output pin state to low PulsOut GPIO.0, Scaled_S1 + 100 ' add 100 (1 ms) to get in range of 1 ... 2 ms 'if s1 > 0 then delayms 12 else delayms 6 ' if the pulse exists at all, wait about 12 ms to get the next one ' if there was no pulse, the code waited 12 ms, so wait another 6 to try again DelayMS ( 11 - (S1 / 100) - (Scaled_S1/100)) ' make the frame rate >12 ms Goto Start