Shop OBEX P1 Docs P2 Docs Learn Events
Programming pulse width modulation on the Propeller Chip. Also, programming an — Parallax Forums

Programming pulse width modulation on the Propeller Chip. Also, programming an

AlerkAlerk Posts: 3
edited 2008-09-26 04:41 in Propeller 1
Hello forum users. Recently, I've been attempting to program an electric vehicle to move forward. I have been trying to use a Duratrax Auto-Sport Fwd/Rev Intellispeed ESC, as well as a servo to control the brake. However, I don't really know how to program the ESC, let alone use it. I've been running into problems with getting these to work.
dira[noparse][[/noparse]EscPin]~~
  'PulseWait := 0.02 - Pulse      0.001 < Pulse < 0.002
  repeat 50
    outa[noparse][[/noparse]EscPin] := 1
    waitcnt(cnt + Pulse * clkfreq)
    !outa[noparse][[/noparse]EscPin]
    waitcnt(cnt + PulseWait * clkfreq)


The above block of code was intended for controlling the ESC. However, I don't have much experience with ESCs. What suggestions do you have for programming an ESC to move a motor forward? I'm completely open to suggestions.

Also, how is it possible to code PWM in spin for the propeller chip?

Thanks in advance.

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-26 02:44
    I would look at the pwm objects in object exchange. I use http://obex.parallax.com/objects/359/ for pwm generation for motor control though I am driving brushed DC motor drivers.
    With pwmx8 you start it saying what pwm speed, pin and how many pwms. Then there is another call to set the duty cycle and it does the rest
  • AlerkAlerk Posts: 3
    edited 2008-09-26 03:17
    Thanks Timmoore,
    I've looked at it, but I really don't know how to use it nor its functions. I apologize for my inexperience, but how can I use the pwm object to control the ESC? And how will the ESC serve to control the motor? Thanks again.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-26 03:37
    I haven't used a brushless esc but my understanding is that they take a pwm rc style input. Thinking about it, thats the same as a servo input. You probably are better with the servo-4 object http://obex.parallax.com/objects/38/

    servo4.start(1500,pin,0,0,0,0,0,0)
    starts 1 output, on pin pin. 1500 is the center servo value which is normally stopped for motors. Though does your esc go in reverse? normally 1000-1500 is reverse and 1500-2000 is forwards but you will need to look in your esc docs for the pulse values to use. The 1000-2000 are the actually pulse widths and are standard for most stuff taking servo/rc style inputs.
    The esc rc input should be connected to the prop pin you select via a 1K resistor to be safe.

    move_to changes the output value, the first parameter is the output no, 0 in the above case. The 2nd value is the pusle width 1000-2000, and the 3rd value is the time taken to change from the current width to the new width 1-50 where 50 is 1 sec.

    I would take a look for what a servo input looks like and what your esc docs says and compare the two. If they are the same then the above idea would work.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-26 04:41
    Alerk,

    The code in your initial post assumes that Spin does floating point arithmetic natively. Unfortunately, it does not. So your pulse widths should be given in whole microseconds, rather than fractions of a second. Your program might then look something like this:

      dira[noparse][[/noparse]EscPin]~~
      Time0 = clk
      repeat 50
        waitcnt(Time0 += clkfreq / 50)
        outa[noparse][[/noparse]EscPin]~~
        waitcnt(Time0 + Pulse * clkfreq / 1_000_000)
        outa[noparse][[/noparse]EscPin]~
    
    
    


    Using WAITCNT in this fashion ("synchronized" timing) yields more accurate pulses than does "fixed" timing. (See the Propeller manual for an explanation fo these terms.)

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
Sign In or Register to comment.