23 #include <sys/types.h>
24 #include "libpruio/pruio.h"
25 #include "libpruio/pruio_pins.h"
45 struct timeval timeout;
49 FD_SET(STDIN_FILENO, &set);
53 timeout.tv_usec = mseconds * 1000;
55 return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
61 int main(
int argc,
char **argv)
66 printf(
"initialisation failed (%s)\n", Io->
Errr);
break;}
76 printf(
"failed setting P9_14 (%s)\n", Io->
Errr);
break;}
79 printf(
"failed setting P9_16 (%s)\n", Io->
Errr);
break;}
82 printf(
"failed setting P9_42 (%s)\n", Io->
Errr);
break;}
85 printf(
"failed getting PWM value (%s)\n", Io->
Errr);
break;}
89 printf(
"QEP pin configuration failed (%s)\n", Io->
Errr);
break;}
92 printf(
"config failed (%s)\n", Io->
Errr);
break;}
95 static char *t[] = {
" A",
" A & B",
"A, B & I"};
100 printf(
"\n p=%u",
p);
101 printf(
"\n m=%i",
m);
102 printf(
"\n %s input", t[
p]);
103 printf(
"\n %s input", t[0]);
104 printf(
"\n %s input", t[1]);
105 printf(
"\n %s input", t[2]);
107 struct termios oldt, newt;
108 tcgetattr(STDIN_FILENO, &oldt);
110 newt.c_lflag &= ~(ICANON);
112 newt.c_cc[VTIME] = 1;
113 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
121 fflush(STDIN_FILENO);
124 case 'a' :
case 'A' :
m = 0;
break;
125 case 'b' :
case 'B' :
m = 1;
break;
126 case 'i' :
case 'I' :
m = 2;
break;
127 case 'p' :
case 'P' :
m = 3;
freq = (
freq < 499995.) ?
freq + 5. : 500000.;
break;
128 case 'm' :
case 'M' :
m = 3;
freq = (
freq > 30.) ?
freq - 5. : 25.;
break;
129 case '*' :
m = 3;
freq = (
freq < 250000.) ?
freq * 5. : 500000.;
break;
130 case '/' :
m = 3;
freq = (
freq > 50.) ?
freq / 5. : 25.;
break;
131 case '0' :
m =
p;
pmax = 0;
break;
132 case '1' :
m =
p;
pmax = 1023;
break;
133 case '4' :
m =
p;
pmax = 4095;
break;
134 case '5' :
m =
p;
pmax = 511;
break;
135 case '8' :
m =
p;
pmax = 8191;
break;
136 case '+' :
m = 3; Io->
Pwm->
AqCtl[0][1][1] = 0x6;
break;
137 case '-' :
m = 3; Io->
Pwm->
AqCtl[0][1][1] = 0x9;
break;
138 case 13 :
m = 3;
freq = 50.;
140 printf(
"failed setting PWM value (%s)\n", Io->
Errr);
143 printf(
"failed getting PWM value (%s)\n", Io->
Errr);
146 default:
goto finish;
151 printf(
"failed setting PWM value (%s)\n", Io->
Errr);
154 printf(
"failed getting PWM value (%s)\n", Io->
Errr);
160 printf(
"QEP pin reconfiguration failed (%s)\n", Io->
Errr);
166 printf(
"failed getting QEP Value (%s)\n", Io->
Errr);
break;}
168 printf(
"\r Position: %8X , Speed: %7.2f",
posi,
velo);
172 tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
VAR p
The position of the 'x' character (if any).
unsigned int uint32
32 bit unsigned integer data type.
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
float float_t
float data type.
char * pruio_pwm_setValue(pruIo *Io, uint8 Ball, float_t Hz, float_t Du)
Wrapper function for PwmMod::setValue().
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
char * pruio_qep_config(pruIo *Io, uint8 Ball, uint32 PMax, float_t VHz, float_t Scale, uint8 Mo)
Wrapper function for QepMod::config().
char * pruio_pwm_Value(pruIo *Io, uint8 Ball, float_t *Hz, float_t *Du)
Wrapper function for PwmMod::Value().
char * pruio_qep_Value(pruIo *Io, uint8 Ball, uint32 *Posi, float_t *Velo)
Wrapper function for QepMod::Value().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().
unsigned char uint8
8 bit unsigned integer data type.
@ PRUIO_DEF_ACTIVE
Activate all subsystems.
const ANY_PTR NULL
The NULL pointer.
#define P8_16
CPU ball number for pin 16 on header 8.
#define P9_14
CPU ball number for pin 14 on header 9.
#define P9_16
CPU ball number for pin 16 on header 9.
#define P8_12
CPU ball number for pin 12 on header 8.
#define P9_42
CPU ball number for double pin 42 on header 9 (second ball is 104)
#define P8_11
CPU ball number for pin 11 on header 8.
UInt32 pmax
The maximum position value.
CONST_UInt8 PINS[...]
The header pins to use for input (PWMSS-1).
Float_t freq
The current frequency (startvalue here).
UInt32 posi
The current position value.
Float_t velo
The current speed.
Float_t realfreq
The real frequency of PWM output.
#define PMX
Default PMax value.
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
int main(int argc, char **argv)
The main function.
#define VHz
The frequency for speed measurement.
Wrapper structure for PruIo.
char * Errr
Pointer for error messages.
pwmMod * Pwm
Pointer to ePWM module structure (in PWMSS subsystem).
uint16 AqCtl[1+1][PRUIO_AZ_PWMSS+1][2+1]
Initializers for Action Qualifier for ePWM modules (see PWM).
uint16 ForceUpDown
< Switch to force up-down counter for ePWM modules.