Control Feedback & RS-232


Closed Thread
Results 1 to 3 of 3
  1. #1
    nate's Avatar
    nate Guest

    Default Control Feedback & RS-232

    Background: Need a PIC to complete a feedback loop using a tachometer. PIC will vary a PWM signal based on Tach input.

    I need a RS-232 link to a PC but I haven't quite figured out how I want to structure my program due to the limitations of ucontrollers. I've chosen the 16F876 PIC and the PBP compiler.

    The PC will send a START/STOP and RPM command via RS232. The motor will then start up and tightly regulate the RPM on the motor as the load changes.

    My question is how do I effectively maintain a tight loop on my feedback loop but maintain RS-232 comm with the PC? Do i need to use an interupt? I would like to stream RPM data back to the PC for analysis.

    Thanks!

    - Nate

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Nate, I would make the serial communications interrupt driven, that way you can spend the other bulk of the time doing the speed control loop.

    Dave Purola,
    N8NTA

  3. #3
    nate's Avatar
    nate Guest


    Did you find this post helpful? Yes | No

    Default

    Made my very first cut at the code and haven't even tried to compile as my compiler hasn't arrived yet.

    You guys mind reviewing it to see if I'm doing anything stupid?

    getdata:HSERIN [B0] ' Wait start/stop/RPM data on serial port
    IF B0 = rpm10 THEN spd2kp = 12
    IF B0 = rpm20 THEN spd2kp = 24
    IF B0 = rpm30 THEN spd2kp = 36
    IF B0 = rpm40 THEN spd2kp = 48
    ELSE getdata
    ENDIF

    loop: COUNT portX.X,100,CRNTSPD ' Get speed from wheel encoder
    IF (crntspd < spd2kp) THEN pw = 1000 ' If not up to speed apply full power
    IF (crntspd >= spd2kp) THEN pw = 750 ' If to fast slow down
    ELSE pw = 500 ' something is wrong shut down
    PULSOUT PORTX.X,pw ' put pulse out to the speed controller
    PAUSE 15 ' setup the pwm frequency
    HSEROUT crntspd ' send speed data to computer
    HSERIN 5,loop,[B0] ' Wait 5ms for stop command
    IF B0.8 = 0 THEN getdata ' If the first bit is 0 then stop and wait for start again
    ELSE loop ' No stop command keep going
    ENDIF
    GOTO loop
    END

    As you can see I tried to steer clear of the interupts as I have control of the pc. I'm hoping this will work. I am interfacing to a standard RC speed controller which should explain the pulseout / pause commands.

    Any comments or suggestions greatly appreciated as I'm on a very very short time schedule for development.

    - Nate

    p.s. I couldn't figure out how to properly format my code for easy readability

Similar Threads

  1. How do I give a radio control car autonomous control
    By Kenjones1935 in forum General
    Replies: 190
    Last Post: - 17th January 2010, 15:40
  2. Allow better control of text in GUI
    By Archangel in forum PBP Wish List
    Replies: 1
    Last Post: - 19th February 2007, 13:25
  3. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  4. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18
  5. RS 485 using 16F84A
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th May 2005, 14:46

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