View previous topic :: View next topic |
Author |
Message |
alireza121
Joined: 09 Dec 2010 Posts: 9
|
Question |
Posted: Wed Jan 05, 2011 8:22 am |
|
|
Hello
I used Hansolo's code for my PIC : 18f452 as follows and I got good result. Please consider my question after that :
http://www.ccsinfo.com/forum/viewtopic.php?t=28564
I have a question :
As you know the output of SHT10 is digital and I want to have it as analog to apply to one of analog input pin of PIC18f452.
How can I convert SHT10 output (digital) to analog ? I found the read_adc() in CCS which is for converting of analog to digital and is not applicable now.
If it is possible, Please send me the code.
Thanks a lot in advance,
Alireza121 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Wed Jan 05, 2011 10:33 am |
|
|
Not without extra hardware.
You could do a 'crude' conversion, by programming the PIC's PWM, to give 0 to 1023, for the temperature range you want, then adding an external integrator to covert this to a voltage. Otherwise, you need to add an external DAC, and use this to output the voltage you require.
Best Wishes |
|
|
alireza121
Joined: 09 Dec 2010 Posts: 9
|
Question |
Posted: Wed Jan 05, 2011 10:45 am |
|
|
Hello Ttelmah
Many thanks for your email.
Would you please clarify more and send me the code?
Thanks again,
Alireza121 |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jan 05, 2011 11:02 am |
|
|
You would need to have a PIC 'talk' to the SHT10 and receive the digital information from it. Then have the PIC drive a DAC that would apply that value to the output of the DAC. I think that's about the most simplest way to do it.
I'm curious though, if you're just going to input it into another PIC why not just input the digital value into your F452 and have it massage the data there? Seems a waste to go from digital->analog->digital because the analog input of your F452 would just convert it to a digital value anyway.
Ronald |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Wed Jan 05, 2011 11:20 am |
|
|
rnielsen wrote: | I'm curious though, if you're just going to input it into another PIC why not just input the digital value into your F452 and have it massage the data there? Seems a waste to go from digital->analog->digital because the analog input of your F452 would just convert it to a digital value anyway.
|
Because this route requires the least thinking/understanding because he can then cut & paste things that others have done. And that's why he asked Ttelmah to do the DAC work for him. |
|
|
alireza121
Joined: 09 Dec 2010 Posts: 9
|
Question |
Posted: Wed Jan 05, 2011 12:04 pm |
|
|
Hello dear friends,
I think there is something wrong.
I review the problem again :
The SHT10 output is digital and at present I connected it to one of digital input of 18f452 and my system (temperature and humidity measuring system) is working properly. Now, I am reading the humidity and temperature on LCD properly.
I don't want to use an analog sensor and want to use just SHT10 from SENSIRION in my project due to its high accuracy.
My question is :
I need to have SHT10 output as analog signal,an analog signal that change its value according to changes in temperature and humidity. Because of output of SHT10 is digital, I should write a program in 18f452 to convert digital output of SHT10 to analog signal and I want to have this value to input of remaining of my program. Because remaining of my program needs analog signal.
I wrote a program in CCS to get analog signal from digital signal of SHT10 for 18f452, but couldn't get result.
Please help me in this regard.
Hope above explanation clarify my problem.
Waiting to your kind replies.
Thanks in advance,
Alireza121 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Wed Jan 05, 2011 1:13 pm |
|
|
Show us your code for reading the SHT10 and converting it to analog.As others have said it's A waster of time to go from digital to analog to digital.... but heck, you're the programmer and only you know why you want to do all this extra work.
PS, everytime you convert, you will lose accuracy in your readings. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jan 05, 2011 1:18 pm |
|
|
Where is this analog signal going? If it is only going into the A/D of another PIC18f452, you would be much better off to send a digital signal between the two processors.
1) Why do you want an analog signal?
2) What sort of accuracy and resolution do you need? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Wed Jan 05, 2011 1:21 pm |
|
|
SherpaDoug wrote: | 1) Why do you want an analog signal? |
That's the assignment he was given at school.
Quote: | 2) What sort of accuracy and resolution do you need? |
I'm betting he doesn't know. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jan 05, 2011 1:30 pm |
|
|
The SHTXX series sensors use an I2C bus for communications, though it's not completely I2C compliant. You need 2 signal lines to communicate with the sensor. There are several posts on the proper way to talk to it. It's impossible to get the SHT10 to give any kind of analog signal out. Do you have the data sheet for it? Read it well.
I would suggest you learn how to talk to the sensor first and how to get the data out of it. If you have code that you have tried, post it.
Ronald |
|
|
alireza121
Joined: 09 Dec 2010 Posts: 9
|
Question |
Posted: Wed Jan 05, 2011 1:51 pm |
|
|
1.I need the analog signal for input of the fuzzy logic.As you know input of fuzzy logic is analog not digital.
2.Accuracy and resolution which is in SHT10 datasheet is enough for my current application:
for relative humidity : +/- 4.5%
for temperature : +/- 0.5 %
Many thanks in advance for your replies. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Wed Jan 05, 2011 2:03 pm |
|
|
Yeesh...they actually TEACH fuzzy logic in school ??? Man I thought it was dead a decade or two ago !
NO, you do NOT need an analog voltage to use 'fuzzy logic'. Think about it, computers (at least ANYTHING made after fuzzy logic was invented, are ALL digital computers.
Whether the computer's internal ADC converts the sensor reading to digital or the peripheral does the conversion is not relevant to HOW fuzzy operates.
As a 'sidebar', I am surprised to find a Fuzzy compiler that will work on any of the new 18 series PICs. |
|
|
alireza121
Joined: 09 Dec 2010 Posts: 9
|
Question |
Posted: Wed Jan 05, 2011 2:38 pm |
|
|
For your information dear friend :
1.Many of systems in the world work with Fuzzy logic, the fuzzy logic hasn't died yet, it is an old controller but useful and efficient. Take a look at your house households, for instance, your washing machine is working on basis of fuzzy logic and also more examples ...
The fuzzy logic has many applications in the world from households appliances to industrial applications, I specially recommend to study more about it.
2.Dear friend : please pay attention in following, since you are in a great mistake :
THE COMPUTERS INVENTED MANY YEARS BEFORE FUZZY LOGIC NOT AFTER THAT, Dr.Zadeh after many researches about answers to questions as fuzzy (not precise) instead of binary answers (Yes or No : precise answers) invented fuzzy logic.
So, we need analog signal (fuzzy) instead of digital signal (binary).
Hope above brief answer clarified the fuzzy logic.
Please study more books and papers in this regard.
3.Not need to special compiler, first you read fuzzy logic fundamentals, after that, start to write the code by CCS compiler.
Cheers, |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jan 05, 2011 3:10 pm |
|
|
The input to a fuzzy logic system is a number. It doesn't matter if that number comes from an A/D converter processing an analog signal, or from a UART processing a digital serial signal. Somehow you need to get the number from the outside world into the processor chip. Within the processor chip, assuming it is a digital chip like a PIC or 99.999% of all the other processors in the world, the number will be stored in digital form. A PIC can not work with an analog signal without immediately converting it to digital form.
If you have a number representing temperature or humidity in a sensor chip which has a digital output, and you need to get the number into a PIC which will use it in digital form, it makes sense to transfer it by digital means. Converting the number to an analog voltage so the PIC can convert it back to digital is complex, error prone, will introduce noise or many sorts, power hungry, and generally a bad idea. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Wed Jan 05, 2011 5:15 pm |
|
|
Working backwards...typical of 'fuzzy'....lol
3) CCS compiler works with DIGITAL computers NOT ANALOG. You seem from the start to have to need to have a pure analog control system...NONE of the PIC computers,with CCS compilers actually work with pure analog variables. They all digitize the data.
2)Please supply the make and model of an ANALOG computer that uses fuzzy. You still imply you can use a digital computer to take analog data and perform a function with it. You miss my point, that NO computer made after fuzzy was invented, works using analog signals left in analog form, the data is digitized (ones and zeros, no maybe bits!)
1) For what it's worth, my washing machine is actually pure DIGITAL. Simple on/off switches for all sensors, tachometers and digital encoders for controls and motor speed, PWM of DC motor drive. Nothing anaolog there. Mind you I did design and build it 15 years ago, and aside from an update from LEDs to an LCD panel, nothing has changed.
BTW if you read the Microchip apnote on fusing fuzzy...it is nothing more than a huge sequence of if....then...else coding..... |
|
|
|