PJ3007 Project  1.1
Motor Controller Board. 4A dual H Bridge
 All Files Functions Variables Macros
init.h File Reference
#include <xc.h>
#include <pwm.h>
#include <timers.h>
#include <usart.h>
#include <stdlib.h>
#include "CNC_functions.h"

Go to the source code of this file.

Macros

#define CLOCK_FREQUENCY   40;
 
#define IN1_HB_1   LATBbits.LATB0
 
#define IN2_HB_1   LATBbits.LATB1
 
#define IN1_HB_2   LATBbits.LATB2
 
#define IN2_HB_2   LATBbits.LATB3
 
#define ENABLE_HB_1   LATCbits.LATC2
 
#define ENABLE_HB_2   LATCbits.LATC1
 
#define LED_1   LATDbits.LATD0
 
#define LED_2   LATDbits.LATD1
 
#define HEART_LED   LATDbits.LATD0
 
#define ERROR_LED   LATDbits.LATD1
 
#define RS485_OUT_ENABLE   LATDbits.LATD2
 
#define RS485_MODE   LATDbits.LATD2
 
#define READ_ONLY   0
 
#define READ_WRITE   1
 
#define TEMP   LATDbits.LATD3
 
#define AUX_SW_1   PORTBbits.RB4
 
#define AUX_SW_2   PORTBbits.RB5
 
#define DIP_SW_1   PORTDbits.RD5
 
#define DIP_SW_2   PORTDbits.RD6
 
#define DIP_SW_3   PORTDbits.RD7
 
#define DIP_SW_4   PORTBbits.RB7
 
#define LED_ON   1
 
#define LED_OFF   0
 
#define VCC   1
 
#define GND   0
 
#define ACTIVATED   1
 
#define DEACTIVATED   0
 
#define FLAG_SET   1
 
#define FLAG_CLEAR   0
 
#define LOW_LEVEL_PRIORITY   0
 
#define HIGH_LEVEL_PRIORITY   1
 
#define ENABLE_SIGNAL   0
 
#define STEP_SIGNAL   1
 
#define DIRECTION_SIGNAL   2
 
#define SWITCH_SIGNAL   3
 
#define RISING_EDGE   1
 
#define FALLING_EDGE   0
 
#define CNC_ENABLE   PORTCbits.RC5
 
#define CNC_STEP   PORTCbits.RC3
 
#define CNC_DIRECTION   PORTCbits.RC4
 
#define CNC_STEP_FLAG   INTCONbits.INT0IF
 
#define CNC_DIRECTION_FLAG   INTCON3bits.INT1IF
 
#define CNC_ENABLE_FLAG   INTCON3bits.INT2IF
 
#define CNC_SWITCH_FLAG   INTCONbits.RBIF
 
#define EMG_STOP_OUT   LATCbits.LATC0
 
#define EMG_STOP_FLTA   PORTDbits.RD4
 
#define EMG_STOP_RB6   PORTBbits.RB6
 
#define ERROR_OVER_VOLTAGE   1
 
#define ERROR_UNDER_VOLTAGE   2
 
#define ERROR_OVER_CURRENT_M_1   3
 
#define ERROR_OVER_CURRENT_M_2   4
 
#define ERROR_OVER_TEMP   5
 
#define ERROR_BOUDARY_SW_1   6
 
#define ERROR_BOUDARY_SW_2   7
 
#define ERROR_DELTA_VOLTAGE_O   8
 
#define ERROR_DELTA_VOLTAGE_B   9
 
#define WARNING_MISSING_STEPS   0b00000001
 
#define WARNING_DELTA_VOLTAGE_O   0b00000010
 
#define WARNING_DELTA_VOLTAGE_B   0b00000100
 
#define WARNING_TEMPERATURE   0b00001000
 
#define WARNING_COMMUNICATION   0b00010000
 
#define WARNING_NOT_DEFINED_2   0b00100000
 
#define WARNING_NOT_DEFINED_3   0b01000000
 
#define WARNING_NOT_DEFINED_4   0b10000000
 
#define MOTOR_1   1
 
#define MOTOR_2   2
 
#define MOTOR_ALL   3
 
#define FULL_STEP   1
 
#define FULL_STEP_2_PHASES   2
 
#define HALF_STEP   3
 
#define LAP   1
 
#define SIGNED_MAGNITUDE   2
 
#define STEPPER   3
 
#define MAX_SPEED   1023
 
#define MIN_SPEED   0
 
#define VIN_MIN   11
 
#define VIN_MAX   28
 
#define VIN_DELTA_WARNING   2
 
#define VIN_DELTA_ERROR   3
 
#define TEMP_MAX   65
 
#define TEMP_WARNING_1   35
 
#define TEMP_WARNING_2   45
 
#define TEMP_HYSTERESIS   6
 
#define MAX_PHASE_CURRENT_PEAK   500
 
#define FULL_STEP_STATE_1   2
 
#define FULL_STEP_STATE_2   8
 
#define FULL_STEP_STATE_3   1
 
#define FULL_STEP_STATE_4   4
 
#define FULL_STEP_NR_STATES   4
 
#define FULL_STEP_2_PHASES_STATE_1   10
 
#define FULL_STEP_2_PHASES_STATE_2   9
 
#define FULL_STEP_2_PHASES_STATE_3   5
 
#define FULL_STEP_2_PHASES_STATE_4   6
 
#define FULL_STEP_2_PHASES_NR_STATES   4
 
#define HALF_STEP_STATE_1   2
 
#define HALF_STEP_STATE_2   10
 
#define HALF_STEP_STATE_3   8
 
#define HALF_STEP_STATE_4   9
 
#define HALF_STEP_STATE_5   1
 
#define HALF_STEP_STATE_6   5
 
#define HALF_STEP_STATE_7   4
 
#define HALF_STEP_STATE_8   6
 
#define HALF_STEP_NR_STATES   8
 
#define ADC_MOTOR_1_TEST   0
 
#define ADC_MOTOR_2_TEST   1
 
#define ADC_PHASE_1_TEST   0
 
#define ADC_PHASE_2_TEST   1
 
#define ADC_VIN_TEST   2
 
#define ADC_TEMP_TEST   3
 
#define SYSTEM_MONITOR_TEST   4
 
#define ADC_IS_BUSY   1
 
#define ADC_IS_FREE   0
 
#define POWER_CONTROL_HALF_RESOLUTION   511
 
#define DEFAULT_PWM   30
 
#define PWM_FREQ_1KHZ   0
 
#define PWM_FREQ_2KHZ   1
 
#define PWM_FREQ_3KHZ   2
 
#define PWM_FREQ_4KHZ   3
 
#define PWM_FREQ_5KHZ   4
 
#define PWM_FREQ_6KHZ   5
 
#define PWM_FREQ_7KHZ   6
 
#define PWM_FREQ_8KHZ   7
 
#define PWM_FREQ_9KHZ   8
 
#define PWM_FREQ_10KHZ   9
 
#define PWM_FREQ_11KHZ   10
 
#define PWM_FREQ_12KHZ   11
 
#define PWM_FREQ_13KHZ   12
 
#define PWM_FREQ_14KHZ   13
 
#define PWM_FREQ_15KHZ   14
 
#define PWM_FREQ_16KHZ   15
 
#define PWM_FREQ_17KHZ   16
 
#define PWM_FREQ_18KHZ   17
 
#define PWM_FREQ_19KHZ   18
 
#define PWM_FREQ_20KHZ   19
 
#define PWM_FREQ_21KHZ   20
 
#define PWM_FREQ_22KHZ   21
 
#define PWM_FREQ_23KHZ   22
 
#define PWM_FREQ_24KHZ   23
 
#define PWM_FREQ_25KHZ   24
 
#define PWM_FREQ_26KHZ   25
 
#define PWM_FREQ_27KHZ   26
 
#define PWM_FREQ_28KHZ   27
 
#define PWM_FREQ_29KHZ   28
 
#define PWM_FREQ_30KHZ   29
 
#define PWM_FREQ_31KHZ   30
 
#define PWM_FREQ_32KHZ   31
 
#define PWM_FREQ_33KHZ   32
 
#define PWM_FREQ_34KHZ   33
 
#define PWM_FREQ_35KHZ   34
 
#define PWM_FREQ_36KHZ   35
 
#define PWM_FREQ_37KHZ   36
 
#define PWM_FREQ_38KHZ   37
 
#define PWM_FREQ_39KHZ   38
 
#define PWM_FREQ_40KHZ   39
 
#define PWM_FREQ_41KHZ   40
 
#define PWM_FREQ_42KHZ   41
 
#define PWM_FREQ_43KHZ   42
 
#define PWM_FREQ_44KHZ   43
 
#define PWM_FREQ_45KHZ   44
 
#define PWM_FREQ_46KHZ   45
 
#define PWM_FREQ_47KHZ   46
 
#define PWM_FREQ_48KHZ   47
 
#define PWM_FREQ_49KHZ   48
 
#define PWM_FREQ_50KHZ   49
 
#define PWM_SIGNED_MAGNITUDE_FREQ_1KHZ   25
 
#define PWM_SIGNED_MAGNITUDE_FREQ_2KHZ   255
 
#define PWM_SIGNED_MAGNITUDE_FREQ_3KHZ   207
 
#define PWM_SIGNED_MAGNITUDE_FREQ_4KHZ   155
 
#define PWM_SIGNED_MAGNITUDE_FREQ_5KHZ   124
 
#define PWM_SIGNED_MAGNITUDE_FREQ_6KHZ   103
 
#define PWM_SIGNED_MAGNITUDE_FREQ_7KHZ   88
 
#define PWM_SIGNED_MAGNITUDE_FREQ_8KHZ   77
 
#define PWM_SIGNED_MAGNITUDE_FREQ_9KHZ   68
 
#define PWM_SIGNED_MAGNITUDE_FREQ_10KHZ   62
 
#define PWM_SIGNED_MAGNITUDE_FREQ_11KHZ   56
 
#define PWM_SIGNED_MAGNITUDE_FREQ_12KHZ   51
 
#define PWM_SIGNED_MAGNITUDE_FREQ_13KHZ   47
 
#define PWM_SIGNED_MAGNITUDE_FREQ_14KHZ   44
 
#define PWM_SIGNED_MAGNITUDE_FREQ_15KHZ   41
 
#define PWM_SIGNED_MAGNITUDE_FREQ_16KHZ   38
 
#define PWM_SIGNED_MAGNITUDE_FREQ_17KHZ   36
 
#define PWM_SIGNED_MAGNITUDE_FREQ_18KHZ   34
 
#define PWM_SIGNED_MAGNITUDE_FREQ_19KHZ   32
 
#define PWM_SIGNED_MAGNITUDE_FREQ_20KHZ   30
 
#define PWM_SIGNED_MAGNITUDE_FREQ_21KHZ   29
 
#define PWM_SIGNED_MAGNITUDE_FREQ_22KHZ   27
 
#define PWM_SIGNED_MAGNITUDE_FREQ_23KHZ   26
 
#define PWM_SIGNED_MAGNITUDE_FREQ_24KHZ   25
 
#define PWM_SIGNED_MAGNITUDE_FREQ_25KHZ   24
 
#define PWM_SIGNED_MAGNITUDE_FREQ_26KHZ   23
 
#define PWM_SIGNED_MAGNITUDE_FREQ_27KHZ   22
 
#define PWM_SIGNED_MAGNITUDE_FREQ_28KHZ   21
 
#define PWM_SIGNED_MAGNITUDE_FREQ_29KHZ   21
 
#define PWM_SIGNED_MAGNITUDE_FREQ_30KHZ   20
 
#define PWM_SIGNED_MAGNITUDE_FREQ_31KHZ   19
 
#define PWM_SIGNED_MAGNITUDE_FREQ_32KHZ   19
 
#define PWM_SIGNED_MAGNITUDE_FREQ_33KHZ   18
 
#define PWM_SIGNED_MAGNITUDE_FREQ_34KHZ   17
 
#define PWM_SIGNED_MAGNITUDE_FREQ_35KHZ   17
 
#define PWM_SIGNED_MAGNITUDE_FREQ_36KHZ   16
 
#define PWM_SIGNED_MAGNITUDE_FREQ_37KHZ   16
 
#define PWM_SIGNED_MAGNITUDE_FREQ_38KHZ   15
 
#define PWM_SIGNED_MAGNITUDE_FREQ_39KHZ   15
 
#define PWM_SIGNED_MAGNITUDE_FREQ_40KHZ   15
 
#define PWM_SIGNED_MAGNITUDE_FREQ_41KHZ   14
 
#define PWM_SIGNED_MAGNITUDE_FREQ_42KHZ   14
 
#define PWM_SIGNED_MAGNITUDE_FREQ_43KHZ   14
 
#define PWM_SIGNED_MAGNITUDE_FREQ_44KHZ   13
 
#define PWM_SIGNED_MAGNITUDE_FREQ_45KHZ   13
 
#define PWM_SIGNED_MAGNITUDE_FREQ_46KHZ   13
 
#define PWM_SIGNED_MAGNITUDE_FREQ_47KHZ   12
 
#define PWM_SIGNED_MAGNITUDE_FREQ_48KHZ   12
 
#define PWM_SIGNED_MAGNITUDE_FREQ_49KHZ   12
 
#define PWM_SIGNED_MAGNITUDE_FREQ_50KHZ   12
 
#define CURRENT_0   0
 
#define CURRENT_1   25
 
#define CURRENT_2   50
 
#define CURRENT_3   75
 
#define CURRENT_4   100
 
#define CURRENT_5   125
 
#define CURRENT_6   150
 
#define CURRENT_7   175
 
#define CURRENT_8   200
 
#define CURRENT_9   225
 
#define CURRENT_10   250
 
#define CURRENT_11   275
 
#define CURRENT_12   300
 
#define CURRENT_13   325
 
#define CURRENT_14   350
 
#define CURRENT_15   375
 
#define BAUD_RATE_9600   255
 
#define BAUD_RATE_19200   129
 
#define BAUD_RATE_57600   42
 
#define BAUD_RATE_115200   21
 
#define TX_INTERRUPT_ON   USART_TX_INT_ON
 
#define TX_INTERRUPT_OFF   USART_TX_INT_OFF
 
#define RX_INTERRUPT_ON   USART_RX_INT_ON
 
#define RX_INTERRUPT_OFF   USART_RX_INT_OFF
 
#define EMG_STOP_NOT_ACTIVATED   2
 
#define OPERATION_PROPERLY_EXECUTED   1
 
#define ERROR_MODALITY_NOT_DEFINED   -1
 
#define ERROR_RX_DATA_NOT_READY   -2
 
#define ERROR_VIN_MAX   -3
 
#define ERROR_VIN_MIN   -4
 
#define ERROR_EMG_STOP_ACTIVE   -5
 

Functions

signed char board_initialization (void)
 
signed char initialize_RS485 (unsigned char baud_rate, unsigned char rx_interrupt_enable, unsigned char tx_interrupt_enable)
 
signed char read_data_RS485 (unsigned char *data)
 
signed char write_const_string_RS485 (const char *data)
 
signed char write_int_ASCII_RS485 (int value, char number_of_digits)
 
void send_return_RS485 (void)
 
void send_delete_RS485 (void)
 
unsigned char get_dip_switch_value (void)
 
signed char stop_motor_rotation (unsigned char motor)
 
signed char initialize_stepper_motor (unsigned char modality, unsigned char pwm_frequency, int max_current)
 
signed char step_motor_clockwise (int current)
 
signed char step_motor_anticlockwise (int current)
 
int ADC_read_POT_1 (void)
 
int ADC_read_POT_2 (void)
 
int ADC_read_TEMP (void)
 
int ADC_read_VIN_TEST (void)
 
int ADC_read_motor_current (unsigned char motor)
 
void turn_on_FAN (void)
 
void turn_off_FAN (void)
 
unsigned char system_check (void)
 
unsigned char is_emergency_stop_out_active (void)
 
unsigned char is_emergency_stop_in_active (void)
 
unsigned char set_emergency_stop_out (void)
 
unsigned char set_emergency_stop_in (void)
 
unsigned char reset_emergency_stop_out (void)
 
unsigned char reset_emergency_stop_in (void)
 
unsigned char emergency_stops_check (void)
 
int ADC_read_buffer (void)
 
void power_control_PWM_set_period (int period)
 
void set_duty_cycle_DC0 (int duty_cycle)
 
void set_duty_cycle_DC1 (int duty_cycle)
 
void initialize_interrupt (unsigned char interrupt_status)
 
void initialize_TIMER0 (unsigned char interrupt_priority)
 
void activate_signal_interupt (unsigned char signal, unsigned char interrupt_priority)
 
void set_error_status (unsigned char error)
 
unsigned char get_error_status (void)
 
void set_warning_status (unsigned char warning)
 
unsigned char get_warning_status (void)
 

Variables

volatile unsigned char error_status = 0
 
volatile unsigned char warning_status = 0
 
const int pwm_SIGNED_MAGNITUDE_frequency_table []
 
const int I_peak_current_table []
 

Macro Definition Documentation

#define ACTIVATED   1

Definition at line 89 of file init.h.

#define ADC_IS_BUSY   1

Definition at line 224 of file init.h.

#define ADC_IS_FREE   0

Definition at line 225 of file init.h.

#define ADC_MOTOR_1_TEST   0

Definition at line 216 of file init.h.

#define ADC_MOTOR_2_TEST   1

Definition at line 217 of file init.h.

#define ADC_PHASE_1_TEST   0

Definition at line 218 of file init.h.

#define ADC_PHASE_2_TEST   1

Definition at line 219 of file init.h.

#define ADC_TEMP_TEST   3

Definition at line 221 of file init.h.

#define ADC_VIN_TEST   2

Definition at line 220 of file init.h.

#define AUX_SW_1   PORTBbits.RB4

Definition at line 74 of file init.h.

#define AUX_SW_2   PORTBbits.RB5

Definition at line 75 of file init.h.

#define BAUD_RATE_115200   21

Definition at line 552 of file init.h.

#define BAUD_RATE_19200   129

Definition at line 550 of file init.h.

#define BAUD_RATE_57600   42

Definition at line 551 of file init.h.

#define BAUD_RATE_9600   255

Definition at line 549 of file init.h.

#define CLOCK_FREQUENCY   40;

Definition at line 51 of file init.h.

#define CNC_DIRECTION   PORTCbits.RC4

Definition at line 108 of file init.h.

#define CNC_DIRECTION_FLAG   INTCON3bits.INT1IF

Definition at line 111 of file init.h.

#define CNC_ENABLE   PORTCbits.RC5

Definition at line 106 of file init.h.

#define CNC_ENABLE_FLAG   INTCON3bits.INT2IF

Definition at line 112 of file init.h.

#define CNC_STEP   PORTCbits.RC3

Definition at line 107 of file init.h.

#define CNC_STEP_FLAG   INTCONbits.INT0IF

Definition at line 110 of file init.h.

#define CNC_SWITCH_FLAG   INTCONbits.RBIF

Definition at line 113 of file init.h.

#define CURRENT_0   0
Note
This table include all the LAP PWM values to set the correct Frequency. The array index is pointed by the PWM_FREQ_xxKHZ used when the motor initialization is called.

Definition at line 523 of file init.h.

#define CURRENT_1   25

Definition at line 524 of file init.h.

#define CURRENT_10   250

Definition at line 533 of file init.h.

#define CURRENT_11   275

Definition at line 534 of file init.h.

#define CURRENT_12   300

Definition at line 535 of file init.h.

#define CURRENT_13   325

Definition at line 536 of file init.h.

#define CURRENT_14   350

Definition at line 537 of file init.h.

#define CURRENT_15   375

Definition at line 538 of file init.h.

#define CURRENT_2   50

Definition at line 525 of file init.h.

#define CURRENT_3   75

Definition at line 526 of file init.h.

#define CURRENT_4   100

Definition at line 527 of file init.h.

#define CURRENT_5   125

Definition at line 528 of file init.h.

#define CURRENT_6   150

Definition at line 529 of file init.h.

#define CURRENT_7   175

Definition at line 530 of file init.h.

#define CURRENT_8   200

Definition at line 531 of file init.h.

#define CURRENT_9   225

Definition at line 532 of file init.h.

#define DEACTIVATED   0

Definition at line 90 of file init.h.

#define DEFAULT_PWM   30

Definition at line 242 of file init.h.

#define DIP_SW_1   PORTDbits.RD5

Definition at line 77 of file init.h.

#define DIP_SW_2   PORTDbits.RD6

Definition at line 78 of file init.h.

#define DIP_SW_3   PORTDbits.RD7

Definition at line 79 of file init.h.

#define DIP_SW_4   PORTBbits.RB7

Definition at line 80 of file init.h.

#define DIRECTION_SIGNAL   2

Definition at line 100 of file init.h.

#define EMG_STOP_FLTA   PORTDbits.RD4

Definition at line 117 of file init.h.

#define EMG_STOP_NOT_ACTIVATED   2

Definition at line 564 of file init.h.

#define EMG_STOP_OUT   LATCbits.LATC0

Definition at line 115 of file init.h.

#define EMG_STOP_RB6   PORTBbits.RB6

Definition at line 118 of file init.h.

#define ENABLE_HB_1   LATCbits.LATC2

Definition at line 59 of file init.h.

#define ENABLE_HB_2   LATCbits.LATC1

Definition at line 60 of file init.h.

#define ENABLE_SIGNAL   0

Definition at line 98 of file init.h.

#define ERROR_BOUDARY_SW_1   6

Definition at line 126 of file init.h.

#define ERROR_BOUDARY_SW_2   7

Definition at line 127 of file init.h.

#define ERROR_DELTA_VOLTAGE_B   9

Definition at line 129 of file init.h.

#define ERROR_DELTA_VOLTAGE_O   8

Definition at line 128 of file init.h.

#define ERROR_EMG_STOP_ACTIVE   -5

Definition at line 571 of file init.h.

#define ERROR_LED   LATDbits.LATD1

Definition at line 65 of file init.h.

#define ERROR_MODALITY_NOT_DEFINED   -1

Definition at line 567 of file init.h.

#define ERROR_OVER_CURRENT_M_1   3

Definition at line 123 of file init.h.

#define ERROR_OVER_CURRENT_M_2   4

Definition at line 124 of file init.h.

#define ERROR_OVER_TEMP   5

Definition at line 125 of file init.h.

#define ERROR_OVER_VOLTAGE   1

Definition at line 121 of file init.h.

#define ERROR_RX_DATA_NOT_READY   -2

Definition at line 568 of file init.h.

#define ERROR_UNDER_VOLTAGE   2

Definition at line 122 of file init.h.

#define ERROR_VIN_MAX   -3

Definition at line 569 of file init.h.

#define ERROR_VIN_MIN   -4

Definition at line 570 of file init.h.

#define FALLING_EDGE   0

Definition at line 104 of file init.h.

#define FLAG_CLEAR   0

Definition at line 93 of file init.h.

#define FLAG_SET   1

Definition at line 92 of file init.h.

#define FULL_STEP   1

Definition at line 150 of file init.h.

#define FULL_STEP_2_PHASES   2

Definition at line 151 of file init.h.

#define FULL_STEP_2_PHASES_NR_STATES   4

Definition at line 199 of file init.h.

#define FULL_STEP_2_PHASES_STATE_1   10

Definition at line 195 of file init.h.

#define FULL_STEP_2_PHASES_STATE_2   9

Definition at line 196 of file init.h.

#define FULL_STEP_2_PHASES_STATE_3   5

Definition at line 197 of file init.h.

#define FULL_STEP_2_PHASES_STATE_4   6

Definition at line 198 of file init.h.

#define FULL_STEP_NR_STATES   4

Definition at line 191 of file init.h.

#define FULL_STEP_STATE_1   2

Definition at line 187 of file init.h.

#define FULL_STEP_STATE_2   8

Definition at line 188 of file init.h.

#define FULL_STEP_STATE_3   1

Definition at line 189 of file init.h.

#define FULL_STEP_STATE_4   4

Definition at line 190 of file init.h.

#define GND   0

Definition at line 86 of file init.h.

#define HALF_STEP   3

Definition at line 152 of file init.h.

#define HALF_STEP_NR_STATES   8

Definition at line 210 of file init.h.

#define HALF_STEP_STATE_1   2

Definition at line 202 of file init.h.

#define HALF_STEP_STATE_2   10

Definition at line 203 of file init.h.

#define HALF_STEP_STATE_3   8

Definition at line 204 of file init.h.

#define HALF_STEP_STATE_4   9

Definition at line 205 of file init.h.

#define HALF_STEP_STATE_5   1

Definition at line 206 of file init.h.

#define HALF_STEP_STATE_6   5

Definition at line 207 of file init.h.

#define HALF_STEP_STATE_7   4

Definition at line 208 of file init.h.

#define HALF_STEP_STATE_8   6

Definition at line 209 of file init.h.

#define HEART_LED   LATDbits.LATD0

Definition at line 64 of file init.h.

#define HIGH_LEVEL_PRIORITY   1

Definition at line 96 of file init.h.

#define IN1_HB_1   LATBbits.LATB0

Definition at line 53 of file init.h.

#define IN1_HB_2   LATBbits.LATB2

Definition at line 56 of file init.h.

#define IN2_HB_1   LATBbits.LATB1

Definition at line 54 of file init.h.

#define IN2_HB_2   LATBbits.LATB3

Definition at line 57 of file init.h.

#define LAP   1

Definition at line 155 of file init.h.

#define LED_1   LATDbits.LATD0

Definition at line 62 of file init.h.

#define LED_2   LATDbits.LATD1

Definition at line 63 of file init.h.

#define LED_OFF   0

Definition at line 83 of file init.h.

#define LED_ON   1

Definition at line 82 of file init.h.

#define LOW_LEVEL_PRIORITY   0

Definition at line 95 of file init.h.

#define MAX_PHASE_CURRENT_PEAK   500

Definition at line 184 of file init.h.

#define MAX_SPEED   1023

Definition at line 161 of file init.h.

#define MIN_SPEED   0

Definition at line 162 of file init.h.

#define MOTOR_1   1

Definition at line 145 of file init.h.

#define MOTOR_2   2

Definition at line 146 of file init.h.

#define MOTOR_ALL   3

Definition at line 147 of file init.h.

#define OPERATION_PROPERLY_EXECUTED   1

Definition at line 565 of file init.h.

#define POWER_CONTROL_HALF_RESOLUTION   511

Definition at line 234 of file init.h.

#define PWM_FREQ_10KHZ   9

Definition at line 253 of file init.h.

#define PWM_FREQ_11KHZ   10

Definition at line 254 of file init.h.

#define PWM_FREQ_12KHZ   11

Definition at line 255 of file init.h.

#define PWM_FREQ_13KHZ   12

Definition at line 256 of file init.h.

#define PWM_FREQ_14KHZ   13

Definition at line 257 of file init.h.

#define PWM_FREQ_15KHZ   14

Definition at line 258 of file init.h.

#define PWM_FREQ_16KHZ   15

Definition at line 259 of file init.h.

#define PWM_FREQ_17KHZ   16

Definition at line 260 of file init.h.

#define PWM_FREQ_18KHZ   17

Definition at line 261 of file init.h.

#define PWM_FREQ_19KHZ   18

Definition at line 262 of file init.h.

#define PWM_FREQ_1KHZ   0

Definition at line 244 of file init.h.

#define PWM_FREQ_20KHZ   19

Definition at line 263 of file init.h.

#define PWM_FREQ_21KHZ   20

Definition at line 264 of file init.h.

#define PWM_FREQ_22KHZ   21

Definition at line 265 of file init.h.

#define PWM_FREQ_23KHZ   22

Definition at line 266 of file init.h.

#define PWM_FREQ_24KHZ   23

Definition at line 267 of file init.h.

#define PWM_FREQ_25KHZ   24

Definition at line 268 of file init.h.

#define PWM_FREQ_26KHZ   25

Definition at line 269 of file init.h.

#define PWM_FREQ_27KHZ   26

Definition at line 270 of file init.h.

#define PWM_FREQ_28KHZ   27

Definition at line 271 of file init.h.

#define PWM_FREQ_29KHZ   28

Definition at line 272 of file init.h.

#define PWM_FREQ_2KHZ   1

Definition at line 245 of file init.h.

#define PWM_FREQ_30KHZ   29

Definition at line 273 of file init.h.

#define PWM_FREQ_31KHZ   30

Definition at line 274 of file init.h.

#define PWM_FREQ_32KHZ   31

Definition at line 275 of file init.h.

#define PWM_FREQ_33KHZ   32

Definition at line 276 of file init.h.

#define PWM_FREQ_34KHZ   33

Definition at line 277 of file init.h.

#define PWM_FREQ_35KHZ   34

Definition at line 278 of file init.h.

#define PWM_FREQ_36KHZ   35

Definition at line 279 of file init.h.

#define PWM_FREQ_37KHZ   36

Definition at line 280 of file init.h.

#define PWM_FREQ_38KHZ   37

Definition at line 281 of file init.h.

#define PWM_FREQ_39KHZ   38

Definition at line 282 of file init.h.

#define PWM_FREQ_3KHZ   2

Definition at line 246 of file init.h.

#define PWM_FREQ_40KHZ   39

Definition at line 283 of file init.h.

#define PWM_FREQ_41KHZ   40

Definition at line 284 of file init.h.

#define PWM_FREQ_42KHZ   41

Definition at line 285 of file init.h.

#define PWM_FREQ_43KHZ   42

Definition at line 286 of file init.h.

#define PWM_FREQ_44KHZ   43

Definition at line 287 of file init.h.

#define PWM_FREQ_45KHZ   44

Definition at line 288 of file init.h.

#define PWM_FREQ_46KHZ   45

Definition at line 289 of file init.h.

#define PWM_FREQ_47KHZ   46

Definition at line 290 of file init.h.

#define PWM_FREQ_48KHZ   47

Definition at line 291 of file init.h.

#define PWM_FREQ_49KHZ   48

Definition at line 292 of file init.h.

#define PWM_FREQ_4KHZ   3

Definition at line 247 of file init.h.

#define PWM_FREQ_50KHZ   49

Definition at line 293 of file init.h.

#define PWM_FREQ_5KHZ   4

Definition at line 248 of file init.h.

#define PWM_FREQ_6KHZ   5

Definition at line 249 of file init.h.

#define PWM_FREQ_7KHZ   6

Definition at line 250 of file init.h.

#define PWM_FREQ_8KHZ   7

Definition at line 251 of file init.h.

#define PWM_FREQ_9KHZ   8

Definition at line 252 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_10KHZ   62

Definition at line 309 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_11KHZ   56

Definition at line 310 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_12KHZ   51

Definition at line 311 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_13KHZ   47

Definition at line 312 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_14KHZ   44

Definition at line 313 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_15KHZ   41

Definition at line 314 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_16KHZ   38

Definition at line 315 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_17KHZ   36

Definition at line 316 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_18KHZ   34

Definition at line 317 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_19KHZ   32

Definition at line 318 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_1KHZ   25

Definition at line 300 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_20KHZ   30

Definition at line 319 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_21KHZ   29

Definition at line 320 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_22KHZ   27

Definition at line 321 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_23KHZ   26

Definition at line 322 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_24KHZ   25

Definition at line 323 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_25KHZ   24

Definition at line 324 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_26KHZ   23

Definition at line 325 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_27KHZ   22

Definition at line 326 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_28KHZ   21

Definition at line 327 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_29KHZ   21

Definition at line 328 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_2KHZ   255

Definition at line 301 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_30KHZ   20

Definition at line 329 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_31KHZ   19

Definition at line 330 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_32KHZ   19

Definition at line 331 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_33KHZ   18

Definition at line 332 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_34KHZ   17

Definition at line 333 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_35KHZ   17

Definition at line 334 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_36KHZ   16

Definition at line 335 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_37KHZ   16

Definition at line 336 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_38KHZ   15

Definition at line 337 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_39KHZ   15

Definition at line 338 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_3KHZ   207

Definition at line 302 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_40KHZ   15

Definition at line 339 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_41KHZ   14

Definition at line 340 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_42KHZ   14

Definition at line 341 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_43KHZ   14

Definition at line 342 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_44KHZ   13

Definition at line 343 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_45KHZ   13

Definition at line 344 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_46KHZ   13

Definition at line 345 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_47KHZ   12

Definition at line 346 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_48KHZ   12

Definition at line 347 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_49KHZ   12

Definition at line 348 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_4KHZ   155

Definition at line 303 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_50KHZ   12

Definition at line 349 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_5KHZ   124

Definition at line 304 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_6KHZ   103

Definition at line 305 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_7KHZ   88

Definition at line 306 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_8KHZ   77

Definition at line 307 of file init.h.

#define PWM_SIGNED_MAGNITUDE_FREQ_9KHZ   68

Definition at line 308 of file init.h.

#define READ_ONLY   0

Definition at line 69 of file init.h.

#define READ_WRITE   1

Definition at line 70 of file init.h.

#define RISING_EDGE   1

Definition at line 103 of file init.h.

#define RS485_MODE   LATDbits.LATD2

Definition at line 68 of file init.h.

#define RS485_OUT_ENABLE   LATDbits.LATD2

Definition at line 67 of file init.h.

#define RX_INTERRUPT_OFF   USART_RX_INT_OFF

Definition at line 557 of file init.h.

#define RX_INTERRUPT_ON   USART_RX_INT_ON

Definition at line 556 of file init.h.

#define SIGNED_MAGNITUDE   2

Definition at line 156 of file init.h.

#define STEP_SIGNAL   1

Definition at line 99 of file init.h.

#define STEPPER   3

Definition at line 157 of file init.h.

#define SWITCH_SIGNAL   3

Definition at line 101 of file init.h.

#define SYSTEM_MONITOR_TEST   4

Definition at line 222 of file init.h.

#define TEMP   LATDbits.LATD3

Definition at line 72 of file init.h.

#define TEMP_HYSTERESIS   6

Definition at line 180 of file init.h.

#define TEMP_MAX   65

Definition at line 177 of file init.h.

#define TEMP_WARNING_1   35

Definition at line 178 of file init.h.

#define TEMP_WARNING_2   45

Definition at line 179 of file init.h.

#define TX_INTERRUPT_OFF   USART_TX_INT_OFF

Definition at line 555 of file init.h.

#define TX_INTERRUPT_ON   USART_TX_INT_ON

Definition at line 554 of file init.h.

#define VCC   1

Definition at line 85 of file init.h.

#define VIN_DELTA_ERROR   3

Definition at line 171 of file init.h.

#define VIN_DELTA_WARNING   2

Definition at line 170 of file init.h.

#define VIN_MAX   28

Definition at line 169 of file init.h.

#define VIN_MIN   11

Definition at line 168 of file init.h.

#define WARNING_COMMUNICATION   0b00010000

Definition at line 138 of file init.h.

#define WARNING_DELTA_VOLTAGE_B   0b00000100

Definition at line 136 of file init.h.

#define WARNING_DELTA_VOLTAGE_O   0b00000010

Definition at line 135 of file init.h.

#define WARNING_MISSING_STEPS   0b00000001

Definition at line 134 of file init.h.

#define WARNING_NOT_DEFINED_2   0b00100000

Definition at line 139 of file init.h.

#define WARNING_NOT_DEFINED_3   0b01000000

Definition at line 140 of file init.h.

#define WARNING_NOT_DEFINED_4   0b10000000

Definition at line 141 of file init.h.

#define WARNING_TEMPERATURE   0b00001000

Definition at line 137 of file init.h.

Function Documentation

void activate_signal_interupt ( unsigned char  signal,
unsigned char  interrupt_priority 
)

The function activate the interrupt for one of the follwowing signal ENABLE, STEP, DIRECTION, SWITCH

Parameters
interrupt_priorityIt specifies the Interrupt Priority Level
Returns

Definition at line 1098 of file init.c.

int ADC_read_buffer ( void  )

Definition at line 724 of file init.c.

int ADC_read_motor_current ( unsigned char  motor)

The function reads the the current sinked from the selected Motor. The returned value is expressed in mA. This function is called from system_check () to monitor that the curernt is within maximum pick motor current.

Parameters
motorSelect the motor from which the curren shlould be read. Value [MOTOR_1, MOTOR_2].
Returns
Current expressed in mA from the selected motor.
Note
The ADC reading is a blocking function until the ADC conversion is over and the ADC buffer is read out.

Definition at line 807 of file init.c.

int ADC_read_POT_1 ( void  )

The function reads the the voltage from the potenziometer POT_1 connected to AUX_1 connector.

Parameters
@returnAnalog value from the Potenziometer POT_1 connected to AUX_1. The value is expressed in quantum.
Note
The ADC reading is a blocking function until the ADC conversion is over and the ADC buffer is read out.

Definition at line 745 of file init.c.

int ADC_read_POT_2 ( void  )

The function reads the the voltage from the potenziometer POT_2 connected to AUX_2 connector.

Parameters
@returnAnalog value from the Potenziometer POT_2 connected to AUX_2. The value is expressed in quantum.
Note
The ADC reading is a blocking function until the ADC conversion is over and the ADC buffer is read out.

Definition at line 760 of file init.c.

int ADC_read_TEMP ( void  )

The function reads the the voltage from the temperature sensor AN_TEMP and returns the reading expressed in celsius degree. This function is called from system_check () to monitor that the temperature is less than TEMP_MAX. If the themperature reachs TEMP_WARNING the fun is turned on.

Parameters
@returnAnalog value from the temperature sensor AN_TEMP expressed in celsius degree.
Note
The ADC reading is a blocking function until the ADC conversion is over and the ADC buffer is read out.

Definition at line 775 of file init.c.

int ADC_read_VIN_TEST ( void  )

The function reads the the voltage from the temperature sensor VIN_TEST and returns the reading expressed in V. This function is called from system_check () to monitor that the voltage is within VIN_MIN and VIN_MAX.

Parameters
@returnAnalog value from the temperature sensor VIN_TEST expressed in V.
Note
The ADC reading is a blocking function until the ADC conversion is over and the ADC buffer is read out.

Definition at line 790 of file init.c.

signed char board_initialization ( void  )

The functions initializes the board and hardware. All the PIC pins are properly set either as Input or Output. It should be called one time right after the main () function.

Parameters
@returnerror: Refer to the defined error constants.

Definition at line 94 of file init.c.

unsigned char emergency_stops_check ( void  )

The function checks the emergency stop conditions. If either the emergency stop in or out are activeted any motion activity is halted.

Parameters
@returnStatus: EMG_STOP_NOT_ACTIVATED, ERROR_EMG_STOP_ACTIVE

Definition at line 1045 of file init.c.

unsigned char get_dip_switch_value ( void  )

The function reads the position of the dip switches. Jumper JP1 must be properly set if dip switch 4 must be used.

Parameters
@returndip_switch_value It returns the dip switch value.

Definition at line 701 of file init.c.

unsigned char get_error_status ( void  )

This function returns the error status global variable.

Parameters
@returnError Status

Definition at line 1183 of file init.c.

unsigned char get_warning_status ( void  )

This function returns the warning status global variable.

Parameters
@returnError Status

Definition at line 1198 of file init.c.

void initialize_interrupt ( unsigned char  interrupt_status)

The function allows enabling and disabling system interrupt.

Parameters
interrupt_statusIt specifies whether the interrupts need to be activated or not.
Returns

Definition at line 1150 of file init.c.

signed char initialize_RS485 ( unsigned char  baud_rate,
unsigned char  rx_interrupt_enable,
unsigned char  tx_interrupt_enable 
)

The function activates and initializes the UART used for the RS485 communication. It should be called before using the RS485 bus and after having initialized the board.

Parameters
baud_rateIs the communication baud rate. Value [BAUD_RATE_9600, BAUD_RATE_19200, BAUD_RATE_57600, BAUD_RATE_115200 ]
rx_interrupt_enableEnable or deactivate the RX interrupt. Value [RX_INTERRUPT_ON, RX_INTERRUPT_OFF]
tx_interrupt_enableEnable or deactivate the RX interrupt. Calue [TX_INTERRUPT_ON, TX_INTERRUPT_OFF]
Returns
error: Refer to the defined error constants.
Note
The UART settings, beside the baudrate that can be selected are: 8 bit format, 1 bit stop, No parity and No hardware handshaking.

Definition at line 564 of file init.c.

signed char initialize_stepper_motor ( unsigned char  modality,
unsigned char  pwm_frequency,
int  max_current 
)

The function initializes the stepper motor either in Full step, full step two phases or half step. The funtion should be called once, before using the stepper motor functions. It also sets the PWM at which the motor will be driven and the maximum current that will be monitored. Maximum current is monitored using the check_system () function, that should be called periodicaly.

Parameters
modalityIt sets the motor modality in Full step, full step two phases or half step. Value [FULL_STEP, FULL_STEP_2_PHASES, HALF_STEP)
pwm_frequencyIt sest the PWM frequency. Value [PWM_FREQ_1KHZ - PWM_FREQ_50KHZ].
max_currentIt sets the maximum pick current used by the motor expressed in mA. Value [min. 0, max. 5000]
Returns
error: Refer to the defined error constants.
Note
The PWM frequency is not optimyzed to let the user gets the maximum PWM resolution. Timer Prescaler should be set differently if an optimiziation is wanted or required.

Definition at line 840 of file init.c.

void initialize_TIMER0 ( unsigned char  interrupt_priority)

The function initializes the TIMER0 and activate the interuppt.

Parameters
interrupt_priorityIt specifies the Interrupt Priority Level
Returns

Definition at line 1064 of file init.c.

unsigned char is_emergency_stop_in_active ( void  )

The function checks if the emergency stop IN is activated. This is done monitoring the global flag associated to the emergency stop IN.

Parameters
@returnStatus: Emergency stop status. Value [ACTIVATED, DEACTIVATED]
Note
Status 1: EMG_STOP_IN is Active, 0: EMG_STOP_IN is not Active

Definition at line 989 of file init.c.

unsigned char is_emergency_stop_out_active ( void  )

The function checks if the emergency stop OUT is activated. This is done monitoring the global flag associated to the emergency stop OUT.

Parameters
@returnStatus: Emergency stop status. Value [ACTIVATED, DEACTIVATED]
Note
Status 1: EMG_STOP_OUT is Active, 0: EMG_STOP_OUT is not Active

Definition at line 977 of file init.c.

void power_control_PWM_set_period ( int  period)

The function sets the period of the Power Control PWM module (12 bit resolution).

Parameters
periodIt sets the period of the Power Control PWM module (12 bit resolution). Value [ min. 0 - max. 4095].
Returns
Warning
The actual resolution depends on the Frequency and Prescaler settings.
This function should be consdired Private so it should not be used within the user applications.

Definition at line 304 of file init.c.

signed char read_data_RS485 ( unsigned char *  data)

The function reads the data out of the UART input buffer. The UART Input buffer is filled with the data coming from the RS485 bus. The function is a non blocking function. If no data is within the buffer it returns ERROR_RX_DATA_NOT_READY, otherwise OPERATION_PROPERLY_EXECUTED.

Parameters
*dataPointer to the unsigned char that will contain the received data.
Returns
error: Refer to the defined error constants.

Definition at line 601 of file init.c.

unsigned char reset_emergency_stop_in ( void  )

The function resets the emergency stop IN and pin. The global flag associated to the emergency stop IN is also set to DEACTIVATED.

Parameters
@returnStatus: OPERATION_PROPERLY_EXECUTED
Note
Status 1: EMG_STOP_IN is Active, 0: EMG_STOP_IN is not Active

Definition at line 1033 of file init.c.

unsigned char reset_emergency_stop_out ( void  )

The function resets the emergency stop OUT and pin. The global flag associated to the emergency stop OUT is also set to DEACTIVATED.

Parameters
@returnStatus: OPERATION_PROPERLY_EXECUTED
Note
Status 1: EMG_STOP_OUT is Active, 0: EMG_STOP_OUT is not Active

Definition at line 1022 of file init.c.

void send_delete_RS485 ( void  )

The function sends a Delete ASCII code via RS485.

Parameters
@return

Definition at line 642 of file init.c.

void send_return_RS485 ( void  )

The function sends a Carriage Return via RS485.

Parameters
@return

Definition at line 629 of file init.c.

void set_duty_cycle_DC0 ( int  duty_cycle)

The function sets the period of the PWM 0 module (10 bit resolution).

Parameters
duty_cycleIt sets the period of the PWM 0 module (10 bit resolution). Value [ min. 0 - max. 1023].
Returns
Warning
The actual resolution depends on the Frequency and Prescaler settings.
This function should be consdired Private so it should not be used within the user applications.

Definition at line 314 of file init.c.

void set_duty_cycle_DC1 ( int  duty_cycle)

The function sets the period of the PWM 1 module (10 bit resolution).

Parameters
duty_cycleIt sets the period of the PWM 1 module (10 bit resolution). Value [ min. 0 - max. 1023].
Returns
Warning
The actual resolution depends on the Frequency and Prescaler settings.
This function should be consdired Private so it should not be used within the user applications.

Definition at line 325 of file init.c.

unsigned char set_emergency_stop_in ( void  )

The function sets the emergency stop IN to activated. The global flag associated to the emergency stop IN is also set to ACTIVATED.

Parameters
@returnStatus: OPERATION_PROPERLY_EXECUTED
Note
Status 1: EMG_STOP_IN is Active, 0: EMG_STOP_IN is not Active

Definition at line 1011 of file init.c.

unsigned char set_emergency_stop_out ( void  )

The function sets the emergency stop OUT to ACTIVATED and the EMG_OUT pin is set to 1. The global flag associated to the emergency stop OUT is also set to ACTIVATED.

Parameters
@returnStatus: OPERATION_PROPERLY_EXECUTED
Note
Status 1: EMG_STOP_OUT is Active, 0: EMG_STOP_OUT is not Active

Definition at line 1000 of file init.c.

void set_error_status ( unsigned char  error)

This function sest the error statud global variable accordingly to the Error flags.

Parameters
errorIt specifies the error to be added to the status
Returns

Definition at line 1176 of file init.c.

void set_warning_status ( unsigned char  warning)

This function sets the warning status global variable accordingly to the Warning flags.

Parameters
warningIt specifies the warning to be added to the status
Returns

Definition at line 1191 of file init.c.

signed char step_motor_anticlockwise ( int  current)

The function rotates the stepper motor anticlockwise at certain torque. The motors should be properly initialized before this function can be used.

Parameters
currentPhase current wanted for that rotation expressed in mA. Value [ min. 1 - max. 4000]
Returns
error: refer to the defined error constants
Warning
Currently the current is not monitored and the value does not acually represents the wanted current but the value written inside the PWM period register. For that reason care should be taken to not excede the maximum PWM resolution.

Definition at line 935 of file init.c.

signed char step_motor_clockwise ( int  current)

The function rotates the stepper motor clockwise at certain torque. The motors should be properly initialized before this function can be used.

Parameters
currentPhase current wanted for that rotation expressed in mA. Value [ min. 1 - max. 4000]
Returns
error: Refer to the defined error constants.
Warning
Currently the current is not monitored and the value does not acually represents the wanted current but the value written inside the PWM period register. For that reason care should be taken to not excede the maximum PWM resolution.

Definition at line 907 of file init.c.

signed char stop_motor_rotation ( unsigned char  motor)

The function initializes the DC motors either as LAP or Signed Magnitude modality. The function should be called just once, before using the motor functions. It also sets the PWM at which the motors will be driven and the maximum current that will be monitored. Maximum current is monitored using the check_system () function, that should be called periodicaly.

Parameters
modalityIt sets the motor modality eiter as LAP or Signed Magnitude. Value [LAP, SIGNED_MAGNITUDE]
pwm_frequencyIt sets the PWM frequency. Value [PWM_FREQ_1KHZ - PWM_FREQ_50KHZ].
max_currentit sets the maximum pick current used by the motor expressed in mA. Value [min. 1, max. 5000]
Returns
error: Refer to the defined error constants.
Note
The PWM frequency is not optimyzed to let the user gets the maximum PWM resolution. Timer Prescaler should be set differently if an optimiziation is wanted or required. The functions rotates the DC motor clockwise. The motors should be properly initialized before this function can be used.
Parameters
motorIndicates the motor that should be rotated clockwise. Value [MOTOR_1, MOTOR_2, MOTOR_ALL]
speedMotor speed. Value [ min. 1- max. 30000]
Returns
error: Refer to the defined error constants.
Warning
Currently the speed is not monitored and the value does not acually represents the rpm (root per minute)but the value written inside the PWM period register. For that reason care should be taken to not exceed the maximum PWM resolution. the function rotates the DC motor anticlockwise. The motors should be properly initialized before this function can be used.
Parameters
motorIndicates the motor that should be rotated anticlockwise. Value [MOTOR_1, MOTOR_2, MOTOR_ALL]
speedMotor speed. Value [ min. 1- max. 30000]
Returns
error: Refer to the defined error constants.
Warning
Currently the speed is not monitored and the value does not acually represents the rpm (root per minute)but the value written inside the PWM period register. For that reason care should be taken to not exceed the maximum PWM resolution. The function stops the motor rotation, either DC motor or stepper motor. The motors should be properly initialized before this function can be used. It could be used for an emergency stop, beside other actions.
Parameters
motorIndicates the motor that should be halted. Value [MOTOR_1, MOTOR_2, MOTOR_ALL]
Returns
error: Refer to the defined error constants.
Note
If a Stepper motor is used the input parameter is ignored [MOTOR_1, MOTOR_2, MOTOR_ALL], so any choise would be fine.. For code consistency MOTOR_1 is reccomended to be used.

Definition at line 485 of file init.c.

unsigned char system_check ( void  )

The function checks that the system is working within the maximum values. Temperature, Current and supply voltage are checked out.

Parameters
@returnStatus: system status
Note
If an anomaly is detected the set_emergency_stop_out is called and the system is halted. ERROR_LED is turned on.
If themperature gets hiher than TEMP_MAX the motors are halted. If Themperature gets higher than TEMP_WARNING, the fun is turned ON. The fun is turned OFF, only if the Themperature gets reduced to TEMP_WARNING - TEMP_HYSTERESIS.
Warning
This function should be called periodically. If not periodically called the system is not monitored.

Definition at line 189 of file init.c.

void turn_off_FAN ( void  )

The function turns the Fun OFF. If system_check is regularly called, the fun is turned off if the themperature gets lower than TEMP_WARNING - TEMP_HYSTERESIS.

Parameters
@return

Definition at line 970 of file init.c.

void turn_on_FAN ( void  )

The function turns the Fun ON. If system_check is regularly called, the fun is turned on if the themperature gets higher than TEMP_WARNING.

Parameters
@return

Definition at line 963 of file init.c.

signed char write_const_string_RS485 ( const char *  data)

The function writes a constant string stored to the rom area, to the UART. The function is a blocking function until the data is sent out. RS485 is automaticly changed to READ_WRITE mode and than back to READ_ONLY once the data is sent out.

Parameters
*dataPointer to a constant string (eg. write_const_string_RS485 ("Hello World")).
Returns
error: Refer to the defined error constants.

Definition at line 614 of file init.c.

signed char write_int_ASCII_RS485 ( int  value,
char  number_of_digits 
)

The function writes an Integer to the RS485 bus with a defined number of digits. The function is a blocking function until the data is sent out. RS485 is automaticly changed to READ_WRITE mode and than back to READ_ONLY once the data is sent out.

Parameters
valueInteger value to be sent on the RS485 bus.

Number of significant digits out of the integer number digits.

Returns
error: Refer to the defined error constants.

Variable Documentation

volatile unsigned char error_status = 0

Definition at line 131 of file init.h.

const int I_peak_current_table[]
const int pwm_SIGNED_MAGNITUDE_frequency_table[]
Initial value:
}
Note
This table includes all the SIGNED MAGNITUDE PWM values to set the correct Frequency. The array index is pointed by the PWM_FREQ_xxKHZ used when the motor initialization is called.

Definition at line 412 of file init.h.

volatile unsigned char warning_status = 0

Definition at line 143 of file init.h.