• Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Anlogue Output Voltage

    Scheduled Pinned Locked Moved Neuron Series
    3 Posts 2 Posters 983 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      knebb
      last edited by

      Hi,

      finally I was able to set (and read) the analogue output (AO1) on my Neuron M103 device through C with modbus_read_registers().

      So I am using as documented regsiter 3000-3001 as floating point variable.

      Works fine so far- I can set and verify the value by reading.

      Now when attaching a voltmeter to measure the real physical AO voltage I am getting some strange numbers.

      Here is a little table from what I observed:
      Setting the register to value (upper line) yields in measuring a voltage of the lower line on the AO1:

      Set to: 0 1.3 3.5 5.0 5.7 7.9 10.
      Result: 0 1.1 2.9 4.0 4.8 6.5 8.2

      Somehow I doubt it is mismeasured. The device usually is accurate.

      So how does it come to these differences?

      Thanks!

      /KNEBB

      Martin KudláčekM 1 Reply Last reply
      Reply Quote 0
      • Martin KudláčekM
        Martin Kudláček @knebb
        last edited by

        Hi @knebb,
        can you please post the C code?

        Thank you and have a nice day,
        Martin

        K 1 Reply Last reply
        Reply Quote 0
        • K
          knebb @Martin Kudláček
          last edited by

          @Martin-Kudláček :

          Of course. Here you are. I set the registers and am measuring the AO port during the sleep() cycle.

          #include "header.h"
          #include "vars.h"
          void main(int argc, char* argv[])
          {
          
          modbus_t *modbusglob;
          union {
                 uint16_t word[2];
                 uint32_t dword;
                 float fl;
          } counter,direct;
          int n[9],mode;
          
          /********************************* Function **********************************/
          void fieldbus_free(modbus_t *modbus)
          {
                  if (modbus != NULL) {
                  modbus_close(modbus);
                  modbus_free(modbus);
              }
          }
          
          /********************************* Function **********************************/
          modbus_t * fieldbus_new(void)
          {
          int err;
          modbus_t *modbus;
          char host[15];
          int port;
          
              strcpy(host,"127.0.0.1");
              port   = 502;
              modbus = modbus_new_tcp(host, port);
              if (modbus == NULL )
              {
                 fieldbus_free(modbus);
                 exit (55);
              }
              err = modbus_connect(modbus);
              if (err  == -1)
              {
                  fieldbus_free(modbus);
                  modbus = NULL;
                  exit (55);
              };
              err=modbus_set_slave(modbus, 0);
              if(  err == -1)
              {
                  fieldbus_free(modbus);
                  modbus = NULL;
                  exit (60);
              } else {
                  return modbus;
              }
          }
          
          /********************************* Function **********************************/
          int setvoltage(float wish)
          {
          int errlvl;
          union {
                 uint16_t word[2];
                 uint32_t dword;
                 float fl;
          } wert;
          uint16_t ao;
          
                  wert.fl=wish;
                  errlvl=modbus_write_registers(modbusglob, 3000, 2, (&wert.word[0]));
                  if (errlvl == -1) {printf("ERR1 modbus_write_register, %s\n",modbus_strerror(errno));}
                  else { printf("Register set to %f\n",wert.fl);}
                  return errlvl;
          }
          modbusglob=fieldbus_new();
          mode=1;
          setvoltage(1.3);
          sleep(60);
          setvoltage(3.5);
          sleep(60);
          setvoltage(5.7);
          sleep(60);
          setvoltage(7.9);
          sleep(60);
          setvoltage(10.0);
          sleep(60);
          setvoltage(0);
          sleep(60);
          setvoltage(5.0);
          
          fieldbus_free(modbusglob);
          exit (0);
          }
          
          
          1 Reply Last reply
          Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post