process_EMS22A.cpp
Go to the documentation of this file.
1 /*
2  * process_EMS22A.cpp
3  *
4  * Created: 20/07/2017 10:13:46
5  * Author: Francisco José Mañas
6  */
7 
8  /*Beginning of Auto generated code by Atmel studio */
9  #include <Arduino.h>
10  /*End of auto generated code by Atmel studio */
11 
12  #include "arduinodaq_declarations.h"
13  #include "arduinodaq2pc-structs.h"
14  #include "Encoder_EMS22A.h"
15 
16 /* Absolute encoder EMS22A reading waveforms (from its datasheet) */
17 // ____ ____
18 // Cs: | | |
19 // |________________________________________________________________| |_____
20 // __________ _ _ _ _ _ _ _ _ _ _ _ _ ______________
21 // Clk: | | | | | | | | | | | | | | | | | | | | | | | | | |
22 // |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_|
23 //
24 // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
25 // DO:__________ / \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \______________
26 // |_|\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
27 // D9-D8-D7-D6-D5-D4-D3-D2-D1-D0-S1-S2-S3-S4-S5-P1
28 //
29 // D0-D9: Absolute angular position data.
30 // S1 : End of offset compensation algorithm.
31 // S2 : Cordic overflow indicating an error in cordic part.
32 // S3 : Linearity alarm.
33 // S4 : Increase in magnitude.
34 // S5 : Decrease in magnitude.
35 // P1 : Even parity for detecting bits 1-15 transmission error.
36 
37 /* Lectura de Encoder Absoluto EMS22A */
41 unsigned long EMS22A_last_millis = 0;
43 bool EMS22A_active = false;
44 
45 bool init_EMS22A(int8_t init_ENCODER_ABS_CS, int8_t init_ENCODER_ABS_CLK, int8_t init_ENCODER_ABS_DO, uint16_t init_sampling_period_ms)
46 {
47  ENCODER_ABS_CS = init_ENCODER_ABS_CS;
48  ENCODER_ABS_CLK = init_ENCODER_ABS_CLK;
49  ENCODER_ABS_DO = init_ENCODER_ABS_DO;
50  EMS22A_sampling_period_ms = init_sampling_period_ms;
52  return false; // error
53 
57 
60 
61  return true; // all ok
62 }
63 
64 uint16_t read_EMS22A()
65 {
69 
72 
73  uint16_t pos = 0;
74  for (int i=0; i<16; i++) {
77 
78  pos = pos << 1; // shift 1 bit left
80  {
81  pos |= 0x01;
82  }
83  }
84 
86  return pos;
87 }
88 
90 {
91  if (!EMS22A_active)
92  {
93  return;
94  }
95 
96  const unsigned long tnow = millis(); /* the current time ("now") */
97 
99  {
100  return;
101  }
102  EMS22A_last_millis = tnow;
103 
104  const uint16_t dat = read_EMS22A();
105 
106  // Extract the position part and the status part
107  const uint16_t enc_pos = dat >> 6;
108  const uint8_t enc_status = dat & 0x3f;
109 
111  // send answer back:
112  tx.payload.timestamp_ms = tnow;
113  tx.payload.enc_pos = enc_pos;
114  tx.payload.enc_status = enc_status;
116 
117  Serial.write((uint8_t*)&tx,sizeof(tx));
118 
119  }
120 
void calc_and_update_checksum()
void pinMode(uint8_t, uint8_t)
void delayMicroseconds(unsigned int us)
Definition: wiring.c:120
static const uint8_t A3
bool init_EMS22A(int8_t init_ENCODER_ABS_CS, int8_t init_ENCODER_ABS_CLK, int8_t init_ENCODER_ABS_DO, uint16_t init_sampling_period_ms)
uint16_t EMS22A_sampling_period_ms
uint16_t enc_pos
Absolute value read from the encoder (10 bits resolution)
void processEMS22A()
uint8_t enc_status
See EMS22A datasheet for the bit map.
#define OUTPUT
Definition: Arduino.h:44
#define HIGH
Definition: Arduino.h:40
#define INPUT
Definition: Arduino.h:43
int ENCODER_ABS_DO
unsigned long EMS22A_last_millis
unsigned long millis(void)
Definition: wiring.c:65
uint16_t read_EMS22A()
double A1
int digitalRead(uint8_t)
int ENCODER_ABS_CS
bool EMS22A_active
int ENCODER_ABS_CLK
void digitalWrite(uint8_t, uint8_t)
#define LOW
Definition: Arduino.h:41
static const uint8_t A2


arduino_daq
Author(s):
autogenerated on Mon Jun 10 2019 12:46:03