Why not just add a condition that only updates the LCD if the ADC value changes by a certain amount from the last reading. That would reduce the updates and also make it less resposive to small changes in voltage.
Why not just add a condition that only updates the LCD if the ADC value changes by a certain amount from the last reading. That would reduce the updates and also make it less resposive to small changes in voltage.
Well, this is just an idea. Take 10 readings, then obtain the average, and display it in the LCD. Something like this,
RobertCode:MAIN: FOR I = 0 TO 9 ....Take ADC reading READING[I] NEXT I 'Next obtain the average AVERAGE = (READING[0] + READING[1] + ......) / 10 LCDOUT $FE, 1, DEC AVERAGE GOTO MAIN
"No one is completely worthless. They can always serve as a bad example."
Anonymous
How do that?
Here is a sample of my loop :
lp:
ADCON0.1=%1
WHILE ADCON0.1=%1:WEND
' Store ADC results
isense.HIGHBYTE=ADRESH
isense.LOWBYTE=ADRESL
' Security fault verifications
IF isense**40000>imax THEN flt=1
' LCD
idisp=isense**40000
lcdout $fe,$c0,$1,$20,"1 ISENS: ",DEC idisp DIG 2,DEC idisp DIG 1,".",DEC idisp DIG 0,"A"
goto lp
Code:lp: ADCON0.1=%1 WHILE ADCON0.1=%1:WEND ' Store ADC results isense.HIGHBYTE=ADRESH isense.LOWBYTE=ADRESL ' Security fault verifications IF isense**40000>imax THEN flt=1 I = I+1 ; insert @top " I var Byte " IF I = 1 THEN ; also can use IF I // 200 = 1 ... and adjust "200" to the desired rate ' LCD idisp=isense**40000 lcdout $fe,$c0,$1,$20,"1 ISENS: ",DEC idisp DIG 2,DEC idisp DIG 1,".",DEC idisp DIG 0,"A" ENDIF goto lp
Last edited by Acetronics2; - 3rd November 2011 at 20:46.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Something like this,
Code:lp: AVERAGE = 0 FOR I = 0 TO 9 ADCON0.1=%1 WHILE ADCON0.1=%1:WEND ' Store ADC results isense.HIGHBYTE=ADRESH isense.LOWBYTE=ADRESL AVERAGE = AVERAGE + isense NEXT I AVERAGE = AVERAGE / 10 ISENSE = AVERAGE ' Security fault verifications IF isense**40000>imax THEN flt=1 ' LCD idisp=isense**40000 lcdout $fe,$c0,$1,$20,"1 ISENS: ",DEC idisp DIG 2,DEC idisp DIG 1,".",DEC idisp DIG 0,"A" goto lp
"No one is completely worthless. They can always serve as a bad example."
Anonymous
A slightly different method:
Updating LCDs is really time consuming, from a PIC viewpoint. I find that a .25(once every 4 seconds) update rate is about right for most people, especially if it a two-line display.
The code below lets your code run at full speed and updates the LCD once every 4 seconds. Of course the rate can be changed to suit the user. It uses an ASM interrupt for low overhead.
Of course, you could read the timer directly, but I find that I always need interrupts anyway.
Code:DEFINE OSC 4 MasterClock VAR WORD BANKA SYSTEM ;----------------Timer Setup----------------------------------- T0CON = 000010 ; /1:8 prescaler, tmr0 ON ; ;------------------------------------------------------------- INCLUDE "DT_INTS-18.bas" ' ;--------------------------------------------------------------- asm INT_LIST macro INT_Handler TMR0_INT, MainTimer, ASM, yes endm INT_CREATE endasm ''----------------- Initialization Done! ----------------------------- Goto OverInt ;----------------------- Timer INt ------------------------------------ ASM MainTimer movlw 0xCF ; 100 mSec @ 4MHz movwf TMR0H movlw 0x2C movwf TMR0L btfsc MasterClock + 1,7 ; Don't let MasterClock roll over bra DontCount infsnz MasterClock incf MasterClock + 1 DontCount bcf INTCON,2 INT_ENABLE TMR0_INT INT_RETURN ENDASM ;--------------------------------------------------------------------- OverInt: INTCON.7 = 1 ; Main Ints INTCON.6 = 1 ; Peripheral ints MasterClock = 0 @ bcf INTCON,2 @ INT_ENABLE TMR0_INT TopOfLoop: If MasterClock >= 20 then ; 20 X .1 sec = 2 seconds MasterClock = 0 ; Do LCD routines here endif ; Your main program here goto TopOfLoop
Last edited by Charles Linquis; - 4th November 2011 at 01:08.
Charles Linquist
There is no @ int_return at the end?
I already use a timer1 DT interrupt, this one will not affect my program?
Last edited by pxidr84; - 4th November 2011 at 10:51.
Note : I use a 40MHz xtal, and my LCD desired refresh rate is about 0.5s.
The ISR is not written in PBP. It is in assembly. The only INT_RETURN you need is at the end of the interrupt service routine - just before the ENDASM.
For 40Mhz -
Lines you need to change
DEFINE OSC 40
T0CON = %10000011 ; Turn timer on, divide by 16 prescaler
movlw 0x0B ; 100 mSec @ 40MHz
movwf TMR0H
movlw 0xDC
movwf TMR0L
If MasterClock >= 5 then ; 5 X .1 sec = .5 seconds
And no, it will not affect anything else you have running.
Charles Linquist
Bookmarks