-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardware_interrupts.c
100 lines (87 loc) · 3.44 KB
/
hardware_interrupts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
* File: hardware_interrupts.c
* Author: Vladimir Pasashnikov, [email protected]
*
* Created on 31 August 2017
******************************************************************************/
#include "hardware.h"
#include "main.h"
#include "sine_table.h"
#include "status_led_state_machine.h"
#include <p33FJ12MC202.h>
#include <libpic30.h>
/*******************************************************************************
* Function: _INT0Interrupt ()
* Output: None
* Description: Processing step pulse on PIN RB6
* Note: None
******************************************************************************/
void __attribute__((__interrupt__, auto_psv)) _INT0Interrupt () {
// Update stepCount
if (DIR_PIN) {
stepper_state.step_count = TABLE_SIZE_MUL4 + stepper_state.step_count - stepper_state.step_increment;
}
else
{
stepper_state.step_count = TABLE_SIZE_MUL4 + stepper_state.step_count + stepper_state.step_increment;
}
stepper_state.step_count %= TABLE_SIZE_MUL4;
UpdateStepperState ();
IFS0bits.INT0IF = 0;
}
/*******************************************************************************
* Function: _ADC1Interrupt ()
* Output: None
* Description: ADC completion interrupt.
* Note: Calls actual subroutine depending on state machine
******************************************************************************/
void __attribute__((__interrupt__, auto_psv)) _ADC1Interrupt () {
// Clear ADC interrupt flag
IFS0bits.AD1IF = 0;
/*
* Interrupt depends on controller FSM state, thus switch here
*/
switch (controller_state) {
case CTRL_STATE_HOLD:
case CTRL_STATE_STEPPING:
ClosedLoopADCInterruptRoutine ();
break;
default:
break;
}
}
/*******************************************************************************
* Function: _T1Interrupt ()
* Output: None
* Description: Household timer
* Note: Detects halt state, provides base for step speed
* calculation, LED FSM state changes, etc
******************************************************************************/
void __attribute__((__interrupt__, auto_psv)) _T1Interrupt () {
StatusLedTimerEvent();
controller_state = CTRL_STATE_FAULT_W1;
DisableOutput ();
IFS0bits.T1IF = 0;
}
/*******************************************************************************
* Function: _FLTA1Interrupt ()
* Output: None
* Description: Overcurrent event for winding 1 processing
* Note: None
******************************************************************************/
void __attribute__((__interrupt__, auto_psv)) _FLTA1Interrupt() {
led_state = LED_STATE_FAULT_W1_01;
controller_state = CTRL_STATE_FAULT_W2;
DisableOutput ();
IFS3bits.FLTA1IF = 0;
}
/*******************************************************************************
* Function: _FLTA2Interrupt ()
* Output: None
* Description: Overcurrent event for winding 2 processing
* Note: None
******************************************************************************/
void __attribute__((__interrupt__, auto_psv)) _FLTA2Interrupt() {
led_state = LED_STATE_FAULT_W2_01;
IFS4bits.FLTA2IF = 0;
}