Home - Search - Members
Full Version: Sensors
Pages: 1, 2, 3, 4, 5, 6
Ajay
Mar 30 2008, 9:04 AM
why are you initializing lcd again and again? I mean just use lcd clear command to clear lcd instead of re-initializing. Init part should be just once at the starting of program.
pdi33
Mar 30 2008, 9:10 AM
have read all the details of your project. Am confused about your power supply part. I havealready used all the components you are using and in fact had used multiplexed 0.5" LED displays instead of LCD. but never did i find a need for a supply current exceeding 500mA. The only current consuming part in your ckt is the backlight which itself takes upto 100mA. Do connect the 10 ohms resistor in series as it will limit the current to the led.
check your sensor ciruit (analog input section) as it may be draining most of the current.
the 7805 cannot source more than 1A current and will shut down if excess current is drawn.
As for the ADC resolution part, I have a novel way to interface ICL7135 to the 8051 by using only 4 i/o pins. and will post it shortly. The 7135 can give a resolution of upto +/-20,000 counts i.e. more than 14 bit resolution and is as cheap or even cheaper than ADC0808. check out its datasheet.
pdi33
Mar 30 2008, 9:15 AM
ajay is right . Why reset the whole uC when you can just refresh the data??
Amit Radha
Mar 30 2008, 9:34 AM
Ok i am terribly confused now :'( i dunno wat to do.
I hope u understod my concern regarding the display. Il upload my code pls do go thro it and suggest changes. (It is not yet complete and it is for the LM35 only not done for other sensors.)
Regarding the supply, i interfaced my boards and sensors to a 9v transformer (dunno the current rating) in my lab and dint face any loading problem. I purchased a 2A one to be on the safer side.l Dint know the 7805 cant handle higer current

Pls do check my code and tel me wat to do. Also do i need to include any file in the beginning? i will be using keil uVision 2
pdi33
Mar 30 2008, 9:53 AM
it doesnot matter if u use a higher current txformer as long as ur curcuit does not sink more than 1amp current, go ahead and use it
pdi33
Mar 30 2008, 9:56 AM
remember that the transformer current rating is the maximum capacity which it can sorce and not the actual current it is sourcing
pdi33
Mar 30 2008, 10:08 AM
where is the code?
Amit Radha
Mar 30 2008, 10:19 AM
oh i attached it... il do it again...
Yup i know that about that transformer
maincode1.zip
Amit Radha
Mar 30 2008, 11:08 AM
Hey i got a solution to the problem. Just tell me if my logic is not faulty!!!
In the ISR, After displaying the actuator status, there is a 5sec delay (so that user can see the status on the LCD for 5sec.) then instead of RETI il again display the sensor data from the buffer and then RETI.
This will send back the control to where the uC was interrupted. So even if it was displaying sensor data and was interrupted midway, it will just redisplay it in the same locations on the LCD but the LCD wont be garbled right?
And yes, i will remove the repeated initialisation of the LCD from the code.
Pls do tell me incase of any more mistakes in my code...

Thanks
sashijoseph
Mar 30 2008, 11:21 AM
Had a brief look at your code.Like Ajay said you should initialise the LCD only once whereas you've done it 3 times.
This is how it should be:
1- initialise LCD
2- display welcome msg
3- Read ADC
4- Convert
5- Data Display
6- Threshold check
7- Back to step 3

You needn't re-initialise the LCD in steps 2,5 or the ISR.

As for the ISR doubt.....this is what you can try.Use a flag,say 'Act'.Inside the ISR you do 2 things.First set the Act flag ie. Act=1.Then display a msg "Hang on,gathering Actuator data....." or sth similar.Then a RETI.
Now in the data display routine(step 5) this is what you do.....
1 check Act bit.
2 If Act=1
(-IE=0 ;disable interrupts
-Display Actuator Data.
-Wait 5 sec.
-Make Act=0
-Display Sensor data
-IE = 81h ;re-enable interrupts
-Ret
)
Else (-Display sensor data
-Ret
)
Amit Radha
Mar 30 2008, 11:33 AM
hey thanks a ton! you simplified so many things in my code!!!
This is a very good idea. But i had a doubt.
Now when the user presses the button for viewing the actuator status, wont there be a big time lag before the actuator status is displayed on the LCD? considering that at that instant the uC was checking threshold?
pdi33
Mar 30 2008, 11:39 AM
seeing your code. one common mistake is that u have not pushed the registers r0,r7 and accumulator before executing the ISR. this may corrupt their values from the main routine.
always backup the general purpose variables. my c16 universal hex compiler doesnot support 'push r0' instruction. So i always set the register bank to a different value before executing ISRs. but in this case, take care that the stack pointer is reassigned a different location as its default location is 08h which corresponds to second register bank.
be careful
Amit Radha
Mar 30 2008, 11:45 AM
oh oki il do that! dint realise that it could create a problem.
I was under the impression that the the uC takes care of pushing all reg values etc to a stack and the RETI instruction is specifically used for the purpose of retrieving them all.
So shall i initialise the stack to 10h and push acc, r0? or shall i not initialise the stack.
Also, i am not using r7. then why should i push it?
pdi33
Mar 30 2008, 11:47 AM
another problem is the 'conversion' routine. in the adc routine, u store theadc value(binary) in 'BUFFER'. now this when converted to BCD can be a two or three digit value. so u have to split it nibble by nibble and then convert it to ascii. confused? just check your conversion routine by assigning a fixed value say 15h to variable 'buffer' and see what output u get in ASCII_RESULT.
pdi33
Mar 30 2008, 11:51 AM
i would suggest that u first write the LCD interface part, then add the ADC code and finally the actuator logic. Step by step debugging usually saves a lot of time.
pdi33
Mar 30 2008, 11:54 AM
push only the registers which are used mutually by both your main code and your ISR. and yes if you are using a different register bank in ISR, u need not push r0-r7 but reassign stack to 10h. If ur compiler supports Push r0 instruction, u need not assign the SP to different value.
pdi33
Mar 30 2008, 12:57 PM
check this code. i donot know from where i downloaded it . good reference. it gets value from ADC0808 and displays it on lcd.
pdi33
Mar 30 2008, 1:00 PM
oops cannot upload asm files. will attach it in zip format
adc0808.zip
sashijoseph
Mar 30 2008, 5:18 PM
Now when the user presses the button for viewing the actuator status, wont there be a big time lag before the actuator status is displayed on the LCD? considering that at that instant the uC was checking threshold?

Won't take more than a few milliseconds unless delays have been purposely introduced.
In that case you may try this:
In the ISR .... set Act,jump to Data_Display routine.
In Data_Display:
If Act=1
(-IE=0 ;disable interrupts
-Display Actuator Data.
-Wait 5 sec.
-Display sensor data
-Make Act=0
-IE = 81h ;re-enable interrupts
-RETI
)
Else (-Display sensor data
-Ret
)
Amit Radha
Mar 30 2008, 8:09 PM
Oh oh... so many mistakes!!! dint expect this to happen!!!
Regasrding the conversion routine:
pdi33 wrote ...

another problem is the 'conversion' routine. in the adc routine, u store theadc value(binary) in 'BUFFER'. now this when converted to BCD can be a two or three digit value. so u have to split it nibble by nibble and then convert it to ascii. confused? just check your conversion routine by assigning a fixed value say 15h to variable 'buffer' and see what output u get in ASCII_RESULT.

i thought that instead of the uC doing the calculations, il manually calculate wat must be the o/p and make 2 LUTs one for the tens place and one for the ones place and pick up the direct display values from it.
for eg if for 2.5V o/p from the temp sensor (using an opamp with gain 4.8) the bcd o/p af the ADC is 128d or 80h. Which coresponds to ~52 deg C. So At the 128th location of the "tens" LUT il store 35 and "ones" LUT il store 32 and use 2 loops in the data display routine to pick up the temp reading.

Am i doing something wrong? if yes then il try doing the calculation. that was getting very complicated and esp for the humidity sensor the formula has many decimal values in it so i thought of this.
Amit Radha
Mar 30 2008, 8:17 PM
Regarding the Port 0 quiery i had

Is this how i must use pull up resistors to all the pins of port 0?
I have already soldered my LCD so will have to improvise and insert the resistors!
Since i am using a 2A transformer should i use a higher value of resistance?
Ajay
Mar 31 2008, 1:56 AM
you can use 10K of resistance for pullups..
use a resistor pack which is far easy to solder on board.
pdi33
Mar 31 2008, 2:05 AM
ur logic is fine amit, so go ahead . i was confused about the ASCII_RESULT part as it is only one byte long so it can take ASCII value of only one digit.
Amit Radha
Mar 31 2008, 10:04 AM
Hmmm thanks alot, il incorporate all the changes into the code and the hardware.
Am facing a peculiar problem regarding the power supply. I am unable to make a common groung from the 7805 & 7905. When i tried the 1000uF cap swole up and the rectifier heated up. So i changed the cap and inverted it (as i had made that mistake) now it is exactly same as the dual power suppy in the datasheet but that still doesnt allow me to have a common ground as shown in that. The rectifier still heats up when i short the 2 grounds.
Does anyone have a tested circuit for +-5V?

Pls post it here. It will be a huge help. I dunnot want to buy a ready supply, even though i have spent ~150 bucks already on it and it is still not working!
Amit Radha
Mar 31 2008, 10:14 AM
Regarding prgramming the uC, i couldnt do it today! The programmer refused to be detected vy 3systems in my lab! So we assumed it was faulty but my groupmate says that it was detected at home so il try it again tomorrow.
And yes, il start as pdi33 mentioned, first the LCD, then ADC then the actuators.

Had another doubt, do i need to use any unity buffers b/w the ADC & the uC or b/w the LCD & uC? I certainly will need them when i connect the uC to relays right?
Yeah and one more thing, the current limiting resistor to the LCD should be 10ohms or 100ohms? or higher?

And Ajay, what is a resistor pack?
pdi33
Mar 31 2008, 1:11 PM
a Resistor pack is an array of resistors with one end of all resistors connected to a common point. See if you can find a 4.7k , 8+1 resistor SIP. the common point should be connected to VCC and the eight other resistor ends to the port.
u need not use any buffers between the LCD and port pins nor between the ADC and uC.
ur last doubt about the 10ohms resistor, that should be connected in series with the LCD backlight only. Actually the voltage required by the LED is about 4V and current specified is 80mA. So the 10 ohms resistor. If u use 100 ohms, the current sourced will reduce to about 10mA and the LED will light dimly.
About the power supply just send me the power supply circuit and maybe i can help u. Are u using a centre tapped txformer for +5 and -5V generation?
pdi33
Mar 31 2008, 1:13 PM
note that the heat sinking fin of the 7905 is not internally connected to gnd like the 7805. check whether it is accidentally connected to ground.
Amit Radha
Mar 31 2008, 1:20 PM
Hey thanks a lot for clearing those doubts.
Regarding the power supply, I am using the center tap (ie 0-6)of a 6-0-6 transformer. I shall be changing it to 0-9. (The person who had been assigned to buy it brought a 0-6v 2A!!! a waste so gotta have it exchanged now!)
I have not used a heat sink to the 7905 as it has a full plastic package,for the 7805 i have used a heat sink (but not grounded it).
I checked xome ckts online and saw that they use 2 bridge rectifiers. 1 each for the +ve regulator and the -ve regulators. but i sourced both from one.
Could that be the problem?
the_simple_mans_spectrum_analyser.zip
supply.zip
pdi33
Mar 31 2008, 8:20 PM
if u r using a centre-tapped txformer then the ciruit in supply.pdf wont wrk buddy. For that ckt u have to use two seperate windings.do this:
connect one bridge rectifier to the extreme ends of the centre-tapped winding. Now if u short all the grounds of our ps ckt to the centre tap, the + output of the bridge will give u an unregulated +ve supply w.r.t ground(or centre tap) , and the - point of ur bridge will give u the -ve unregulated supply which can be connected to the 7905. Don't worry, both outputs will have a full wave rectification. .
pdi33
Mar 31 2008, 8:45 PM
o.k. u do not worry about the supply part buddy. just modify ur ckt according to this ckt attached.
power_supply.pdf
pdi33
Mar 31 2008, 8:47 PM
sorry wrong attachment. check this file
power_supply.pdf
Chiru
Mar 31 2008, 9:44 PM
Hi Amit, don't get yourself confused follow the circuit given by pdi33. Take care with the pin config of 7905 it is not same as 7805. 7905 wont require a heatsink in your circuit Go ahead.
Chiru
Mar 31 2008, 9:48 PM
Amit, try and implement some part of the adc code supplied by pdi
pdi33
Apr 1 2008, 3:34 AM
cool down amit. take arest when things don't work out as expected. play some games in the arcade section. thee are some real cool games out there and importantly they do not takeeons to complete. .that will refresh your mind and u will see and rectify ur mistakes.
Amit Radha
Apr 1 2008, 8:13 AM
Hi Chiru and Pdi33,
Thanks for being so supportive Frankly the whole thing is getting onto my nerves! Nothing seems to be working right and the submission date is nearing!!!

My brand new programmer is behaving funny. In the lab PCs it says h/w detect time out but at home, the programmer without the uC gives the following msg:
Detecting Hardware...
Device Programmer for 89 Series 4.4 SS
Detecting Chip...
Device Detect Timeout

And with the uC in it it gives the flg msg:
Detecting Hardware...
Hardware Detect Timeout

HAve to figure this out with the dealer now

Regarding the power supply, I am doing a similar ckt (my 7905 pins are correct, burnt 2 and learnt the hard way ) except that i am using the 6-0 lines and not the 6-6 lines to the bridge rectifier.
My concern regaring ur ckt is that if i connect the 6-6 terminals, i will be giving more than 12V rectified o/p to the 7805 & 7905! Wont that cause considerable heating up? esp considering the fact that the 7905 is plastic package and has no heatsink!!!
But il surely try out this ckt u have mentioned, doesnt require much changes to wat i have done...
Besides this, I have laid my hands on a 9V adapter (of a busted Panasonic cordless phone)
Can i use it to source my 2 regulators and still get a common ground.

I cant believe i am doing all this exercise just to provide -5V to an opamp! if i could do away with it, this whole problem could have been solved, but without the opamp, my LM35 resolution through the ADC is 2degrees only and with opamp its 0.5degrees so i really need the opamp.

Also had another doubt, how can i make degree symbol in the LCD?

Oh and i almost forgot, for the +&-LED of the LCD, i need to connect a 10ohm each? or a 10ohm between those 2 terminals? (I am hoping it is fig a in the image i have uploaded).

Phew, i have more questions and no answers!!!
Waiting eagerly for ur help
pdi33
Apr 1 2008, 8:49 AM
fig. (a) is good and only one 10E is required.
regarding the power supply query, dear amit, only half of the voltage i.e. voltage from center tap to one end, is rectified and applied to the 7805 or 7905 so do not worry. secondly, regarding the heating up of 7905, u have to understand that the heat generated in the regulator is the power dissipated by it which depends on both the voltage drop across it and the current flowing thru it.Now ur -5V supply will not be sourcing more than 20~30mA and even if the input to 7905 is 20V i.e. if dropout voltage across the 7905 is (20-5) i.e. 15V, then the power dissipated in the regulator is only (15V x 20mA) = 0.3Watts which will only make it warm.
secondly U CANNOT use a single winding for both +ve and -ve voltage generation
especially if u want a full wave rectification. It is only possible by half wave rectification which is not recommended.
Also if u still are thinking of procuring a transformer, then finalise all the hardware u are going to use my concern is about the relays u will be using for control as the relays commercially available operate on +12VDC .
Amit Radha
Apr 1 2008, 9:17 AM
Hey thanks a lot got to learn so much from ur post!
The only silver lining to my daily hurdles is that i am getting to learn something everyday... and bug u guys too...

I understood everything u mentioned except this:

pdi33 wrote ...

secondly U CANNOT use a single winding for both +ve and -ve voltage generation
especially if u want a full wave rectification. It is only possible by half wave rectification which is not recommended.

That means i need a 9-0-0-9 transformer? But for now i can try with the 6-0-6 itself right to get +&-5V?
sashijoseph
Apr 1 2008, 9:32 AM
You can use the 6-0-6 for now.Later get a 9-0-9.
You need only one bridge between the 6-6 points of the transformer.So the output of your bridge is +6v and -6v when referenced to the centre point of the xformer.Thus the centre point is Gnd and you connect the 7805 between bridge +ve and gnd.The 7905 between bridge -ve and the same ground.
Hope it's clear.
Amit Radha
Apr 1 2008, 9:42 AM
Yup its clear now
Thanks a lot... God i am such a noob!
BTW my groupmate came across LM833 opamp which only needs +5 n gnd, no -5 so if the supply ckt doesnt work in the end i think wel switch to that!
Dont feel like giving up though, this supply has troubled me more than anything in this project!
pdi33
Apr 1 2008, 9:42 AM
If u are using the negative supply only to power the op-amp and not in any other resistive circuit, then u can generate -5V from +5V using a voltage converting IC ICL7660.
but it can source only upto 10mA . slight variations in the supply for the op-amps do not influence the output as nowadays op-amps have an excellent PSRR. I have checked it practically believe me!!!!
Amit Radha
Apr 1 2008, 9:48 AM
Hey thats a good idea. incase ur clt doesnt work (which i am sure is very unlikely )then i can try this...or the LM833 also. Well i am only using -5 for the opamp and nothing else in the whole ckt...
BTW wat do u do? hope u dont mind me asking! Such a wide knowledge base! u guys are terrific u must be a moderator on this site too..
pdi33
Apr 1 2008, 9:50 AM
if u want to use a cheap single supply op-amp lm358 and lm324 are good options. I have worked with both of them and they work very reliabally near ground under single supply conditions
Amit Radha
Apr 1 2008, 9:52 AM
oh oki. 324 needs a -ve bias too right? like the uA741
pdi33
Apr 1 2008, 10:03 AM
not necessarily. it can operate on only positive supply buddy. In fact 741 does not operate efficiently on single supply.
Amit Radha
Apr 1 2008, 10:04 AM
And regarding the relay u mentioned that 12V would be needed right? but i thought 5V should suffice. I had done the same for a ckt i did in class 12. (hope i am not wrong need to pull it out of my rubble and check it now i think!)
I wont be controlling any major devices. Just to demonstrate that on crossing the set thhresholds, i can turn on/off any AC device. aThis i plan to simulate by turning on/ off small bulbs, fans etc. U have any suggestions to this?
pdi33
Apr 1 2008, 10:05 AM
If u still have doubts for 324, use 358 which is built for low power consumption, single supply operation (usually for battery operated circuits.
Amit Radha
Apr 1 2008, 10:06 AM
Oh that shows my stupidity in not reading datasheets. I have used the 324 and used +&-5V as bias to it just like the 741.
Amit Radha
Apr 1 2008, 10:09 AM
Great, u have given me so many options now. I can try out either f thm! In fact i think i have a 324. il use it in place of the 741 and try eliminating the trouble all together!
pdi33
Apr 1 2008, 10:09 AM
if u plan to just turn on/off bulbs then use LEDs instead of bulbs as they consume higher currents. instead use bright white LEDs. they look more attractive . As for fans, derive the supply for them from the unregulated side of ur power supply or else ur 7805 will unnecessarily overheat as they too consume a lot of current.
pdi33
Apr 1 2008, 10:16 AM
As u have a single winding , why don't u check the digital part first by using only +5V?. After u have succesfully tested ur LCD, check the ADC by giving a variable voltage source to its input and once that is acheived, then go for the analog part using the op-amps. Step by step remember?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007