178 |
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 |
void pip() // pipnuti a bliknuti
|
|
|
36 |
{
|
|
|
37 |
int1 beep;
|
|
|
38 |
int i;
|
|
|
39 |
|
|
|
40 |
for(i=0; i<250; i++)
|
|
|
41 |
{
|
|
|
42 |
output_bit(PIEZO, beep);
|
|
|
43 |
beep=~beep;
|
|
|
44 |
output_bit(LED, beep);
|
|
|
45 |
delay_us(100);
|
|
|
46 |
};
|
|
|
47 |
output_high(PIEZO);
|
|
|
48 |
output_high(LED);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
void cvak() // pouze cvaknuti piezoelementem bez bliknuti
|
|
|
52 |
{
|
|
|
53 |
output_bit(PIEZO,~input(PIEZO));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
void main()
|
|
|
57 |
{
|
|
|
58 |
int8 n;
|
|
|
59 |
int8 perioda;
|
|
|
60 |
int8 razeni;
|
|
|
61 |
int8 uclanku;
|
|
|
62 |
int8 ble;
|
|
|
63 |
|
|
|
64 |
setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_1152MS);
|
|
|
65 |
setup_timer_1(T1_DISABLED);
|
|
|
66 |
setup_adc_ports(ADC_CLOCK_INTERNAL|sAN0|sAN1|sAN4|VSS_VDD);
|
|
|
67 |
setup_adc(ADC_CLOCK_INTERNAL);
|
|
|
68 |
setup_spi(FALSE);
|
|
|
69 |
setup_comparator(NC_NC_NC_NC);
|
|
|
70 |
setup_vref(FALSE);
|
|
|
71 |
|
|
|
72 |
output_low(MENIC); // Vsechno zastav
|
|
|
73 |
output_low(MOTOR);
|
|
|
74 |
output_low(REFPWR);
|
|
|
75 |
output_high(LED);
|
|
|
76 |
output_high(PIEZO);
|
|
|
77 |
|
|
|
78 |
set_adc_channel(NAPETI); // Vyber AD kanal pro pomerne mereni napeti
|
|
|
79 |
set_pwm1_duty(0); // Spust PWM, ale zatim s trvalou 0 na vystupu
|
|
|
80 |
setup_ccp1(CCP_PWM);
|
|
|
81 |
setup_timer_2(T2_DIV_BY_1,100,1); // perioda
|
|
|
82 |
|
|
|
83 |
setup_oscillator(OSC_4MHZ|OSC_INTRC); // rozjed PIC (zvysi se odber)
|
|
|
84 |
|
|
|
85 |
// jsme v depu?
|
|
|
86 |
set_pwm1_duty(DUTY1); // PWM pro zatizeni clanku pri malem osvetleni
|
|
|
87 |
n=0;
|
|
|
88 |
do
|
|
|
89 |
{
|
|
|
90 |
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
|
|
|
91 |
delay_ms(100);
|
|
|
92 |
if (4==n++) {cvak(); n=0;}; // Kazdy 4. pruchod cvakni
|
|
|
93 |
output_high(REFPWR); // Zapni napajeni napetove reference
|
|
|
94 |
delay_ms(1); // Pockej na ustaleni napeti
|
|
|
95 |
} while (read_adc()>REFSTART); // Odkryl starter clanky?
|
|
|
96 |
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
|
|
|
97 |
|
|
|
98 |
// port_b_pullups(TRUE); // Zapni pullupy, aby slo cist DIPswitch
|
|
|
99 |
// do
|
|
|
100 |
// {
|
|
|
101 |
// Precti trimry
|
|
|
102 |
set_adc_channel(PWM); // Zjisteni nastaveni PWM
|
|
|
103 |
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
|
|
|
104 |
perioda=(read_adc()>>2)+40; // rozsah: 40 az 103
|
|
|
105 |
|
|
|
106 |
set_adc_channel(ROZJEZD); // Zjisteni nastaveni rozjezdu
|
|
|
107 |
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
|
|
|
108 |
razeni=read_adc()>>4; // rozsah: 0 az 15
|
|
|
109 |
|
|
|
110 |
// Rozjeti menice
|
|
|
111 |
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
|
|
|
112 |
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
|
|
|
113 |
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
|
|
|
114 |
|
|
|
115 |
pip(); // potvrzeni odstartovani / servisni mod
|
|
|
116 |
delay_ms(500);
|
|
|
117 |
|
|
|
118 |
// } while (input(SW1)); // Je zapnut servisni mod? SW1(OFF)=ANO
|
|
|
119 |
// port_b_pullups(FALSE); // Vypni pullupy, aby se setrilo energii
|
|
|
120 |
|
|
|
121 |
// zmereni napeti na clancich
|
|
|
122 |
output_high(REFPWR); // Prepni AD na mereni napeti clanku
|
|
|
123 |
set_adc_channel(NAPETI); // Prepni Zmer napeti clanku
|
|
|
124 |
delay_us(50); // Pockej na prepnuti kanalu A/D prevodniku
|
|
|
125 |
uclanku=read_adc();
|
|
|
126 |
output_low(REFPWR); // odpoj odpor pro mereni napeti
|
|
|
127 |
|
|
|
128 |
// posli telemetrii
|
|
|
129 |
sprintf(AXstring,"p=%u r=%u u=%u", perioda, razeni, uclanku); // Convert DATA to String.
|
|
|
130 |
SendPacket(&AXstring[0]);
|
|
|
131 |
|
|
|
132 |
delay_ms(14000); // Pockame do 14.5s
|
|
|
133 |
|
|
|
134 |
// rozjezd
|
|
|
135 |
for( ble=1;ble<255;ble++)
|
|
|
136 |
{
|
|
|
137 |
for(n=0;n<=razeni;n++)
|
|
|
138 |
{
|
|
|
139 |
output_high(MOTOR);
|
|
|
140 |
delay_us(ble);
|
|
|
141 |
delay_us(ble);
|
|
|
142 |
output_low(MOTOR);
|
|
|
143 |
delay_us(255-ble);
|
|
|
144 |
delay_us(255-ble);
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
// jedem co to da
|
|
|
149 |
output_high(MOTOR);
|
|
|
150 |
|
|
|
151 |
delay_ms(1300); // Nemeli bysme jet dele nez 1,3s :-)
|
|
|
152 |
output_low(MOTOR); // Zastav motor
|
|
|
153 |
// Menic je stale zapnut a zatezuje clanky
|
|
|
154 |
|
|
|
155 |
reset_cpu();
|
|
|
156 |
}
|