7 |
kaklik |
1 |
// *************************************
|
|
|
2 |
// * Scamnum Specularis ** 20. 9. 2006 *
|
|
|
3 |
// *************************************
|
|
|
4 |
|
|
|
5 |
#include ".\menic.h"
|
|
|
6 |
|
|
|
7 |
#define TXo PIN_B5 // To the transmitter modulator
|
|
|
8 |
#include ".\AX25.c" // Podprogram pro prenos telemetrie
|
|
|
9 |
char AXstring[40]; // Buffer pro prenos telemetrie
|
|
|
10 |
|
|
|
11 |
#define REFSTART 95 // Hodnota odpovidajici 1,2V pri nezatizenych clancich
|
|
|
12 |
#define DUTY1 2 // Delka sepnuti PWM v us pro sero
|
|
|
13 |
#define DUTY2 19 // Delka sepnuti PWM v us pro jednu zarovku 500W
|
|
|
14 |
|
|
|
15 |
// Tabulka hodnot prevodniku pro ruzna napajeci napeti
|
|
|
16 |
// 80 3,99V
|
|
|
17 |
// 90 3,54V
|
|
|
18 |
// 100 3,20V
|
|
|
19 |
// 105 3,04V
|
|
|
20 |
// 107 2,99V
|
|
|
21 |
// 110 2,91v
|
|
|
22 |
// 200 1,61V
|
|
|
23 |
|
|
|
24 |
#define PIEZO PIN_A6 // Jeden pol piezo reproduktoru
|
|
|
25 |
#define LED PIN_A7 // LED / druhy pol piezo reproduktoru
|
|
|
26 |
#define MENIC PIN_B3 // Spinani tranzistoru menice
|
|
|
27 |
#define REFPWR PIN_B1 // Napajeni zdroje referencniho napeti
|
|
|
28 |
#define MOTOR PIN_B2 // Spinani tranzistoru motoru
|
|
|
29 |
#define SW1 PIN_B6 // DIPswitch 1
|
|
|
30 |
#define SW2 PIN_B7 // DIPswitch 2
|
|
|
31 |
#define NAPETI 4 // Cislo kanalu DA prevodniku pro mereni napeti
|
|
|
32 |
#define PWM 0 // Cislo kanalu DA prevodniku pro nastaveni PWM
|
|
|
33 |
#define ROZJEZD 1 // Cislo kanalu DA prevodniku pro nastaveni rozjezdu
|
|
|
34 |
|
|
|
35 |
#byte SSPBUF = 0x13 // Adresy registru jednotky SSP
|
|
|
36 |
#byte SSPCON1 = 0x14
|
|
|
37 |
#byte SSPSTAT = 0x94
|
|
|
38 |
|
|
|
39 |
// Vzorky pro generovani PWM pomoci SSP
|
|
|
40 |
unsigned int8 const Pattern[8] = {0x02,0x06,0x0e,0x1e,0x3e,0x7e,0xfe,0xff};
|
|
|
41 |
unsigned int8 MotorPattern;
|
|
|
42 |
|
|
|
43 |
#INT_SSP
|
|
|
44 |
void IntSSP()
|
|
|
45 |
{
|
|
|
46 |
SSPBUF=MotorPattern; // znovu vysli stejnou hodnotu
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
void pip() // pipnuti a bliknuti
|
|
|
50 |
{
|
|
|
51 |
int1 beep;
|
|
|
52 |
int i;
|
|
|
53 |
|
|
|
54 |
for(i=0; i<250; i++)
|
|
|
55 |
{
|
|
|
56 |
output_bit(PIEZO, beep);
|
|
|
57 |
beep=~beep;
|
|
|
58 |
output_bit(LED, beep);
|
|
|
59 |
delay_us(100);
|
|
|
60 |
};
|
|
|
61 |
output_high(PIEZO);
|
|
|
62 |
output_high(LED);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
void cvak() // pouze cvaknuti piezoelementem bez bliknuti
|
|
|
66 |
{
|
|
|
67 |
output_bit(PIEZO,~input(PIEZO));
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
void main()
|
|
|
71 |
{
|
|
|
72 |
int8 n;
|
|
|
73 |
int8 perioda;
|
|
|
74 |
int8 razeni;
|
|
|
75 |
int8 uclanku;
|
12 |
kaklik |
76 |
int16 ble;
|
7 |
kaklik |
77 |
|
|
|
78 |
setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_1152MS);
|
|
|
79 |
setup_timer_1(T1_DISABLED);
|
|
|
80 |
setup_adc_ports(ADC_CLOCK_INTERNAL|sAN0|sAN1|sAN4|VSS_VDD);
|
|
|
81 |
setup_adc(ADC_CLOCK_INTERNAL);
|
|
|
82 |
setup_spi(FALSE);
|
|
|
83 |
setup_comparator(NC_NC_NC_NC);
|
|
|
84 |
setup_vref(FALSE);
|
|
|
85 |
|
|
|
86 |
output_low(MENIC); // Vsechno zastav
|
|
|
87 |
output_low(MOTOR);
|
|
|
88 |
output_low(REFPWR);
|
|
|
89 |
output_high(LED);
|
|
|
90 |
output_high(PIEZO);
|
|
|
91 |
|
|
|
92 |
set_adc_channel(NAPETI); // Vyber AD kanal pro pomerne mereni napeti
|
|
|
93 |
set_pwm1_duty(0); // Spust PWM, ale zatim s trvalou 0 na vystupu
|
|
|
94 |
setup_ccp1(CCP_PWM);
|
|
|
95 |
setup_timer_2(T2_DIV_BY_1,100,1); // perioda
|
|
|
96 |
|
|
|
97 |
setup_oscillator(OSC_4MHZ|OSC_INTRC); // rozjed PIC (zvysi se odber)
|
|
|
98 |
|
|
|
99 |
// jsme v depu?
|
|
|
100 |
set_pwm1_duty(DUTY1); // PWM pro zatizeni clanku pri malem osvetleni
|
|
|
101 |
n=0;
|
|
|
102 |
do
|
|
|
103 |
{
|
|
|
104 |
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
|
|
|
105 |
delay_ms(100);
|
|
|
106 |
if (4==n++) {cvak(); n=0;}; // Kazdy 4. pruchod cvakni
|
|
|
107 |
output_high(REFPWR); // Zapni napajeni napetove reference
|
|
|
108 |
delay_ms(1); // Pockej na ustaleni napeti
|
|
|
109 |
} while (read_adc()>REFSTART); // Odkryl starter clanky?
|
|
|
110 |
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
|
|
|
111 |
|
|
|
112 |
// port_b_pullups(TRUE); // Zapni pullupy, aby slo cist DIPswitch
|
|
|
113 |
// do
|
|
|
114 |
// {
|
|
|
115 |
// Precti trimry
|
|
|
116 |
set_adc_channel(PWM); // Zjisteni nastaveni PWM
|
|
|
117 |
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
|
12 |
kaklik |
118 |
perioda=(read_adc()>>2)+40; // rozsah: 40 az 103
|
7 |
kaklik |
119 |
|
|
|
120 |
set_adc_channel(ROZJEZD); // Zjisteni nastaveni rozjezdu
|
|
|
121 |
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
|
12 |
kaklik |
122 |
razeni=read_adc()>>3; // rozsah: 0 az 31
|
7 |
kaklik |
123 |
|
|
|
124 |
// Rozjeti menice
|
|
|
125 |
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
|
|
|
126 |
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
|
|
|
127 |
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
|
|
|
128 |
|
|
|
129 |
pip(); // potvrzeni odstartovani / servisni mod
|
|
|
130 |
delay_ms(500);
|
|
|
131 |
|
|
|
132 |
// } while (input(SW1)); // Je zapnut servisni mod? SW1(OFF)=ANO
|
|
|
133 |
// port_b_pullups(FALSE); // Vypni pullupy, aby se setrilo energii
|
|
|
134 |
|
12 |
kaklik |
135 |
// zmereni napeti na clancich
|
7 |
kaklik |
136 |
output_high(REFPWR); // Prepni AD na mereni napeti clanku
|
|
|
137 |
set_adc_channel(NAPETI); // Prepni Zmer napeti clanku
|
|
|
138 |
delay_us(50); // Pockej na prepnuti kanalu A/D prevodniku
|
12 |
kaklik |
139 |
uclanku=read_adc();
|
|
|
140 |
output_low(REFPWR); // odpoj odpor pro mereni napeti
|
|
|
141 |
|
7 |
kaklik |
142 |
// posli telemetrii
|
|
|
143 |
sprintf(AXstring,"p=%u r=%u u=%u", perioda, razeni, uclanku); // Convert DATA to String.
|
|
|
144 |
SendPacket(&AXstring[0]);
|
|
|
145 |
|
12 |
kaklik |
146 |
delay_ms(14000); // Pockame do 14.5s
|
7 |
kaklik |
147 |
|
12 |
kaklik |
148 |
// rozjezd
|
|
|
149 |
for(ble=1;ble<=1000;ble++)
|
|
|
150 |
{
|
|
|
151 |
for(n=0;n<=razeni;n++)
|
|
|
152 |
{
|
|
|
153 |
output_high(MOTOR);
|
|
|
154 |
delay_us(ble);
|
|
|
155 |
output_low(MOTOR);
|
|
|
156 |
delay_us(1000-ble);
|
|
|
157 |
}
|
|
|
158 |
}
|
7 |
kaklik |
159 |
|
|
|
160 |
// jedem co to da
|
|
|
161 |
output_high(MOTOR);
|
|
|
162 |
|
|
|
163 |
delay_ms(1300); // Nemeli bysme jet dele nez 1,3s :-)
|
|
|
164 |
output_low(MOTOR); // Zastav motor
|
|
|
165 |
// Menic je stale zapnut a zatezuje clanky
|
|
|
166 |
|
|
|
167 |
while(TRUE); // Cekej, dokud se neztrati svetlo,
|
|
|
168 |
// nebo prijde WatchDog
|
|
|
169 |
|
|
|
170 |
}
|