Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help with 12f675 Servo controller

Status
Not open for further replies.

mastero

Member
Hello Friends,

I am building a simple RC servo controller for my ESC to run a BLDC motor.
Do not want a pot to control, Basic Motor On and Off circuit.
Did not find any without the analog pot control so decided to build one based on 12f675.

PIN1 = VSS
PIN2= PWM out
PIN3 = LED
Pin4 = Digital Input
PIN5 = NIL
PIN6= NIL
PIN7= NIL
PIN8=VDD

THE WORKING REQUIRED.
When 5v on pin 4 the PWM does 2ms when 0v on pin4 the PWM does 1ms @ 50~60Hz. Simple working.

Attached is my code for reference.

Problem all works well in simulation, in real life the LED does not blink, just constantly on.

any idea what am i doing wrong ?

Cheers
Mastero
 

Attachments

  • 12F675_SERVO.txt
    1.1 KB · Views: 266
Last edited:
I don't know what software you're using but it looks odd to me.

Basically you need two alternate paths through your code, 1mS and 2mS.

Pseudo code.
Code:
while(1)
    if pin4 high
        out=1
        delayms(2)
        out=0
        delayms(18)
    else
         out=1
        delayms(1)
        out=0
        delayms(19)
    endif
wend
Mike.
Edit, note that it's important that pulses only get sent once every 20mS,
 
Hello Mike,

Using Oshonsoft software.

I have till not reached the PWM stage my issue is the LED is constantly on not blinking.. i feel the issue is somewhere here

OPTION_REG = %00001000 'Pull-ups = yes, GPIO.2 = I/O, prescaler to WDTINTCON = %00000000 'disable all interupts
CMCON = %00000000 'comparator off
WPU = %00110111 'Internal pull-ups = on
IOC = %00000000 'disable IOC interrupt
TRISIO = %00001000 'GP4 and GP5 output
GPIO = %00000000 'All outputs = 0 on boot

could you confirm it is ok ?
 
It will run through that code so fast that your LED will be blinking 1000s of times a second and will look like it's constantly on. Try adding a delay of about 500mS every time you reset heartbeat.

Mike.
 
Hello Ian ....

Have a few of 675 lying around and this is not a production work.

if you can share your work it shall be nice to learn from a master :)

Below is my final code till date... LED is blinking fine now. waiting for the ESC to check the PWM function.


Define CONFIG = 0x01b4
Define CLOCK_FREQUENCY = 4
AllDigital

OPTION_REG = %00000000
WPU = %00000010
TRISIO = %00000010 'GP1 as input
GPIO = %00000000 'All outputs = 0 on boot

Symbol pulse = GPIO.5
Symbol led = GPIO.4
Symbol run = GPIO.1
Dim timer As Byte

pulse = 0
timer = 0
led = 0

loop:

If timer = 30 Then
timer = 0

If run = 0 Then
If led = 0 Then
led = 1
Else
led = 0
Endif
Endif

Else
timer = timer + 1
Endif

If run = 1 Then
pulse = 1
WaitUs 2000
pulse = 0
WaitMs 18
Else
pulse = 1
WaitUs 1000
pulse = 0
WaitMs 19
Endif

Goto loop
End


If you find any issues please let me know.

cheers
Mastero
 
What happens if you change heartbeat to a larger value, like 200 or 500 (integer variable instead of byte). I suspect you are just flashing it too quickly for the eye to see. 50 counts at 1ms is flashing every 50ms on/50ms off, 10 times a second. That is too fast to see by eye.
Also, not sure if "reading" ledout pin will return a proper value, since the GPIO is defined as output. It may return the internal buffered value, not sure.
I would use a variable to define the LED state. Then when heartbeat >= value, just "not" the storage value like "led = not led". Then output the value as "ledout = led"
 
Try something like this:

Code:
'Variablles
Symbol Servopulse = GPIO.5
Symbol ledout = GPIO.4
Symbol alarmin = GPIO.3
Dim heartbeat As Byte
Dim servoposition As Byte
Dim led as byte

'*****************************************
Servopulse = 0
heartbeat = 0
ledout = 0
led = 0

main:

        If heartbeat = 100 Then
            heartbeat = 0
            
            led = not led
            ledout = led
            
        Else
            heartbeat = heartbeat + 1
        Endif
                
        If alarmin = 1 Then
            servoposition = 200
        Else
            servoposition = 100
        Endif

        Gosub ServoMove

Goto main

    End
 
LOL !!! Master... As per... I never comment anything..

This is a pwm based on a frequency input.. Just need to use " modified" as the PWM duty..

Code:
AllDigital
Define CONF_WORD = 0x31c4

Dim y As Byte
Dim oput As Bit
Dim x As Byte
Dim d As Byte
Dim modified As Byte
OPTION_REG = 0x38
TRISIO = 4

PIE1.0 = 1
TMR1H = 0
TMR1L = 0
PIR1.TMR1IF = 0
PIE1.TMR1IE = 1
INTCON.PEIE = 1
INTCON.GIE = 1
T1CON = 1
oput = 1

y = 0xf0
x = 0x8f
main:
    TMR0 = 0
    WaitMs 1000
    modified = TMR0
    y = 255 - modified
    x = 128 + modified
    d = x + y
Goto main
End                                              

On Interrupt
    Toggle oput
    GPIO.0 = oput
    If oput Then
        TMR1H = y
    Else
        TMR1H = x
    Endif
    TMR1L = 0xff
    PIR1.TMR1IF = 0
Resume
 
Hello all,

Just finished this using osho and VSM. Works perfectly as required in VSM simulation.

If any one requires this enclosed are the VSM project file and the osho source code enjoy :)

Thanx all for the support.

cheers
Mastero
 

Attachments

  • 12F675_Servo.rar
    85.2 KB · Views: 279
LOL !!! Master... As per... I never comment anything..

This is a pwm based on a frequency input.. Just need to use " modified" as the PWM duty..

Code:
AllDigital
Define CONF_WORD = 0x31c4

Dim y As Byte
Dim oput As Bit
Dim x As Byte
Dim d As Byte
Dim modified As Byte
OPTION_REG = 0x38
TRISIO = 4

PIE1.0 = 1
TMR1H = 0
TMR1L = 0
PIR1.TMR1IF = 0
PIE1.TMR1IE = 1
INTCON.PEIE = 1
INTCON.GIE = 1
T1CON = 1
oput = 1

y = 0xf0
x = 0x8f
main:
    TMR0 = 0
    WaitMs 1000
    modified = TMR0
    y = 255 - modified
    x = 128 + modified
    d = x + y
Goto main
End                                             

On Interrupt
    Toggle oput
    GPIO.0 = oput
    If oput Then
        TMR1H = y
    Else
        TMR1H = x
    Endif
    TMR1L = 0xff
    PIR1.TMR1IF = 0
Resume

Hello Ian what is the clock frequency you used for above ?
cheers
Mastero
 
i see you are using PWM input... how do i change it ?

normally 50% cycle and when an input pin goes 0 then 99%

i am not good with interrupt routine...

cheers
 
i see you are using PWM input... how do i change it ?

normally 50% cycle and when an input pin goes 0 then 99%

i am not good with interrupt routine...

cheers
Nope... I read a frequency then convert to a voltage... BUT!! PWM -> Voltage via a small filter is NOT linear, hence I only worked with the top 50%


The input is just a count.. so an ADC reading will do just as well..

EDIT!!! Vladimir already has an RC output routine built in...
 
Need help to understand something here....!
Code:
Define CONFIG = 0x01b4
Define CLOCK_FREQUENCY = 4
AllDigital

OPTION_REG = %00000000
WPU = %00000010
TRISIO = %00000010  'GP1 as input
GPIO = %00000000  'All outputs = 0 on boot

Symbol pulse = GPIO.5
Symbol led = GPIO.4
Symbol run = GPIO.1

pulse = 0
led = 0

loop:
   
    If run = 0 Then
        led = 1
        pulse = 1
        WaitUs 2100
        pulse = 0
        WaitMs 10
    Else
        led = 0
        pulse = 1
        WaitUs 1000
        pulse = 0
        WaitMs 10
    Endif
   
Goto loop
    End
When i program this to the PIC12F765 The ESC work perfect with 4vdc but with 5vdc the ESC does not operate.

any ideas ??

cheers
Mastero
 
Last edited:
Hello Ian..

ESC =Electronic Speed Controller for brushless motor used in RC airplanes etc.. see attached data sheet.

Yes power supply is stable 5vdc if i add two 1N4007 diodes in series then it works fine and the voltage is around 4volts

tried with single diode but no luck needs two diodes.

any idea ?
 

Attachments

  • 30A_BLDC_ESC_Product_Manual.pdf
    172 KB · Views: 284
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top