Hello all!
I want to publish a long code - Grain dryers chains damage detector. This project will first be installed on a single grain dryer as an experiment. In the test mode on the stand, it works perfectly. But if it works, there will be a demand for other dryers. Some time ago I already published a code for a project that used an encoder and compared the numbers of the impulses. Installation of encoders is complicated and costly. This project is based on the time difference between 4 inductive sensors. I have written the package leaflet also in English, translated from the Latvian language. The instruction is included in Word format. I do not know English perfectly, so if you see an error in my instructions, please correct it. Maybe someone sees the inaccuracies in the program code and can something be corrected or simplified? I also added a scheme.
#chip 16F886, 4
#config osc=int
#define LCD_IO 8
#define LCD_RS Portc.5
#define LCD_Enable Portc.7
#define LCD_RW Portc.6
#define LCD_DATA_PORT PortB
dir Portc.5 out
dir Portc.6 out
dir Portc.7 out
dir PortB out
cls
''#include <maths.h>
''+++++ DIGITAL INPUTS & OUTPUTS
#define button_menu portc.0 '' button - SETTINGS DISPLAYS SCHROLL
dir portc.0 in
#define button_up_down_reset portc.1 '' button + , - , reset
dir portc.1 in
#define FAULT portc.2 '' fault relays
dir portc.2 out
#define LED portc.3 '' status LED
dir portc.3 out
''=========
#define RUN porta.0 '' run signal from chains drive
dir porta.0 in
#define sensor_1 porta.1 '' sensors
dir porta.1 in
#define sensor_2 porta.2 '' sensors
dir porta.2 in
#define sensor_3 porta.3 '' sensors
dir porta.3 in
#define sensor_4 porta.4 '' sensors
dir porta.4 in
set LED on
''--------------------------------------- reklama
locate 0,0
print "WATCHDOG 2017 "
locate 1,0
print "J.K.egineering "
wait 1 s
'Scroll display one character right (all lines) lcdcmd 28
repeat 15
lcdcmd 28
wait 100 ms
end repeat
lcdcmd 2
cls
''===========================================
'' timer2 for CLOCK
inittimer2 PS2_16, 0 '' (8bit timer) timer2 prescaler, postscaler
'' Fosc=4MHz; Fosc=4/4=1MHz; 1000kHz/16 =(PS2_16) =62,5kHz=62500Hz
'' 62500/256(8bit timer)=244
cleartimer 2
TMR2IE = 1
full=0
sec=0
min=0
hours=0
sec_disp=0
min_disp=0
pushtime_1=0
now1=0
prev1=0
aa=0
pushtime_2=0
now2=0
prev2=0
bb=1
now3=0
prev3=0
''=========================
now_run=0
prev_run=0
nowFLT=0
prevFLT=0
now_sens_all=0
prev_sens_all=0
now2_sens_all=0
prev2_sens_all=0
now3_sens_all=0
prev3_sens_all=0
now_sens1=0
prev_sens1=0
now_sens2=0
prev_sens2=0
now_sens3=0
prev_sens3=0
now_sens4=0
prev_sens4=0
now2_sens1=0
prev2_sens1=0
now2_sens2=0
prev2_sens2=0
now2_sens3=0
prev2_sens3=0
now2_sens4=0
prev2_sens4=0
dim pulse_ind, bit_sens1, bit_sens2, bit_sens3, bit_sens4, bit_sens_all, bit_sens_all2 as bit
bit_sens1=0
bit_sens2=0
bit_sens3=0
bit_sens4=0
bit_sens_all=0
bit_sens_all2=0
'' milisec un decisec (sec/100)
decsec1=0
decsec2=0
decsec3=0
decsec4=0
decsec_all=0
full_dec_cyc=0
decsec_cyc=0
full_dec1=0
full_dec2=0
full_dec3=0
full_dec4=0
full_dec_all=0
full_dec_all=0
ind_time=0
ind_time2=0
dim increment, decrement, sens1_difflt, sens2_difflt, sens3_difflt, sens4_difflt, sens_difflt, sens_cycflt as bit
''=============
epread 0, set_diff_dsec
epread 1, diff_sens1
epread 2, diff_sens2
epread 3, diff_sens3
epread 4, diff_sens4
epread 5, decsec_cyc
EPRead 6, set_cyc_dsec
epread 7, sens_difflt
epread 8, sens_cycflt
epread 9, sens1_difflt
epread 10, sens2_difflt
epread 11, sens3_difflt
epread 12, sens4_difflt
''=======================
do while button_up_down_reset=0
set LED on
set_diff_dsec=20
set_cyc_dsec=50
wait 100 ms
set LED off
wait 100 ms
diff_sens1=0
diff_sens2=0
diff_sens3=0
diff_sens4=0
sens1_difflt=0
sens2_difflt=0
sens3_difflt=0
sens4_difflt=0
sens_difflt=0
sens_cycflt=0
epwrite 0, set_diff_dsec
EPwrite 6, set_cyc_dsec
FAULT=0
loop
''==============
set LED off
''=================
main:
starttimer 2
''=====================================
if !button_menu then
pushtime_1++
sec_disp=0
min_disp=0
else
pushtime_1=0
end if
''===============
''TOOGLE SW
now1=!button_menu & pushtime_1=>50
if now1>prev1 then
pushtime_1=0
aa++
cls
end if
prev1=now1
'' DISPLAY CASES
select case aa
case 0 '' MAIN DISPLEJS
MAIN_disp
case 1
test_difftime
case 2
set_difftime
case 3
test_cyctime
case 4
set_cyctime
case 5
aa=0
end select
''==========================================
now_run= !RUN
if now_run>prev_run then
cls
sec=0
min=0
hours=0
end if
prev_run=now_run
''=============================
if RUN=0 & FAULT=0 then
''sensor_1 HIGH LEVEL FRONT (rising edge)
now_sens1=!sensor_1
if now_sens1>prev_sens1 Then
cls
bit_sens1=1
decsec1=0
diff_sens1=0
end if
prev_sens1=now_sens1
' sensor_1 LOW LEVEL FRONT (falling edge)
now2_sens1=sensor_1
if now2_sens1>prev2_sens1 Then
cls
diff_sens1=decsec1
epwrite 1, diff_sens1
bit_sens1=0
decsec1=0
end if
prev2_sens1=now2_sens1
''+++++++++++++++++++++++++++++++
' sensor_2 HIGH LEVEL FRONT (rising edge_)
now_sens2=!sensor_2
if now_sens2>prev_sens2 Then
cls
bit_sens2=1
decsec2=0
diff_sens2=0
end if
prev_sens2=now_sens2
' sensor_2 LOW LEVEL FRONT (falling edge)
now2_sens2=sensor_2
if now2_sens2>prev2_sens2 Then
cls
diff_sens2=decsec2
epwrite 2, diff_sens2
bit_sens2=0
decsec2=0
end if
prev2_sens2=now2_sens2
''+++++++++++++++++++++++++++++++++
'' sensor_3 HIGH LEVEL FRONT (rising edge)
now_sens3=!sensor_3
if now_sens3>prev_sens3 Then
cls
bit_sens3=1
decsec3=0
diff_sens3=0
end if
prev_sens3=now_sens3
' sensor_3 LOW LEVEL FRONT (falling edge)
now2_sens3=sensor_3
if now2_sens3>prev2_sens3 Then
cls
diff_sens3=decsec3
epwrite 3, diff_sens3
bit_sens3=0
decsec3=0
end if
prev2_sens3=now2_sens3
''+++++++++++++++++++++++++++++++
' sensor_4 HIGH LEVEL FRONT (rising edge_)
now_sens4=!sensor_4
if now_sens4>prev_sens4 Then
cls
bit_sens4=1
decsec4=0
diff_sens4=0
end if
prev_sens4=now_sens4
' sensor_4 LOW LEVEL FRONT (falling edge)
now2_sens4=sensor_4
if now2_sens4>prev2_sens4 Then
cls
diff_sens4=decsec4
epwrite 4, diff_sens4
bit_sens4=0
decsec4=0
end if
prev2_sens4=now2_sens4
'=================================
' all sensors =1 OR logic
now_sens_all= (bit_sens1 or bit_sens2 or bit_sens3 or bit_sens4) & bit_sens_all=0 ''
if now_sens_all > prev_sens_all Then
bit_sens_all=1
end if
prev_sens_all=now_sens_all
' all sensors =1 AND logic
now3_sens_all= (bit_sens1 & bit_sens2 & bit_sens3 & bit_sens4 & bit_sens_all=1) ''
if now3_sens_all > prev3_sens_all Then
bit_sens_all2=1
epwrite 5, decsec_cyc
end if
prev3_sens_all=now3_sens_all
'' all sensors=0 AND logic
now2_sens_all= (bit_sens1=0 & bit_sens2=0 & bit_sens3=0 & bit_sens4=0 & bit_sens_all &bit_sens_all2)
if now2_sens_all > prev2_sens_all Then
''=====
full_dec_cyc=0
decsec_cyc=0
''====
bit_sens_all=0
bit_sens_all2=0
end if
prev2_sens_all=now2_sens_all
''==================================
end if
''======
if aa<>0 Then
if min_disp=2 Then
cls
aa=0
min_disp=0
sec_disp=0
end if
end if
''==============================================================================
wait 10 ms
goto main
'' CLOCK (Timer 2)
sub Interrupt
TMR2IF = 0
full++
if full=244 then
sec_disp++
if RUN=0 then sec++
full=0
end if
if sec_disp>59 then
sec_disp=0
min_disp++
end if
if min_disp>59 Then min_disp=0
if RUN=0 then
if sec>59 then
min++
sec=0
end if
if min>59 then
hours++
min=0
end if
if hours>99 then hours=0
''=============== decisekundes for sensors
full_dec1++
full_dec2++
full_dec3++
full_dec4++
If full_dec1=24 Then
decsec1++
full_dec1=0
end if
If full_dec2=24 Then
decsec2++
full_dec2=0
end if
If full_dec3=24 Then
decsec3++
full_dec3=0
end if
If full_dec4=24 Then
decsec4++
full_dec4=0
end if
''======== diff fault ==================================
''=============================
if bit_sens_all then
full_dec_all++
If full_dec_all=24 Then
decsec_all++
full_dec_all=0
end if
Else
full_dec_all=0
decsec_all=0
end if
''================
''=========cyc flt
if bit_sens_all2=0 Then
full_dec_cyc++
If full_dec_cyc=24 Then
decsec_cyc++
full_dec_cyc=0
end if
end if
''=============
end if
'''===========STATUS LED (1sec tact)
if full<10 then
set LED on
Else
set LED off
end if
end sub
''========= MAIN displejs
sub MAIN_disp '' (aa=0)
locate 0,0
print "RUNTIME="
if hours<10 then
locate 0,8
print "0"
locate 0,9
print hours
Else
locate 0,8
print hours
end if
locate 0,10
print ":"
if min<10 Then
locate 0,11
print "0"
locate 0,12
print min
else
locate 0,11
print min
end if
locate 0,13
print ":"
if sec<10 Then
locate 0,14
print"0"
locate 0,15
print sec
Else
locate 0,14
print sec
end if
''=========================================================
''===================== comparators, fault detectors if bit_sens_all=1
if decsec_all>set_diff_dsec then ''===DIFF FAULT
if decsec1>set_diff_dsec or bit_sens1=1 then sens1_difflt=1
if decsec2>set_diff_dsec or bit_sens2=1 then sens2_difflt=1
if decsec3>set_diff_dsec or bit_sens3=1 then sens3_difflt=1
if decsec4>set_diff_dsec or bit_sens4=1 then sens4_difflt=1
sens_difflt=1
end if
if decsec_cyc>set_cyc_dsec then sens_cycflt=1 '' ===CYC FAULT
'' ====== FOR lcd blinking
if full<122 Then
if sens_difflt=1 & sens_cycflt=0 then
locate 1, 0
print "FLTsens:"
if sens1_difflt then
locate 1, 8
print "1"
end if
if sens2_difflt then
locate 1, 9
print "&2"
end if
if sens3_difflt then
locate 1, 11
print "&3"
end if
if sens4_difflt then
locate 1, 13
print "&4"
end if
end if
if sens_cycflt & sens_difflt=0 then
locate 1, 0
print "CYCFLT:"
locate 1, 7
print decsec_cyc
locate 1, 10
print "decsec"
end if
Else
locate 1, 0
print " "
end if
'''======================================
if sens_difflt=1 or sens_cycflt=1 then
set FAULT on
Else
set FAULT off
end if
nowFLT = FAULT
if nowFLT>prevFLT then
epwrite 7, sens_difflt
epwrite 8, sens_cycflt
epwrite 9, sens1_difflt
epwrite 10, sens2_difflt
epwrite 11, sens3_difflt
epwrite 12, sens4_difflt
end if
prevFLT=nowFLT
''===========================
button_up_down_reset_act
if pushtime_2=30 Then
sens1_difflt=0
sens2_difflt=0
sens3_difflt=0
sens4_difflt=0
sens_difflt=0
bit_sens_all=0
bit_sens_all2=0
decsec1=0
decsec2=0
decsec3=0
decsec4=0
decsec_all=0
sens_cycflt=0
decsec_cyc=0
epwrite 5, decsec_cyc
epwrite 7, sens_difflt
epwrite 8, sens_cycflt
epwrite 9, sens1_difflt
epwrite 10, sens2_difflt
epwrite 11, sens3_difflt
epwrite 12, sens4_difflt
cls
end if
end sub
sub test_difftime
locate 0, 0
print "diff:1="
locate 0, 11
print "2="
locate 1, 1
print "3="
locate 1, 7
print "4="
''=====================
if bit_sens1 Then
locate 0, 7
print decsec1 ' "RUN"
Else
locate 0 , 7
print diff_sens1
end if
''=====================
if bit_sens2 Then
locate 0, 13
print decsec2' "RUN"
Else
locate 0 , 13
print diff_sens2
end if
''=====================
if bit_sens3 Then
locate 1, 3
print decsec3' "RUN"
Else
locate 1 , 3
print diff_sens3
end if
''====================
if bit_sens4 Then
locate 1, 9
print decsec4' "RUN"
Else
locate 1 , 9
print diff_sens4
end if
end sub
sub set_difftime '' (aa=2)
locate 0, 0
print "SET DIFF_TIME: "
''======================
call button_up_down_reset_act
''+++++++++++++++++++++++++
now3=!button_up_down_reset & pushtime_2>2 & pushtime_2<20
if now3>prev3 then
cls
if increment & set_diff_dsec < 200 Then set_diff_dsec++
if decrement Then set_diff_dsec--
epwrite 0, set_diff_dsec
end if
prev3=now3
''============================
locate 1, 4
print set_diff_dsec
locate 1, 9
print " decsec"
end sub
''=========================
sub test_cyctime '' (aa=3)
locate 0, 0
print "test CYCTIME:"
locate 1, 2
print decsec_cyc
locate 1, 6
print "secdec"
end sub
sub set_cyctime '' (aa=4)
locate 0,0
print "SET CYC_TIME: "
''======================
call button_up_down_reset_act
''+++++++++++++++++++++++++
now3=!button_up_down_reset & pushtime_2>2 & pushtime_2<20
if now3>prev3 then
cls
if increment & set_cyc_dsec < 250 Then set_cyc_dsec++
if decrement Then set_cyc_dsec--
epwrite 6, set_cyc_dsec
end if
prev3=now3
''============================
locate 1, 4
print set_cyc_dsec
locate 1, 9
print " decsec"
''=======================
end sub
sub button_up_down_reset_act
if !button_up_down_reset then
pushtime_2++
sec_disp=0
min_disp=0
Else
pushtime_2=0
end if
if aa<>0 Then
now2=!button_up_down_reset & pushtime_2=50
if now2>prev2 Then bb++
prev2=now2
select case bb
case 1
increment=1
decrement=0
case 2
increment=0
decrement=1
case 3
bb=1 '' !!!!!!!!!!
end select
locate 1, 0 ' inc vai dec indikacija
if bb=1 then print "(+)"
if bb=2 then print "(-)"
end if
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Very exciting when a project comes together and works. Thanks for sharing!
I too live in a farming community and do ocassional work with dryers and grain storage. Last year I started a project to monitor a grain leg belt type bucket elevator. The drive is at the top and when the operator dumps corn in the bottom too fast the belt/buckets slow down from slipping. Was going to uses an inductive sensor and give an alarm when the "tail pulley" slowed. Similar to your project but not as in depth.
I will look over when time permits.
Too many projects,too little time.
BR
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Circuit diagramms and pcb I designed with the online program EASYEDA. Very good. I recommend you! There can also be sharing projects. There's also help around the clock, just like here :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all!
I want to publish a long code - Grain dryers chains damage detector. This project will first be installed on a single grain dryer as an experiment. In the test mode on the stand, it works perfectly. But if it works, there will be a demand for other dryers. Some time ago I already published a code for a project that used an encoder and compared the numbers of the impulses. Installation of encoders is complicated and costly. This project is based on the time difference between 4 inductive sensors. I have written the package leaflet also in English, translated from the Latvian language. The instruction is included in Word format. I do not know English perfectly, so if you see an error in my instructions, please correct it. Maybe someone sees the inaccuracies in the program code and can something be corrected or simplified? I also added a scheme.
Circuit diagramm
instruction in english
In The program code #include <maths.h> not used. I forgot to delete.
Always interesting to see your projects, thanks for sharing. What, no klaxon/emergency horn to wake up the sleeping operator? haha.
Very exciting when a project comes together and works. Thanks for sharing!
I too live in a farming community and do ocassional work with dryers and grain storage. Last year I started a project to monitor a grain leg belt type bucket elevator. The drive is at the top and when the operator dumps corn in the bottom too fast the belt/buckets slow down from slipping. Was going to uses an inductive sensor and give an alarm when the "tail pulley" slowed. Similar to your project but not as in depth.
I will look over when time permits.
Too many projects,too little time.
BR
Mike
Circuit diagramms and pcb I designed with the online program EASYEDA. Very good. I recommend you! There can also be sharing projects. There's also help around the clock, just like here :)
Thank you to all who help and share information! Information must be shared, otherwise there will be no development! :) GCB rullz :)