PJ3007 Project
1.1
Motor Controller Board. 4A dual H Bridge
|
#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.
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 [] |
#define CURRENT_0 0 |
void activate_signal_interupt | ( | unsigned char | signal, |
unsigned char | interrupt_priority | ||
) |
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.
motor | Select the motor from which the curren shlould be read. Value [MOTOR_1, MOTOR_2]. |
int ADC_read_POT_1 | ( | void | ) |
The function reads the the voltage from the potenziometer POT_1 connected to AUX_1 connector.
@return | Analog value from the Potenziometer POT_1 connected to AUX_1. The value is expressed in quantum. |
int ADC_read_POT_2 | ( | void | ) |
The function reads the the voltage from the potenziometer POT_2 connected to AUX_2 connector.
@return | Analog value from the Potenziometer POT_2 connected to AUX_2. The value is expressed in quantum. |
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.
@return | Analog value from the temperature sensor AN_TEMP expressed in celsius degree. |
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.
@return | Analog value from the temperature sensor VIN_TEST expressed in V. |
signed char board_initialization | ( | void | ) |
unsigned char emergency_stops_check | ( | void | ) |
unsigned char get_dip_switch_value | ( | void | ) |
unsigned char get_error_status | ( | void | ) |
unsigned char get_warning_status | ( | void | ) |
void initialize_interrupt | ( | unsigned char | interrupt_status | ) |
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.
baud_rate | Is the communication baud rate. Value [BAUD_RATE_9600, BAUD_RATE_19200, BAUD_RATE_57600, BAUD_RATE_115200 ] |
rx_interrupt_enable | Enable or deactivate the RX interrupt. Value [RX_INTERRUPT_ON, RX_INTERRUPT_OFF] |
tx_interrupt_enable | Enable or deactivate the RX interrupt. Calue [TX_INTERRUPT_ON, TX_INTERRUPT_OFF] |
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.
modality | It sets the motor modality in Full step, full step two phases or half step. Value [FULL_STEP, FULL_STEP_2_PHASES, HALF_STEP) |
pwm_frequency | It sest the PWM frequency. Value [PWM_FREQ_1KHZ - PWM_FREQ_50KHZ]. |
max_current | It sets the maximum pick current used by the motor expressed in mA. Value [min. 0, max. 5000] |
void initialize_TIMER0 | ( | unsigned char | interrupt_priority | ) |
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.
@return | Status: Emergency stop status. Value [ACTIVATED, DEACTIVATED] |
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.
@return | Status: Emergency stop status. Value [ACTIVATED, DEACTIVATED] |
void power_control_PWM_set_period | ( | int | period | ) |
The function sets the period of the Power Control PWM module (12 bit resolution).
period | It sets the period of the Power Control PWM module (12 bit resolution). Value [ min. 0 - max. 4095]. |
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.
*data | Pointer to the unsigned char that will contain the received data. |
unsigned char reset_emergency_stop_in | ( | void | ) |
unsigned char reset_emergency_stop_out | ( | void | ) |
void send_delete_RS485 | ( | void | ) |
void send_return_RS485 | ( | void | ) |
void set_duty_cycle_DC0 | ( | int | duty_cycle | ) |
The function sets the period of the PWM 0 module (10 bit resolution).
duty_cycle | It sets the period of the PWM 0 module (10 bit resolution). Value [ min. 0 - max. 1023]. |
void set_duty_cycle_DC1 | ( | int | duty_cycle | ) |
The function sets the period of the PWM 1 module (10 bit resolution).
duty_cycle | It sets the period of the PWM 1 module (10 bit resolution). Value [ min. 0 - max. 1023]. |
unsigned char set_emergency_stop_in | ( | void | ) |
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.
@return | Status: OPERATION_PROPERLY_EXECUTED |
void set_error_status | ( | unsigned char | error | ) |
void set_warning_status | ( | unsigned char | warning | ) |
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.
current | Phase current wanted for that rotation expressed in mA. Value [ min. 1 - max. 4000] |
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.
current | Phase current wanted for that rotation expressed in mA. Value [ min. 1 - max. 4000] |
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.
modality | It sets the motor modality eiter as LAP or Signed Magnitude. Value [LAP, SIGNED_MAGNITUDE] |
pwm_frequency | It sets the PWM frequency. Value [PWM_FREQ_1KHZ - PWM_FREQ_50KHZ]. |
max_current | it sets the maximum pick current used by the motor expressed in mA. Value [min. 1, max. 5000] |
motor | Indicates the motor that should be rotated clockwise. Value [MOTOR_1, MOTOR_2, MOTOR_ALL] |
speed | Motor speed. Value [ min. 1- max. 30000] |
motor | Indicates the motor that should be rotated anticlockwise. Value [MOTOR_1, MOTOR_2, MOTOR_ALL] |
speed | Motor speed. Value [ min. 1- max. 30000] |
motor | Indicates the motor that should be halted. Value [MOTOR_1, MOTOR_2, MOTOR_ALL] |
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.
@return | Status: system status |
void turn_off_FAN | ( | void | ) |
void turn_on_FAN | ( | void | ) |
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.
*data | Pointer to a constant string (eg. write_const_string_RS485 ("Hello World")). |
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.
value | Integer value to be sent on the RS485 bus. |
Number of significant digits out of the integer number digits.
const int I_peak_current_table[] |
const int pwm_SIGNED_MAGNITUDE_frequency_table[] |