DC Motor ESC issue 12F683


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default DC Motor ESC issue 12F683

    Posted to the melabs support forum first on accident...

    Looks like far more people use these forums so I am reposting here.

    So I thought I would pickup this hobby again and start by making something simple.

    I chose to make a basic Electonic Speed Control for a small park flyer I have on my bench.

    For the past few days I've been bread-boarding FET circuits to run the motor (that's not the issue) and I am working on PBP code to run it.

    It works as far as controlling the speed of the motor from the transmitter. But I am having an issue and I am at a loss for what I have missed.

    Some background: I am using a DMX2 Transmitter and Receiver. These things 'mate-up' when you turn them on. You first turn on the TX and then the RX. About 5-10 seconds later they are connected. During this time it's doing some sort of hand-shake routine I guess...

    The problem: My PIC12F683 based ESC starts sending PWM as soon as I turn on the circuit and goes to about 50% throttle until the handshake period is over. Once it's mated up, the motor goes to 0 throttle. Obviously I don't want that as my plane would be either cutting my hand or taking off without control before the mating ritual is over.

    I am fairly certain my electronics are good and there are no stray signals on the dc or in the FET circuit. I've scoped all signal aspects of the circuit at start-up and the only one I see prior to the rx coming on-line is the ~162ms pulse train coming from the hardware pwm on the pic.

    I suspect it has something to do with how I am configuring the control registers of the chip or maybe the meProgrammer settings? It seems like what is happening is the PWM is running right at boot?

    Below is the 'code' so far. As i said, it works well enough except for the whole start-up problem.

    Thoughts and/or suggestions?

    Code:
    '****************************************************************
    '*  Notes   :  DC motor ESC written for PIC12F683               *
    '*          :  Takes Pulsin Input from RX on GPIO.3             *
    '*          :  HPWM FET Driver Output on GPIO.2                 *
    '*          :  Debug Ouput on GPIO.5                            *
    '*          ;  Receiver Sends pulses between 109 & 189          *
    '****************************************************************
    #CONFIG
      __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BOD_ON
    #ENDCONFIG
    ADCON0 = 0   'A/D Off
    CMCON0 = 7   'Comparators Off
    ANSEL = 0    'Set all Digital
    WPU = 0      'turn off pull-ups
    OPTION_REG = %10000000 'Set GPIO.2 i/o, pull-ups off, prescaler to tmr1
    GPIO = 0   'All outputs =0 on boot
    TRISIO.2 = 0  'Set GPIO.2 Data In
    osccon = %01100000 'Set Oscillator to 4mhz
    Include "modedefs.bas"
    DEFINE osc 4 'Set compiler scale to 4mhz'
    DEFINE PULSIN_MAX 1000 'Set Pulse Capture Window Max to 1 second
    DEFINE DEBUG_REG GPIO  'Set Debug Bank to GPIO
    DEFINE DEBUG_BIT 5     'Set Debug Output port to GPIO.5
    DEFINE DEBUG_BAUD 9600 'Set Debug Serial Baud Rate
    DEFINE DEBUG_MODE 1    'Invert Serial Bits
    DEFINE DEBUGIN_REG GPIO 'Set Debug Input Bank to GPIO
    DEFINE DEBUGIN_BIT 4    'Set Debug Input Port to GPIO.4
    DEFINE DEBUGIN_MODE 1   'Invert Serial Bits Received
    rxin var GPIO.3   'Input from rc receiver
    txout var GPIO.2  'pwm output to FET Driver Circuit
    rxval var BYTE    'Raw Pulse Value from RC receiver
    adjp var byte     'Scaled Value for ccp1 duty cycle
    adjp = 0
    rxval=0
    'wait for a stable low
    
    arm:
    pulsin rxin,1,rxval 'Get a pulse
    if rxval>115 then goto arm 'wait for something below 115
    
    main:
     pulsin rxin,1,rxval  'get a pulse
     adjp = (((rxval - 109)*5)/16)*10  'scale the input between 109-189 to make it 0-250'ish
     HPWM  1,adjp,62 'set the pwm
     debug "Duty Cycle:",#adjp,10 'send PWM duty cycle text to console
    goto main

  2. #2
    Join Date
    Nov 2012
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: DC Motor ESC issue 12F683

    This is now fixed. Thanks go to Darrel Taylor over at melabs for giving me a clue.

    Repaired Code with less coments.

    Code:
    '****************************************************************
    '                                                          *
    '*  Notes   :  DC motor ESC written for PIC12F683               *
    '*          :  Input from RX - Throttle                    *
    '*          :  PWM FET Driver Output                       *
    '*          :                                                   *
    '****************************************************************
    #CONFIG
      __config _INTRC_OSC_NOCLKOUT  & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _WDT_ON
    #ENDCONFIG
    
    Include "modedefs.bas"
    ADCON0 = 0   'A/D Off
    CMCON0 = 7   'Comparators Off
    ANSEL = 0    'Set all Digital
    osccon = %01100000 '4mhz
    DEFINE osc 4 'Set oscillator to 4mhz'
    DEFINE DEBUG_REG GPIO
    DEFINE DEBUG_BIT 5
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 1
    DEFINE DEBUGIN_REG GPIO
    DEFINE DEBUGIN_BIT 4
    DEFINE DEBUGIN_MODE 1
    
    rxin var GPIO.3   'input from rc receiver
    txout var GPIO.2  'pwm output to driver
    rxval var BYTE
    adjp var byte
    INPUT rxin
    output txout
    
    hold:           'wait here if the receiver is not up yet
    pulsin rxin,1,rxval
    if rxval=0 then goto hold
    
    arm:            'receiver is up now make sure throttle is low
    pulsin rxin,1,rxval
    if rxval>115 then goto arm
    
    main:           'Throttle is low now start looking for pulses
    pulsin rxin,1,rxval
    adjp = (((rxval - 110)*5)/14)*10 'normalize the pulses & convert for pwm
    HPWM  1,adjp,1000                
    debug "Pulsewidth:",#adjp,10
    goto main

Similar Threads

  1. debug timeout issue 12F683
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th February 2010, 21:44
  2. 12f683 ADC help
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th November 2009, 21:37
  3. 12f683 help!!!! L@@K!!!
    By thm ov3rkill in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd December 2008, 22:46
  4. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  5. pin 12f683
    By jcleaver in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 22nd March 2007, 22:29

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts