ACS Firmware Documentation
Attitude Control System Capstone 2018 for OreSat
Functions
magnetorquer.c File Reference
#include "magnetorquer.h"
Include dependency graph for magnetorquer.c:

Go to the source code of this file.

Functions

void mtqrInit (MTQR *mtqr)
 Magnetorquer initialization function. More...
 
void mtqrStart (MTQR *mtqr)
 Magnetorquer start function. More...
 
void mtqrStop (MTQR *mtqr)
 Magnetorquer stop function. More...
 
void mtqrSetDC (uint16_t dc)
 Magnetorquer set duty cycle function. More...
 
void mtqrSetDir (uint8_t dc)
 Magnetorquer set direction function. More...
 
void mtqrExit (MTQR *mtqr)
 Magnetorquer exit function. More...
 

Function Documentation

◆ mtqrExit()

void mtqrExit ( MTQR mtqr)

Magnetorquer exit function.

Function to initialize shutdown of driver.

91  {
92  if(!mtqr->started){ // Checking if magnetorquer state is off.
93  return;
94  }
95  mtqrStop(mtqr); // If the state isn't already off, shut down the driver.
96 }
int started
Definition: magnetorquer.h:51
void mtqrStop(MTQR *mtqr)
Magnetorquer stop function.
Definition: magnetorquer.c:43

◆ mtqrInit()

void mtqrInit ( MTQR mtqr)

Magnetorquer initialization function.

This function will initialize the driver state to off.

9  {
10  (void)mtqr;
11  mtqr->started = FALSE; // Initializing state of magnetorquer driver.
12  palClearPad(GPIOB,ENABLE); // Initializing motor driver state to off.
13 }
int started
Definition: magnetorquer.h:51
#define ENABLE
Definition: magnetorquer.h:19

◆ mtqrSetDC()

void mtqrSetDC ( uint16_t  dc)

Magnetorquer set duty cycle function.

This function takes a 16 bit value as parameter and sets the duty cycle of the magnetorquer driver using the paramater.

61  {
62  pwmEnableChannel( // Setting duty cycle output using paramater.
63  &PWMD1,
65  PWM_PERCENTAGE_TO_WIDTH(&PWMD1,dc)
66  );
67 }
#define PWM_CH_MTQR
Definition: magnetorquer.h:16

◆ mtqrSetDir()

void mtqrSetDir ( uint8_t  dc)

Magnetorquer set direction function.

This function sets the phase pin for the STSPIN250 motor driver. The phase is set based on the value of the paramater given to the function.

77  {
78  if(dc==FORWARD){ // Set phase selection pin based on requested direction.
79  palClearPad(GPIOA,PH);
80  }else if(dc==REVERSE){
81  palSetPad(GPIOA,PH);
82  }
83 }
#define REVERSE
Definition: magnetorquer.h:12
#define FORWARD
Definition: magnetorquer.h:11
#define PH
Definition: magnetorquer.h:18

◆ mtqrStart()

void mtqrStart ( MTQR mtqr)

Magnetorquer start function.

This function will start the PWM driver and enable the STSPIN250 motor driver while providing a starting duty cycle. At this point, the state of the magnetorquer will be set to true to indicate on state.

25  {
26  if(mtqr->started){ // Checking if state is already on.
27  return;
28  }
29  pwmStart(&PWMD1,&pwm_MTQRcfg); // Starting pwm driver.
30  mtqrSetDC(MTQR_STARTING_DC); // Setting duty cycle of output.
31  palSetPad(GPIOB,ENABLE); // Turning on motor driver.
32  mtqr->started = TRUE; // Setting to on state.
33 }
void mtqrSetDC(uint16_t dc)
Magnetorquer set duty cycle function.
Definition: magnetorquer.c:61
int started
Definition: magnetorquer.h:51
#define ENABLE
Definition: magnetorquer.h:19
#define MTQR_STARTING_DC
Definition: magnetorquer.h:17
static const PWMConfig pwm_MTQRcfg
PWMConfig structure for the magnetorquer.
Definition: magnetorquer.h:28

◆ mtqrStop()

void mtqrStop ( MTQR mtqr)

Magnetorquer stop function.

This function will disable the active PWM driver and disable the STSPIN250 motor driver.

43  {
44  if(!mtqr->started){ // Checking if state is already off.
45  return;
46  }
47  pwmDisableChannel(&PWMD1,PWM_CH_MTQR); // Disabling channel output.
48  palClearPad(GPIOB,ENABLE); // Shutting off STSPIN250 driver.
49  pwmStop(&PWMD1); // Stopping PWM driver.
50  mtqr->started = FALSE; // Changing state to off.
51 }
int started
Definition: magnetorquer.h:51
#define PWM_CH_MTQR
Definition: magnetorquer.h:16
#define ENABLE
Definition: magnetorquer.h:19