How to log PV and Set-point in soft-PID operation for tuning?

Discussion in 'Embedded Systems and Microcontrollers' started by urb-nurd, Mar 9, 2015.

  1. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    I am using a MikroC ready for pic board to control the temperature of a heater using PID.

    I have come as far as implementing the PID function and was wondering the easiest way to visualise the performance.

    I was wondering if i could save the Process variable and set point every 100 milliseconds or so in my program code.
    But then how could i extract this for displaying on my PC screen?

    How can i approach this?
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    Output RS232 using Usart module and a modem program on the PC, Hyperterminal etc.
    You may have to get a cheap USB to RS232 adaptor for ~$4.00.
    Max.
     
  3. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    I don't have an rs232 connection on my board - as it is the cheaper model.
    However if i can use the usb-usart module, then this could work.
    Thanks for the info
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    If you left the ICSP pins unused during normal operation (something I strongly recommend doing) you can use the in curcuit debugger capability of a PICkit or ICD device to extract system variable information.
     
  5. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    Could you elaborate more on that?

    how would the debugger capability of a picKIT aid in my application?
    I am a bit limited with time and resources, so i was going to attempt to use the usart module of my ready for bic board to send the data over serial
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    With a debugger you can set a watch window for anything in your program you wish to look at. However, if you are not familiar with it that may take more time then you have.

    The quick and dirty way to see the data on a PC is to use a program such as Hyperterminal which will display ASCII data. It will help if your PIC converts raw binary to ASCII for display purposes.

    I don't think Hyperterminal is still a standard Windows component but there are excellent freebie replacements on the web.

    All these programs see the USB-UART as a COM port and connect up very simply.
     
  7. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    i have managed to get my code to transmit the values via serial out into my usb.
    I can view this on my usart terminal in MikroC, but now i was wondering if i could possibly graph this in real time using some software?
    I can save the logs of the serial output and graph this in excel (i think) but i would like real time viewing also.
    Thanks
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Excel has a built in Visual Basic for Applications package, you can capture serial data with that and send up to a worksheet to present as a graph.

    Nope, I don't know the details of doing this, just that it should be possible. I doubt this is a trivial effort.
     
  9. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    Thanks for the info!
     
  10. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    For other forum members who are attempting to display serially transmitted data on a graph:

    I used SIMPLOT
    http://www.negtronics.com/simplot

    The software was the quickest to set up and very simple to start using.

    The software expects 16 bits per channel packet.
    Here is how the program wants the data presented.
    Code (Text):
    1.     if (SendPID)
    2.    {
    3.    // send headers first  (SimPlot expects 16-bit data = 2 bytes)
    4.     UART1_Write(0xAB);        // header low byte
    5.     UART1_Write(0xCD);         // header high byte
    6.     // then send packet size
    7.     UART1_Write(0x04);         // packet size low byte (4 bytes for two 8 bit values)
    8.     UART1_Write(0x00);         // high byte
    9.     // send channel 1 bytes
    10.     UART1_Write(SetPoint);       // low byte
    11.     UART1_Write(0x00);           // high byte
    12.     // send channel 2 bytes
    13.     UART1_Write(PV);                  // low byte
    14.     UART1_Write(0x00);               // high byte
    15.     SendPID = 0;                     // Clear SendPID flag
    16.    }
    [​IMG]
     
  11. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,134
    268
    Wire up a DAC and watch it on your scope- the dumb easy way.
     
  12. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    Though that would work for viewing my temperature (PV) - i could not view the set point (software defined) using this method and therefore could not tune my PID loop.
     
  13. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,134
    268
    Why not? I use a 4 channel DAC, outputting the input set point, current position (temp), error signal and integrator value.
    Just write some hooks into those variables, scale them and send to the DAC.

    A PID loop is a digital emulation of an analog idea, better to see the output as analog anyway.
     
  14. urb-nurd

    Thread Starter Member

    Jul 9, 2014
    269
    3
    that could indeed work!

    But would require me to write additional code for the DAC conversions etc.

    I am already having a few issues with the high currents being switched interfering with my measured temperature, so adding more wires and connections would only compound this issue.

    Thanks for the input though!
     
Loading...