|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
16f84 Switch counter to lcdI have to say i am astounded by the reponses. A bit more information i have an old water meter that i have removed the broken dial from the middle. Placed a hall effect switch in the cavity and have it flasheing an led everytime the cylinder turns. Every 50 turns equals 1 gallon. This helped me find a slow leak and fix it. (The new water meter outside does not have slow flow indicatior until the sun has turned the display on.) I then wanted to see how much we use on a typical day - hence this project. Whilst i whole heartedly thank you for your help. I also am now a little more cunfused and need to digest my options. I need to look at Input / output again and whetheri can wait for the whole code to finish before the switch gets polled, seems like a delay ! Regarding the bounce, i origianally had problems witht he hall switch bouncing. but i now used a relay for the switch to contact, and have yet no bounce problems when flashing a led with this setup. However this was before i put a PIc in the picture. Once again i thank you. I will look at other languages too, but i think as my book is all Assembly I am going to sturggle redesigning the lcd part. Thanks again Paul Firstly THANK YOU TO ALL. The book i have demonstrates the Assembly language and each chapter increases the knowledge depth. However i think i do not understand as much as i think i do. I am Proud to say i figured the inputs and outputs and using the data sheet assigned one of the input/output pins for the RB4 Switch and RB5 for the LED. I am currently looking at Interupts to see if i can make head nor tail of them and hopefully the interupts would then break into the program and do what it should do if the switch is pressed. If this works i guess i put my increment count into the interrupt routine and then when its finished or back to 0 or off then the rest of the program would continue. Right now the header for the book puts A and B as outputs, do i just change RB4 to a input or and if so how without setting bank B to all inputs. This has stumped me for a an hour now. I have a day off and i said to my wife i would paint but this has been taking me over all day so far. Thanks again Paul Just to update, I am hopelessly new and lost. I was a VB basic guy years ago and remember a little of what I need to do but not a lot. I know I will need a place to store the count, and will have a call list up to 50 so when the count equals 10 I will have a call to put 1+0 on the screen. How do I : Create a place to store the count. Increment 1 to this count when the state changes compare the stored count so when it equals 50 I increment the lcd by 1 I was hoping to find a piece of code out there in Google land to help me but as of yet I have not been successful. However I do feel a sense of achievement coming this far. Any help is of course appreciated. Thanks Paul Hi all. I am trying to make a switch counter that would put on the lcd screen how many times /50 the switch has been opened/closed. I purchased the Book PIC In Practice and have been successful in building the LCD circuit 2x20 and able to put the words I need to the screen. (after spending hours trying to get it to work) What I need and am hopelessly lost at this point, is to count the switch on A0 and put the amount on to the screen. using the lcd Code in the above book. I beg you, this is not for any other purpose than to count the water gallon usage in my house using a hall effect switch on the meter. Can anyone help me with code/ suggestions etc Thanks in advance Paul -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdOn Fri, 23 Oct 2009 17:35:51 -0500, "Paul & Lynn Tyrer" <Paul@...> said: > A bit more information i have an old water meter that i have removed the > broken dial from the middle. Placed a hall effect switch in the cavity > and > have it flasheing an led everytime the cylinder turns. Every 50 turns > equals > 1 gallon. This helped me find a slow leak and fix it. So how about instead of dividing by 50 you just add 2 each time, and put a decimal place two digits over? That way you can read in 0.02 gallon increments. Even better, add 1 each time there is a change of switch state. You can display down to 0.01 gallon. The 1/50 gallon won't be evenly divided in two but it will help you spot leaks that much faster, and maybe the code will be easy since any routine needs to spot changes of state. Cheerful regards, Bob -- http://www.fastmail.fm - mmm... Fastmail... -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcd> origianally had problems witht he hall switch bouncing. but i now
> used a relay for the switch to contact So using the Hall switch to energise a relay has cured the bounce ? That sounds like the magnetic inertia of the coil is filtering the bounce noise, the result being that the contacts don't chatter If that's correct then adding an RC filter to pre-condition the switch output would help, although not strictly necessary if the s/w can do as good a job with a delay or polling routine. For example something like 10k and 100nF would be a starting point. The 10k and 100n are joined in series. Their junction goes to the PIC pin. The other end of the resistor goes to the Hall switch, the other end of the capacitor goes to 0V http://en.wikipedia.org/wiki/RC_filter You may need a discharge resistor (say 100k) across the capacitor if the Hall switch doesn't drive to 0V, as the high impedance of the PIC pin may not be low enough to discharge the capacitor between switch pulses -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdPaul & Lynn Tyrer wrote:
> (The new water meter > outside does not have slow flow indicatior until the sun has turned the > display on.) > Flashlight works on mine ... which is inside.... > I need to look at Input / > output again and whetheri can wait for the whole code to finish before the > switch gets polled, seems like a delay ! > a 3/4" pipe will likely not do over 40GPM, which means less than 1 pulse per second. Shouldn't be a problem. > Regarding the bounce, i origianally had problems witht he hall switch > bouncing. but i now used a relay for the switch to contact, and have yet no > bounce problems when flashing a led with this setup. However this was before > i put a PIc in the picture. > We're generally talking about bounces down 50 milliseconds... so as long as you insert a hundred milliscond delay, you should be ok (1000 ms in a sec). If your code takes over 100ms to complete, you can also just use it as the debouncer.... Mainly what you don't want to have happen is you read the pin, determine it is high, then read it too soon again - because there is a chance that it will turn on and off a whole bunch of times within the first few milliseconds of turning it on. Thus getting false counts. > I will look at other languages too, but i think as my book is all Assembly I > am going to sturggle redesigning the lcd part. > The mikroe basic compiler I suggested has LCD part built in... Plus the basic might free you up to play with things like metering on a last-minute, last-hour, and last day basic (think about creating a small array in memory of buckets)... want ideas for this later, shoot me or the list a ide... Sample code for your application, assuming bits as described below: Program Meter 'Adjust the following dim LCD_RS as sbit at RB4_bit LCD_EN as sbit at RB5_bit LCD_D4 as sbit at RB0_bit LCD_D5 as sbit at RB1_bit LCD_D6 as sbit at RB2_bit LCD_D7 as sbit at RB3_bit LCD_RS_Direction as sbit at TRISB4_bit LCD_EN_Direction as sbit at TRISB5_bit LCD_D4_Direction as sbit at TRISB0_bit LCD_D5_Direction as sbit at TRISB1_bit LCD_D6_Direction as sbit at TRISB2_bit LCD_D7_Direction as sbit at TRISB3_bit hallsensor as sbit at RB6_bit dim lasthall as bit dim thishall as bit dim hundreths as byte dim gallons as word dim hundrethsstring as string[2] dim gallonsstring as string[4] main: ' Adjust the following as needed for your processor and wiring. TRISB = 0 PORTB = 0xff TRISB = 0xff Lcd_Init() 'Initialize display Lcd_Cmd(_LCD_CLEAR) ' Clear Display Lcd_Cmd(_LCD_CURSOR_OFF) 'Turn cursor off lasthall=0 hundreths = 0 gallons = 0 while TRUE thishall=hallsensor ' capture so if it bounces quickly, we don't have logic errors if thishall<>lasthall then delay_ms (50) ' adjust as needed to eliminate bounces hundreths=hundreths+2; // add 2 hundredths if hundredths>99 then hundreths=hundredths-100 gallons=gallons+1 end if ByteToStr(hundreths, hundrethsstring) if hundredthsstring[0]=' ' then hundrethsstring[0]='0' ' Handle single digits correctly WordToStr(gallons, gallonsstring) Lcd_Out(1,5,gallons) Lcd_Chr(1,10,'.') Lcd_Out(1,11,hundrethsstring) if thishall then Lcd_Chr(1,1,'H') 'show status of hall sensor at 1,1 else Lcd_Chr(1,1,'L') 'show status of hall sensor at 1,1 end if wend end. The above should (besides the fact I never tested it in mikro basic, and I likely have typos and the like) do exactly what you are asking for. Other thank the mikro-basic that should be mostly what you need. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdI don't recall seeing this tidbit, so I thought I'd comment.
Regarding the bounce, i origianally had problems witht he hall switch > bouncing. but i now used a relay for the switch to contact, and have yet no > bounce problems when flashing a led with this setup. However this was > before > i put a PIc in the picture. > Don't be fooled by watching an LED. Switch bounce is way faster than your eye can see. You would need an oscilloscope to see it. Or...a fast processor...! If you have contact bounce, you will get tens of counts with each switch closure. And that's why everyone is talking so enthusiastically about it. Barry -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcd> Regarding the bounce, i origianally had problems witht he hall switch
>> bouncing. but i now used a relay for the switch to contact, and have yet no >> bounce problems when flashing a led with this setup. However this was >> before >> i put a PIc in the picture. Note that a Hall switch tends to provide a degree of inbuilt debouncing due to hysteresis in its response to a magnetic field. This is often quite a significant amount compared to what may be needed. For bounce to occur the field must rise to the trigger point and then drop by the hysteresis amount and then rise to the trigger point again. Also, in a rotating system where a Hall switch detects a magnet, "bounce" tends to suggest axial vibration (to and fro around the axis of rotation. In a rotating system the mechanical slop tends (only TENDS) to be preloaded by windage and other forces and so reduce such contributors to bounce. However, Murphy can make anything bounce if the situation demands it. R -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
| Free embeddable forum powered by Nabble | Forum Help |