Hi
here coms some pic. and movies.
Aftre wishes from Charlie(2005-06-25, 16:06 pm).
Sorry server die online on friday, sorry
The train sensor for reset the time counter too open the bridge.
The 5mm is a IR LED on 18mW and the 3mm is a IR transistor.
(Big file)
The electricmotor from a taperecoder runs on 5V.
(Big file)
The controller card.
(Big file)
The bridge in movement!
Power on & the controller displays with 5 blink that the is ready that drive main program.
The bridge anglesensor
and the final version of the code:
Code: Select all
program Thomas_Bro2;
//******************************************************************************
// microcontroller : P12f675
//
// Svenska.
// Projekt: Thomas styrsystem för klaffbro
// Detta projekt är disangat att fungera med PIC 12F675
// med några mindre ändringar bör det fungera med andra PIC MCU.
//
// Denna kod driver en motor på GP3 och GP2.
// ADC konverterningens värde anger vinkeln bron har och vänte tiden
// mellan varje bro rörelse.
//
// English.
// Project: Thomas controls system for drawbridge
// This project is designed to work with PIC 12F675
// with minor adjustments, it should work with any other PIC MCU.
//
// This code drives a motor at GP3 and GP2.
// ADC conversion value determinate the angel for bridge and the wainting time
// betwen the bridge events.
//******************************************************************************
//program adc_leds;
var Zov,BroVinkel,Tid : word;
Loopz,PowerON:Byte;
Begin
//Setup
GPIO := 0;
CMCON := 7;
TRISIO := 0; // designate gpio as output
SetBit(TRISIO,ANS0); // pin ANS0 as input
SetBit(TRISIO,ANS1); // pin ANS1 as input
ClearBit(ADCON0,VCFG); // Vdd as Vref
// Power ON visning 5 blink
// Power ON show 5 blink
GPIO := $04; // Tänder LED 1101 1111=DF Orginal
delay_ms(1000);
For PowerON:=1 to 5 do
Begin
GPIO := $04; // Tänder LED 1101 1111=DF Orginal
// 0010 0000=20
delay_ms(400);
GPIO := $00; // Släcker alla LED 1111 1111=FF Orginal
// 0000 0000=00
delay_ms(400);
End;
// Kontrollerar att bron är nere
// Controlls if bridge is down
GPIO := $00;
delay_ms(2000);
PowerON:=0;
repeat
Begin
BroVinkel:=ADC_read(ANS1); // ADC conversion
If PowerON=1 then
Begin //Block av - Relä (av)läge ner - Motor på * Block off - Relay (Off) pos. down - Motor on
GPIO := $10; //Bron var inte nere säncker bron! ******** bridge is not down!
delay_ms(50);//Pulserar motorstömen för långsam gång *** Pulse motorpower for slow run
GPIO := $00; //Block av - Relä (av)läge ner - Motor av * Block off - Relay (Off) pos. down - Motor off
delay_ms(50);
End;
PowerON:=1;
End;
until BroVinkel<=63; // <--- Ner värdet 1 ------------------------------------
GPIO := $00;
delay_ms(2000);
// Huvud progrsm
// Main program
repeat // beginning of a repeat endless loop
Begin
// Väntar inställd tid
// Want for set time
//GPIO := $00;
Tid:=ADC_read(ANS0); // ADC conversion
Zov:=0;
If Tid<100 then
Begin
Tid:=100; // 6=Test 100=Normal
//GPIO:=$34; // Tag Bort * Remove
//delay_ms(2000); // Tag Bort * Remove
End;
If Tid>1010 then
Begin
Tid:=2; // 6=Test 100=Normal
End;
//GPIO := $00; // Tag Bort * Remove
//delay_ms(500); // Tag Bort * Remove
Repeat
Begin
Zov:=Zov+1; // Antal varv att vänta * Number of lap too want
for Loopz:=1 to 30 do
Begin
//GPIO:=$20; // Tag Bort
delay_ms(106); // Tid att vänta * Loopz värdet
IF TestBit(GPIO,3)=0 Then
Begin
Zov:=0; // Nollar tidsräknaren * Reset timecount
//GPIO:=$04; // Tag Bort * Remove
Tid:=ADC_read(ANS0); // ADC conversion
If Tid<100 then
Begin
Tid:=100; // 6=Test 100=Normal
End;
If Tid>1010 then
Begin
Tid:=2; // 6=Test 100=Normal
End;
delay_ms(5000); // Väntar ca: 5 Sekunder * Wants 5 Sec.
End;
End;
//GPIO:=$00; // Tag Bort
//delay_ms(200);
End;
until Tid=Zov; // Klart att höja bron
// Clear too take up the bridge
// Höjer bron * Up bridge
GPIO:=$04; // Block på - Relä (av)läge ner - Motor av
Delay_ms(500); // Block on - Relay (Off) pos. down - Motor off
repeat
Begin
BroVinkel:=ADC_read(ANS1); // ADC conversion
GPIO:=$24; // Block på - Relä (på)läge upp - Motor av
Delay_ms(30); // Block on - Relay (on) pos. up - Motor off
GPIO:=$34;
Delay_ms(50); // Block på - Relä (på)läge upp - Motor på
End; // Block on - Relay (on) pos. up - Motor on
until BroVinkel>=365; // <---- Upp värdet ---------------------------------------------
GPIO:=$24; // Block på - Relä (på)läge upp - Motor av
Delay_ms(500); // Block on - Relay (on) pos. up - Motor off
GPIO:=$04; // Block på - Relä (av)läge ner - Motor av
Delay_ms(500); // Block on - Relay (Off) pos. down - Motor off
//Väntar i 20Sekunder * Wants 20 Sec
For Loopz:=1 to 4 do
Begin
Delay_ms(5000);
End;
// 5000mS = 5 Sekunder.
// 5 * 4 = 20 Sekunder.
//Sänker bron
GPIO:=$04; //Block på - Relä (av)läge ner - Motor av * Block on - Relay (Off) pos. down - Motor off
repeat
Begin
BroVinkel:=ADC_read(ANS1); // ADC conversion
GPIO:=$04; // Block på - Relä (av)läge ner - Motor av
Delay_ms(50);// Block on - Relay (Off) pos. down - Motor off
GPIO:=$14; // Block på - Relä (av)läge ner - Motor på
Delay_ms(50); // Block on - Relay (Off) pos. down - Motor on
End;
until BroVinkel<63; // <---- Ner värdet -----------------------------------------
GPIO:=$04; // Block på - Relä (av)läge ner - Motor av
delay_ms(3000);// Block on - Relay (Off) pos. down - Motor off
GPIO:=$00; // Block av - Relä (av)läge ner - Motor av
delay_ms(3000); // Block off - Relay (Off) pos. down - Motor off
End;
until 0 = 1; // endless loop (as this condition is never satisfied)
end.
Files can erase after 20051004, download if you want too save the file!
_____________________________
Edit: fixed the pict. so the are more ok size
ICQ Mess. = Forums name as ref.
If you see stave/grammatical errors is you welcome too tell me.