R2R
Macros | Functions
CurrentControl.c File Reference

The source for the current control file. More...

#include "r2r.h"
#include "CurrentControl.h"
#include "PositionControl.h"
#include "Motor.h"
#include "Utilities.h"
#include <stdio.h>

Macros

#define SWITCHDELAY   30
 
#define MA_PER_COUNT   5.75474330357
 

Functions

void currentControlInit (void)
 Init ADC. More...
 
void CurrentControlIntHandler (void)
 The interrupt handler for the current control loop. More...
 
void PI_controller (int motor, int reference, int actual)
 Simple PI controller that uses motorxControlPWM to control the motor output. More...
 
void get_current_gains (void)
 Print the current gains to UART. More...
 
void set_current_gains (void)
 Sets the current gains by reading the UART buffer. More...
 
void setCurrent (int motor, int u)
 Sets the reference current for a given motor. More...
 
int getCurrent (int motor)
 Gets the motor current in counts (12 bit signed) More...
 
void reset_current_error (void)
 Sets the current gains by reading the UART buffer. More...
 
void counts_read (void)
 Reads the counts of the current to UART from an array. More...
 
void AD0_read (int mux)
 Triggers the ADC reading and saves it to the TEMP array. More...
 
void get_mA (void)
 Print the current in mA to UART. More...
 
void get_counts (void)
 Print the current counts to UART. More...
 
void setADCMux (int motor, int number)
 Sets the ADC MUX to read from either the current sense resistor 1, 2 or 3 from motor 1 or 2. More...
 

Detailed Description

The source for the current control file.

This file contains the functions for current sensing and control.

Author
Benjamen Lim
Huan Weng
Blake Strebel

Function Documentation

◆ AD0_read()

void AD0_read ( int  mux)

Triggers the ADC reading and saves it to the TEMP array.

On the PCB you have to specify either 1 or 2 to read the phase. For the breadboard prototype the number does not matter

Parameters
intthe muxed pins, specify 1 for phase A and 2 for phase B
Returns
Void

◆ counts_read()

void counts_read ( void  )

Reads the counts of the current to UART from an array.

Parameters
Void
Returns
Void

◆ currentControlInit()

void currentControlInit ( void  )

Init ADC.

Initialises ADC with Sequence 0, capturing 8 samples and a FIFO depth of 8 32-bit words, with last 12 bits containing the conversion result

Parameters
Void
Returns
Void

◆ CurrentControlIntHandler()

void CurrentControlIntHandler ( void  )

The interrupt handler for the current control loop.

Parameters
Void
Returns
Void

◆ get_counts()

void get_counts ( void  )

Print the current counts to UART.

Parameters
Void
Returns
Void

◆ get_current_gains()

void get_current_gains ( void  )

Print the current gains to UART.

Parameters
Void
Returns
Void

◆ get_mA()

void get_mA ( void  )

Print the current in mA to UART.

Parameters
Void
Returns
Void

◆ getCurrent()

int getCurrent ( int  motor)

Gets the motor current in counts (12 bit signed)

Parameters
intmotor
Returns
int motor current in counts (12 bit signed)

◆ PI_controller()

void PI_controller ( int  motor,
int  reference,
int  actual 
)

Simple PI controller that uses motorxControlPWM to control the motor output.

Parameters
intmotor
intreference value
intactual value
Returns
Void

◆ reset_current_error()

void reset_current_error ( void  )

Sets the current gains by reading the UART buffer.

Parameters
Void
Returns
Void

◆ set_current_gains()

void set_current_gains ( void  )

Sets the current gains by reading the UART buffer.

Parameters
Void
Returns
Void

◆ setADCMux()

void setADCMux ( int  motor,
int  number 
)

Sets the ADC MUX to read from either the current sense resistor 1, 2 or 3 from motor 1 or 2.

Parameters
Void
Returns
Void

◆ setCurrent()

void setCurrent ( int  motor,
int  u 
)

Sets the reference current for a given motor.

Parameters
intmotor
intu the reference value
Returns
Void