Hi Folks
I am currently working on an Electronic Speed Controller (ESC) project for a friend for a DC outboard motor for his kayak.
I have sucessfully built one in the past using a 12f683 driving mosfets and once I got over some glitches it worked well.
He has come back to me now wanting reverse also.
So I had a bright idea.
Why not use a powerful off the shelf brushed radio control ESC for all the power electronics and just drive it with my 12f683.
The circuit uses An0 as an input from a pot as the source for the speed, GP2 as an output for the PWM signal to the ESC and GP4 and GP5 to show direction on leds.
The code was based on some which I found on a forum somewhere and modified a little to suit my application.
Original author of the code may even be on here and recognise it
A few queries.
Firstly ANSEL, until I set it to 1 the output on my PWM pin was just oscilating with what appeared to be random 8mhz noise, can anybody explain why this was.
Secondly GP4 regardless of whether I set it on or off in code, appears to be on all the time, is there a property of GP4 on a 12f683 that I have missed?
I have tried to work through data sheets and I arent the best at this but I am very curious for my own learning as to what might have been going on here.
It has taken some hours to get the code to here due to one reason or another
(couldnt get the analog to play ball, was either all on or all off then I realised it was because I had anval set as an integer and is was rounding it during my scaling maths)
Before anybody asks the for loop early in the code is a calibration routine to let the esc know the pwm values.
The code is in MikroBasic by the way.
Hopefully somebody might be able to enlighten me.
Kind Regards
Bruce
I am currently working on an Electronic Speed Controller (ESC) project for a friend for a DC outboard motor for his kayak.
I have sucessfully built one in the past using a 12f683 driving mosfets and once I got over some glitches it worked well.
He has come back to me now wanting reverse also.
So I had a bright idea.
Why not use a powerful off the shelf brushed radio control ESC for all the power electronics and just drive it with my 12f683.
The circuit uses An0 as an input from a pot as the source for the speed, GP2 as an output for the PWM signal to the ESC and GP4 and GP5 to show direction on leds.
The code was based on some which I found on a forum somewhere and modified a little to suit my application.
Original author of the code may even be on here and recognise it
Rich (BB code):
program ServoControl
Symbol SPIN = gpio.2 ' Servo Output Pin
Dim CCPR as Word Absolute $13 ' CCPR1L:CCPR1H pair
ServoPos as Word
calcfloat as float
Temp as integer
anval as float
sub procedure Interrupt()
If SPIN = 1 Then
SPIN = 0 ' turn servo off
CCPR = 20000 - CCPR ' off time to finish 20ms
Else
SPIN = 1 ' turn servo on
CCPR = ServoPos ' on time in microseconds
End If
PIR1.CCP1IF = 0 ' clear int flag
End sub
sub procedure INIT()
CMCON0 = 7 ' turn off comparators
ansel = 1
trisio = 1
ServoPos = 2000
end sub
Sub procedure CCP_SETUP()
intcon=0
pie1 = 0
INTCON.peie = 1
intcon.GIE = 1 ' GIE, PEIE enabled
T1CON = 0 ' no prescale; off; 1us ticks
TMR1H = 0 ' clear timer1
TMR1L = 0
CCP1CON = 11 ' reset timer1 on compare-match
CCPR = 2000 ' match int value; 0 deg position
PIR1.CCP1IF = 0 ' clear int flag
PIE1.CCP1IE = 1 ' enable int
T1CON.TMR1ON = 1 ' timer1 run
end sub
main:
osccon = %01100001
INIT()
CCP_SETUP()
adc_init()
for Temp = 0 to 1000
ServoPos = ServoPos -1
delay_ms(2)
next Temp
While 1=1
anval = adc_get_sample(0)
calcfloat=((anval/1023)*1000)+1000
ServoPos = calcfloat
delay_ms(1)
if ServoPos > 1550 then
gpio.4= 1
gpio.5 = 0
end if
if ServoPos < 1450 then
gpio.4= 0
gpio.5= 1
end if
if ServoPos < 1450 then
if ServoPos < 1550 then
gpio.4 = 1
gpio.5 = 1
end if
end if
Wend
end.
Firstly ANSEL, until I set it to 1 the output on my PWM pin was just oscilating with what appeared to be random 8mhz noise, can anybody explain why this was.
Secondly GP4 regardless of whether I set it on or off in code, appears to be on all the time, is there a property of GP4 on a 12f683 that I have missed?
I have tried to work through data sheets and I arent the best at this but I am very curious for my own learning as to what might have been going on here.
It has taken some hours to get the code to here due to one reason or another
(couldnt get the analog to play ball, was either all on or all off then I realised it was because I had anval set as an integer and is was rounding it during my scaling maths)
Before anybody asks the for loop early in the code is a calibration routine to let the esc know the pwm values.
The code is in MikroBasic by the way.
Hopefully somebody might be able to enlighten me.
Kind Regards
Bruce