Hello Everybody,

after noticing some bad noises on a machine I noticed that when I
command an output of -10.0V on an stg2 card that it actually outputs +10V.

To debug and reproduce I did this:
setp stg.2.dac-value -10
or
setp stg.2.dac-value -9.999
measured approx. +10V with a voltmeter, not ok

setp stg.2.dac-value -9.99
measured approx. -9.96V with a voltmeter, ok

Such large values should not usually happen if you use the dac output
for a servo amp because then you've run into saturation, but if you use
the output for something else, like spindle velocity control+ direction,
then it really does.

The relevant code is how the ncounts variable gets
calculated in hal_stg.c:

ncounts = (short) ((-10.0 - volts) / 20.0 * 0x1FFF);

The relevant stg documentation is on p. 30 of the stg2 manual. Values
written to the register are inverted before arriving at the dac.

0x0000 => -10V
0x1000 =>   0V
0x1FFF => +10V

Changing the calculation to:
ncounts = (short) ((((-10.0 - volts) * 0x1FFF) / 20.0) - 1 );
solves the problem. Check with the attached test program. Notice the
0xFFFF values for -10V after the inverting is done in the old calc.

Current Emc2 calculation: Values written to register are: -10V: 0x0000,
-9,999V: 0x0000, -9,99V: 0xFFFC, 0V: 0xF001, +10V: 0xE001
Current Emc2 calculation: Values arriving at DAC (inverted) are: -10V:
0xFFFF, -9,999V: 0xFFFF, -9,99V: 0x0003, 0V: 0x0FFE, +10V: 0x1FFE
Mod. Emc2 calculation: Values written to register are: -10V: 0xFFFF,
-9,999V: 0xFFFF, -9,99V: 0xFFFB, 0V: 0xF000, +10V: 0xE000
Mod. Emc2 calculation: Values arriving at DAC are: -10V: 0x0000,
-9,999V: 0x0000, -9,99V: 0x0004, 0V: 0x0FFF, +10V: 0x1FFF

I also checked this fix 5 mins ago on the real machine - works now.

BR
Max.






#include <stdio.h>

short emc2_calc( double lvolts )
{
  short retval ;
  retval = (short) ((-10.0 - lvolts) / 20.0 * 0x1FFF);
  return retval;
}

short emc2_calc_mod( double lvolts )
{
  short retval ;
  retval = (short) ((((-10.0 - lvolts) * 0x1FFF) / 20.0) - 1 );
  return retval;
}

int main( int argc, char **argv ) 
{
  short n0, n1, n2, n3, n4;
  short m0, m1, m2, m3, m4;

  n0 = emc2_calc( -10.0L );
  n1 = emc2_calc( -9.999L );
  n2 = emc2_calc( -9.99L );
  n3 = emc2_calc( 0.0L );
  n4 = emc2_calc( +10.0L );

  printf( "Current Emc2 calculation: Values written to register are: -10V: 0x%04hX, -9,999V: 0x%04hX, -9,99V: 0x%04hX, 0V: 0x%04hX, +10V: 0x%04hX\n", n0, n1, n2, n3, n4 );

  printf( "Current Emc2 calculation: Values arriving at DAC (inverted) are: -10V: 0x%04hX, -9,999V: 0x%04hX, -9,99V: 0x%04hX, 0V: 0x%04hX, +10V: 0x%04hX\n", ~n0, ~n1, ~n2, ~n3, ~n4 );

  m0 = emc2_calc_mod( -10.0L );
  m1 = emc2_calc_mod( -9.999L );
  m2 = emc2_calc_mod( -9.99L );
  m3 = emc2_calc_mod( 0.0L );
  m4 = emc2_calc_mod( +10.0L );
  
  printf( "Mod. Emc2 calculation: Values written to register are: -10V: 0x%04hX, -9,999V: 0x%04hX, -9,99V: 0x%04hX, 0V: 0x%04hX, +10V: 0x%04hX\n", m0, m1, m2, m3, m4 );

  printf( "Mod. Emc2 calculation: Values arriving at DAC are: -10V: 0x%04hX, -9,999V: 0x%04hX, -9,99V: 0x%04hX, 0V: 0x%04hX, +10V: 0x%04hX\n", ~m0, ~m1, ~m2, ~m3, ~m4 );
  return 0;

}
------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to