Page 1 of 1

ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 9:27 am
by fotios
Forgive me if this topic has been resolved already. Please don't get me like arrogant, i am novice in FlowCode and i know few things about. This is a sample code for which helped me medelec so the half of idea belongs to medelec. Normally, i had to post this code in other topic in which medelec asked me for the method that i use but this topic has an unfit title "Problem....etc" thus i decided to open a new topic because this code it is a solution.
The code example, permits to we convert the ADC input reading as integer from 0 to 1024, to a number in the scale of 0 to 100%. There is a routine as well, which prevents the indication on the LCD from flicker. Because my ignorance of how to use C code, i selected the easy way of using the EEPROM for asistance in the relativelly simple calculations. I tried the code not only in simulation mode, but as well in practice by programming a P16F887. It works just fine.
Thank you medelec.
Fotios

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 10:56 am
by wayne millard
This should fix the proplem.
zero was not display on power on fix that.
the flicker is fixed by puting a large delay after writing to display this will keep display on
of longer before clearing the display.

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 2:22 pm
by medelec35
Hello fotios.
No one would think you are arrogant. If you have tried something and does not work the way you have intended, then we welcome posts about it.
Any way I have corrected minor errors. I am assuming you have not tried the version you posted on real hardware since you have also left out LCD Display start macro. That is vital for LCD initialization on hardware, not needed on simulation only.
Any way, I have tried this on real hardware and there is no flickering at all. You also need to remember that LCD refresh on simulation is much slower than on real hardware. So if you see flickering on simulation, that does not necessary mean you will see flickering on your hardware, due to persistence of vision.

Hope this is what you are after.

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 6:13 pm
by fotios
@ wayne millard
Thanks Wayne for the suggestion. I am not sure that i have understood why the second "calculation" box in the main routine where all variables are zeroed, but... i will try it in actual hardware. Maybe i am missing something that i haven't noticed yet. Please see in my next post (to medelec) some further explanations.
Greetings
Fotios

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 8:24 pm
by fotios
@ medelec
Thanks medelec for your attention and the assistance in my effort. Yes, you are right, i haven't tried this sample code on real hardware. I forgot to refer that it is only a partial code which i developed thru "copy and paste" from the real code of my project. You may know, that i decided from the begining to not use the ICD of FlowCode. Instead this, i made first the actual hardware setup around the EB006, and when a part of the code of project is completed, after a simulation, i compile the code in the actual P16F887 and i try in real mode. If there are errors, i correct those in Flowchart and then recompile the actual PIC. So, when i said that the code is working properly in real mode that was true. In the main routine of my real code there is the command "Start LCD" of course. BTW, you are very observing!
If you remember from my previous posts, i refer that the code which i develop is to control a Hi-Fi Preamplifier. For this, i was based on the ready project of Matrix, a "Simple Hi-Fi". This project, presents flickering of number either in simulation or in real mode. Up to now, i have abolished the TMR0 interrupt which used to update the volume indication. Instead this, i have included in the main loop the "Call macro ADC_READING". I have two interrupts already, the PortB IOC and the PortB0 for the IR receiver
As for your corrections, i have to admit that you resolved a minor problem that i noticed during the real mode execution. Although i haven't flickering, when i turn the potentiometer (1KΩ lin) by hand, there are mid places of pot. where the indication flickers from e.g. 47 to 48 continuously. Obviously, during the ADC convertion and the calculations the equation of difference that i use (VOL_DIFF = VOLUME - VOLUME_SCAN) may result in a non integer number (i.e. fractional like 47.5). Thus the expresion that i use in the decision "If VOL_DIFF = 0" it is changeable - or very sensitive - in these negligible variations of potentiometer. Moreover the potentiometer is a passive part with analog output, thus be it so has not touched, a litle dirt on its wipper can change a little the voltage which is injected in the ADC input of MCU. Thus, i suppose that in such a case the resulted number it confuses the MPU of LCD which can't decide definitelly to write a number either 47 or 48 on the display.
Instead, the expression that you use in the decision "If (VOL_DIFF>0) OR (VOL_DIFF<0)" it takes into account only integer numbers thus slight variations of pot. are rejected. Nice mathematical trick! I did the modification in the concrette decision of my code, and the problem resolved.
I would like to upload the code (better what i made up to now) but is incomplette. I have 2 days of work to finish it, and after this i will upload the whole *fcf project.
Thanks again medelec and have a nice weekend.
Fotios

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 8:25 pm
by Dutchie_World_Wide
Hello Fotios,

My upload is pretty much the same as the one from Wayne Millard.
Accept that I change the positions of the VOLUME_SCAN you write to the display, if the VOLUME_SCAN gets smaller then 100 or smaller then 10.
This way if the number gets smaller then 100 or 10, the number written to the display, stays next to the % sign.

Dutchie_World_Wide

Re: ADC input reading on LCD without flicker

Posted: Sat Jul 31, 2010 9:19 pm
by fotios
@Dutchie
Hello Dutchie and thanks a lot for your interesting.
Wow! Very nice the trick with the sequential decision branches. Yes, the Volume number appearance is more elegant with your way than mine. It is exactly as it should be for the view in which we are used, i.e. the tenth and hundred digits of a number when it goes increased must be added from right to left and when it goes decreased the digits must be subtracted from left to right. The unit digit should be stay beside the % allways. Thanks for the trick. I will apply it in my code imediatelly!
Greetings from Greece, and have a nice weekend
Fotios