-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
119 lines (85 loc) · 2.32 KB
/
debug.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <ADuC841.h>
#include "timer3.h"
#include "timer2.h"
#include "proto_uso/proto_uso.h"
#include "preferences.h"
#include "eeprom/eeprom.h"
#include "rtos/timer1.h"
#include "adc.h"
#include "watchdog.h"
#include "proto_uso/channels.h"
//#include "calibrate/calibrate.h"
#include "pt/pt.h"
#include "dol.h"
extern struct pt pt_proto;
extern volatile unsigned long PHASE_1_RESULT,PHASE_2_RESULT;
extern volatile unsigned long PHASE_1_RESULT_LAST,PHASE_2_RESULT_LAST; //ïðåäûäóùèé ðåçóëüòàò
extern volatile unsigned int ADC_MID_1,ADC_MID_2;
extern volatile unsigned long turn_counter;
volatile struct pt pt_out;
volatile long angle=0, last_angle=0;
PT_THREAD(OutProcess(struct pt *pt));
//-----------------------------------------
//PT_THREAD(I2C_RepeatRead(struct pt *pt));
//---------------------------------------
void main(void) //using 0
{
unsigned char i=0;
EA = 0;
ChannelsInit();//èíèöèàëèçàöèÿ íàñòðîåê êàíàëîâ
Protocol_Init();
Timer0_Initialize();
Timer1_Initialize(); //òàéìåð øåäóëåðà 200Ãö
ADC_Initialize();
EA=1;
for(i=0;i<MID_NUM<<1;i++)
{
unsigned int delay=300;
SCONV=1;
while(delay)
{
delay--;
}
}
ADC_MID_1=PHASE_1_RESULT;
ADC_MID_2=PHASE_2_RESULT;
UART_Init();
Dol_Init();
Timer2_Initialize();
WDT_Init(WDT_2000);//âêëþ÷èòü ñòîðîæåâîé òàéìåð
// RestoreCalibrate();
// PT_INIT(&pt_i2c_read);
// PT_INIT(&pt_freq_measure);
// PT_INIT(&pt_sort);
PT_INIT(&pt_out);
while(1)
{
ProtoProcess(&pt_proto);
OutProcess(&pt_out);
}
}
//-----------------------------------------------------------------------------
#pragma OT(0,Speed)
//-----------------------------------
void Timer1_Interrupt(void) interrupt 3 //òàéìåð øåäóëåðà
{
//---------------------------------------
TH1 = TH1_VAL; ///200 Hz;
TL1 = TL1_VAL;//
pt_proto.pt_time++;
pt_out.pt_time++;
return;
}
//-----------------------------------------
PT_THREAD(OutProcess(struct pt *pt))
{
PT_BEGIN(pt);
while(1)
{
PT_DELAY(pt, 1);
// angle=arctan((long)PHASE_1_RESULT-ADC_MID_1,(long)PHASE_2_RESULT-ADC_MID_2);//Get_Angle(PHASE_1_RESULT,PHASE_2_RESULT);//+turn_counter;
channels[0].channel_data=arctan((long)PHASE_1_RESULT-ADC_MID_1,(long)PHASE_2_RESULT-ADC_MID_2)+turn_counter+0x80008000;//(angle-last_angle);//Get_Angle(PHASE_1_RESULT,PHASE_2_RESULT);
WDT_Clear();
}
PT_END(pt);
}