;******************************************************************************************************* ; ; Project Title STATION STOP MODULE for DCC ; ; Author Jeff MONEGAL ; ; Start Date 15 February 2008 ; ; Program Version 1.0 ; ; Processor PICAXE 08M ; ;------------------------------------------------------------------------------------------------------- ; These are connections to and from the micro ;------------------------------------------------------------------------------------------------------- symbol setup = 1 symbol sens_1 = 4 symbol by_pass = 3 symbol relay = pin2 ;------------------------------------------------------------------------------------------------------- ; These are registers within the micro chip ;_______________________________________________________________________________________________________ symbol temp = w5 symbol ambient = b9 symbol timer = b8 symbol delay = b7 ;_______________________________________________________________________________________________________ ; ; The system could be used on display layouts where the level of ambient light can vary between different ;locations. The first thing this program does is read the current light level then add an offset. By doing ;this we get a self adjusting light sensor that works much better when used in locations that have varing ;levels of ambient light. prog_start: if pin3 = 0 then set_up rem if setup button pressed goto the setup section read 250,timer delay = timer readadc sens_1,b0 rem set the optical sensor trip point according to ambient = b0 + 25 rem the current level of light. begin: if pin4 = 0 then begin rem look at the by-pass switch. readadc sens_1,b0 if b0 > ambient then train_detected goto begin train_detected: pause 100 rem a short delay to make sure detection is not false readadc sens_1,b0 if b0 > ambient then train_is_detected goto begin train_is_detected: high 0 rem select DC to the track to slow and stop the train detected_loop: pause 200 if by_pass = 0 then times_up rem look at the by pass switch to see if moved delay = delay - 1 if delay < 2 then times_up goto detected_loop times_up: delay = timer low 0 rem track back to DCC to start train jeff_lp2: pause 500 rem when train moves off make sure that it has cleared readadc sens_1,b0 rem the sensor before starting over again if b0 > ambient then jeff_lp2 goto begin ;------------------------------------------------------------------------------------------------------ ; Here the operator is setting the total time delay from when the train starts to slow down ; after tripping a sensor right up until the standstill period is finished and DCC is put back ; onto the track and the train moves off. ; ; NOTE= Before entering setup mode make sure the decoder CV's have been set so the train will slow ; down and stop before the end of your block has been reached. ; The prog waits until the operator releases the setup button. It then makes sure DCC is on ; the track. The operator now waits untill the moving train enters the isolated block of track. ; The setup button is now pressed then released again. After release the train begins to slow ; because DC is now connected to the isolated block of track. The train will come to a stop. The ; operator now waits for the required stop time to expire. Another press and release of the button ; will store the time since the sequence started. This time will be used from now on until another ; time is programmed. The program now goes back to the start and runs. ;------------------------------------------------------------------------------------------------------ setup: pause 200 if pin3 = 0 then setup rem wait for button release low 0 rem make sure train is running on DCC timer = 0 setup_lp1: pause 20 if pin3 = 0 then start goto setup_lp1 start: pause 50 rem wait for button to be released if pin3 = 1 then start_cntr: goto start start_cntr: high 0 rem select DC to start the slow down bit pause 200 rem gives max 50 seconds total delay time timer = timer + 1 if pin3 = 1 then start_cntr rem continue counting write 250,timer rem store the set delay time in mem location 250 waiting: pause 500 if pin3 = 0 then waiting low 0 rem track back to DC goto prog_start ;===================================================================================================