Flipklok
 
Loading...
Searching...
No Matches
stepperAdvance.c File Reference

Setup and control of stepper motor. More...

#include "stepperAdvance.h"
#include "timeKeeping.h"
#include "uart.h"
#include "storeLoadMechanicalTime.h"
#include "pinInterrupts.h"

Go to the source code of this file.

Functions

void stepperAdvance ()
 

Variables

int stepperArray [] = {BIT0, BIT3, BIT4, BIT5}
 Advances the stepper each time it gets called by one full step gets triggered by ISR_TA0().
 

Detailed Description

Setup and control of stepper motor.

Definition in file stepperAdvance.c.

Function Documentation

◆ stepperAdvance()

void stepperAdvance ( )

Definition at line 23 of file stepperAdvance.c.

24{
25 if (P1IN & BIT0) // if 5V converter is on turn stepper
26 {
27 toggleCalculateTimeDifference = 0; // disable triggering time difference function in timer interrupt.
28 static unsigned int coil;
29 if (stepsRemaining > 0 || toggleFwdInterrupt == 1)
30 {
31 P2OUT &= ~(STEPPER1 + STEPPER2 + STEPPER3 + STEPPER4);
32 P2OUT |= stepperArray[coil];
33 if (coil == 3)
34 {
35 P2OUT |= stepperArray[0];
36 }
37 else
38 {
39 P2OUT |= stepperArray[coil + 1];
40 }
41
42 coil++;
43 if (coil == 4)
44 {
45 P2OUT |= stepperArray[0];
46 coil = 0;
47 }
48
49
50 if (toggleFwdInterrupt == 0)
51 {
53 mechanicalTimeFloat = mechanicalTimeFloat + timePerStep; //Increment mechanical time keeping counter with 1 step time
54
55 if(mechanicalTimeFloat > 86400)
56 {
57 mechanicalTimeFloat = 0; //reset after 24:00
58 #ifdef UART_ENABLED
59 UART_SendString("mechTime reset\r\n");
60 #endif
61 }
62
63 if((stepsRemaining > 999) && (0 == (stepsRemaining % 1000))) //every 1000 steps print steps remaining
64 {
65 #ifdef UART_ENABLED
66 UART_SendString("s: ");
68 UART_SendString(", MTC: ");
70 UART_SendString("\r\n");
71 #endif
72 }
73 }
74 }
75 else
76 {
77 TA0CCTL2 &= ~CCIE; // TACCR2 interrupt stepperAdvance disable
78// storeTime((uint32_t)mechanicalTimeFloat); // Store the current state of the clock in non volatile flash
80 toggleCalculateTimeDifference = 1; // enable triggering time difference function in timer interrupt.
81 toggleFwdInterruptISR = 1; // Enable fwdButton interrupt again (disabled in timekeeping function when it is syncing)
82 }
83 }
84}
bool toggleFwdInterruptISR
bool toggleFwdInterrupt
#define STEPPER2
Definition pins.h:14
#define STEPPER3
Definition pins.h:15
#define STEPPER4
Definition pins.h:16
#define STEPPER1
Definition pins.h:13
int stepperArray[]
Advances the stepper each time it gets called by one full step gets triggered by ISR_TA0().
void write_SegD(uint32_t value)
Function to write a 32-bit value to Flash segment D for storing the mechanical time,...
uint32_t stepsRemaining
Definition timeKeeping.h:43
double mechanicalTimeFloat
Definition timeKeeping.h:40
bool toggleCalculateTimeDifference
Definition timeKeeping.c:16
#define timePerStep
Definition timeKeeping.h:32
void UART_SendTime(uint32_t seconds)
Sends a time formated in hours and minutes to host system.
Definition uart.c:131
void UART_SendUint32(uint32_t num)
send a 32 bit integer to host system
Definition uart.c:103
void UART_SendString(char *str)
send a full string to host system
Definition uart.c:49

References mechanicalTimeFloat, STEPPER1, STEPPER2, STEPPER3, STEPPER4, stepperArray, stepsRemaining, timePerStep, toggleCalculateTimeDifference, toggleFwdInterrupt, toggleFwdInterruptISR, UART_SendString(), UART_SendTime(), UART_SendUint32(), and write_SegD().

Referenced by ISR_TA0().

Variable Documentation

◆ stepperArray

int stepperArray[] = {BIT0, BIT3, BIT4, BIT5}

Advances the stepper each time it gets called by one full step gets triggered by ISR_TA0().

Step sequence:

  • 0001
  • 0010
  • 0100
  • 1000
    Returns
    void

Definition at line 22 of file stepperAdvance.c.

22{BIT0, BIT3, BIT4, BIT5};

Referenced by stepperAdvance().