Flipklok
 
Loading...
Searching...
No Matches
stepperAdvance.h File Reference
#include <msp430.h>
#include "pins.h"
#include <stdbool.h>

Go to the source code of this file.

Macros

#define stepperTimeOffsetSlow   0x800;
 
#define stepperTimeOffsetFast   0x100;
 

Functions

void setupTimer0 ()
 
void stepperAdvance ()
 

Variables

bool timerCompareStepperSpeedToggle
 

Macro Definition Documentation

◆ stepperTimeOffsetFast

#define stepperTimeOffsetFast   0x100;

Definition at line 15 of file stepperAdvance.h.

Referenced by ISR_TA0().

◆ stepperTimeOffsetSlow

#define stepperTimeOffsetSlow   0x800;

Definition at line 14 of file stepperAdvance.h.

Referenced by ISR_TA0(), and setupTimer0().

Function Documentation

◆ setupTimer0()

void setupTimer0 ( )

Setup of timer0, uses the the ACLK (Auxiliary clock), counts up continuous. Capture control registers

  • CCR0
  • CCR1 triggers pwm LED
  • CCR2 triggers stepperAdvance()
  • TAIFG start reading ADC

Definition at line 26 of file timer.c.

27{
28 //Timer setup
29 TA0CTL = TASSEL_1 | MC_2| TACLR | TAIE | ID_0; // Set to counter to ACLK, Continuous clock, clear counter of clock, Enable TAIFG interrupt, Divider set to 1
30 TA0CCTL1 = CCIE; // TACCR1 interrupt enabled
31 TA0CCTL2 &= ~CCIE; // TACCR2 interrupt disable
32 TA0CCR2 = stepperTimeOffsetSlow; // compare at stepperOffset
33 TA0CCR1 = pwmPeriod_cycles;
34}
#define stepperTimeOffsetSlow
#define pwmPeriod_cycles
Definition timer.h:17

References pwmPeriod_cycles, and stepperTimeOffsetSlow.

Referenced by main().

◆ 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

◆ timerCompareStepperSpeedToggle

bool timerCompareStepperSpeedToggle

Definition at line 17 of file stepperAdvance.h.

Referenced by calculateTimeDifference(), ISR_TA0(), and port2ISR().