Académique Documents
Professionnel Documents
Culture Documents
Home
News
AVR Projects
PIC Projects
Electronics
Links
Sitemap
Translation
Romanian pages
Main Pages
Software File archive Windmill Blog Contact
RESOL DeltaSol BX
www.resol.de The new generation of controllers for solar thermal systems
https://sites.google.com/site/funlw65/tutorials/jal-projects/windmill-controller-logger-shield
1/3
7/12/2013
f o r e v e rl o o p -= = = = = = = =s t a r tt h ec o u n t i n gp r o c e d u r e= = = = = = = = -s t a r tt h ed e l a yo f1s e c o n do nf i r s ts l o t( w h i c hi s0 ) s e t _ d e l a y ( 0 ,1 0 0 0 ) r e p e a t i fD 7= =1t h e n-p o s i t i v ep u l s eo nD 7p i n f l a g=1 -s o ,m a r ki tt ob ec o u n t e dw h e np u l s ew i l lf a l l e l s i ff l a g= =1t h e n-n o wD 7i s0( p u l s ef a l l e n=c o m p l e t e )a n di ff l a gi ss e t , -w ec o u n tt h ep u l s e c o u n t i n g=c o u n t i n g+1 -c o u n t e d !h u r a y ,w eh a v eap u l s e ! f l a g=0 -o k ,c l e a nt h ef l a gt ob er e a d yf o ra n o t h e rr i s i n gp u l s e e n di f u n t i lc h e c k _ d e l a y ( 0 )-c h e c kt h es l o tt os e ei fd e l a ye x p i r e d -t i m ee x p i r e d ,w ee r a s et h ef l a g f l a g=0 -= = = = = = = = = = = = =e n dt h ec o u n t i n gp r o c e d u r e= = = = = = = = = = = = = = = -d os o m e t h i n gw i t hc o u n t i n gv a r i a b l ea n dt h e nr e i n i t i a l i z ei t -o k ,d i ds o m e t h i n g( e . g . ,s e n tt h ev a l u ev i as e r i a lo rd i s p l a y e do nL C D ) c o u n t i n g=0 e n dl o o p
This is the "usual " method of counting pulses on positive edge. Is easy to modify it for the negative edge - an exercise for the reader? An USB example: Unfortunately, we will loose the USB connection (and the application will be blocked) if there is no activity for a maximum of 10 milliseconds pause. We need to deal with that. Bellow is my proposal . I will not go for a maximum of 10 millisecond delay because it is possible to loose the connection. I will "push" the USB at every 5ms and this is the interval for counting. I will count pulses on 5ms interval and repeat it 200 times to gather 1 second. -C o u n t i n gp u l s e so np o s i t i v ee d g e i n c l u d ef r e e j a l d u i n o 4 . j a l i n c l u d eu s b _ s e r i a l i n c l u d ep r i n t c o n s tt i m e r 0 _ i s r _ r a t e=1 0 0 0-1k H zi s rr a t e c o n s tD E L A Y _ S L O T S=1-w en e e do n l yo n ed e l a ya tat i m e i n c l u d et i m e r 0 _ i s r _ i n t e r v a l t i m e r 0 _ i s r _ i n i t ( )-i n i tt i m e r 0i s r v a rb i tf l a g v a rw o r dc o u n t i n g-i fm o r et h a n6 5 5 3 5c o u n t so n1s e c o n de x p e c t e d , -u s ed w o r dt y p ei n s t e a do fw o r d . e n a b l e _ d i g i t a l _ i o ( )-a l lp i n sa r en o wd i g i t a l -d e f i n eo nw h i c hp i nw ed oc o u n t i n g D 7 _ d i r e c t i o n=I N P U T f l a g=0 c o u n t i n g=0 u s b _ s e r i a l _ i n i t ( ) f o r e v e rl o o p u s b _ s e r i a l _ f l u s h ( ) -= = = = = = = =s t a r tt h ec o u n t i n gp r o c e d u r e= = = = = = = = f o r2 0 0l o o p-5*2 0 0=1s e c o n d -s t a r tt h ed e l a yo f5m i l l i s e c o n d so nf i r s ts l o t( w h i c hi s0 ) s e t _ d e l a y ( 0 ,5 ) r e p e a t i fD 7= =1t h e n-p o s i t i v ep u l s eo nD 7p i n f l a g=1 -s o ,m a r ki tt ob ec o u n t e dw h e np u l s ew i l lf a l l e l s i ff l a g= =1t h e n-n o wD 7i s0( p u l s ef a l l e n=c o m p l e t e )a n di ff l a gi ss e t , -w ec o u n tt h ep u l s e c o u n t i n g=c o u n t i n g+1-c o u n t e d !h u r a y ,w eh a v eap u l s e ! f l a g=0 -o k ,c l e a nt h ef l a gt ob er e a d yf o ra n o t h e rr i s i n gp u l s e e n di f u n t i lc h e c k _ d e l a y ( 0 )-c h e c kt h es l o tt os e ei fd e l a ye x p i r e d u s b _ s e r i a l _ f l u s h ( )-t e l lt ot h eu s bw ea r ea c t i v e e n dl o o p -c y c l ee n d e d ,w ee r a s et h ef l a g f l a g=0 -= = = = = = = = = = = = =e n dt h ec o u n t i n gp r o c e d u r e= = = = = = = = = = = = = = =
https://sites.google.com/site/funlw65/tutorials/jal-projects/windmill-controller-logger-shield
2/3
7/12/2013
Why not a 10 millisecond delay? Well , we can try that anyway but is not about an exact delay as is a blocking one (delay_1ms(10)). We start the timer, we do other things then check if the timer has finished his counting. If you get over 10ms, then you may loose USB connection so, 5ms is better.
2. The Hardware
-- not yet available --
Comentarios
H o b b i tn a m e :T o g oT o a d f o o to fF r o g m o r t o n E l v i s hn a m e :M a b l u n gM i r i e l
C o n t e n tc o p y r i g h t( c )V a s i l eG u t aC i u c u r
Iniciar sesin | Informar de uso inadecuado | Imprimir pgina | Eliminar acceso | Con la tecnolog a de Google Sites
Traductor de Google
https://sites.google.com/site/funlw65/tutorials/jal-projects/windmill-controller-logger-shield
3/3