****** ARITHMETIQUE FILTER for up to 8 analog input ********************
unsigned int Table[8];
unsigned int Somme_EA[8];
unisgned int M, EA0,Nbval,Somme;
M=0;
EA0=ADC_Read(M);
Table_EA[M][Nbval & 0x0007]=EA0;
Nbval++;
Somme_EA[M]=0;
for (i=0;i<8;i++)
{
Somme_EA[M]= Somme_EA[M] + Table_EA[M][i];
}
f1=(float)Somme_EA[M] * 0.0061035; // // soit 500.0 / (8 x 1024.0); // LM35DZ 10mV/V
*/
*************** EXPONENTIAL FILTER ********************
unsigned int M;
char *txt;
char Texte[64];
float TF,Kfilter,TNow,TOld;
int FirstPass=0;
void Float2Ascii (float x, unsigned char *str,char precision)
void main()
{
txt=&Texte[0];
UART1_Init(19200);
FirstPass=0; // to init the exponential filter
Kfilter=0.2; // value of filter must be >0.0 and <1.0
while(1)
{
.......
M= ADC_Read(0);
TNow=(float)M * 0.0048;
if (FirstPass==0)
{
TOld=TNow;
TF=TOld;
FirstPass=1;
}
else
{
TF= ( TNow * Kfilter) + (1-Kfilter)*TOld;
TOld=TF;
}
Float2Ascii (TF, txt,2);
UART1_Write_Text(txt); UART1_Write(TAB);
UART1_Write_CText(" Volts");
CRLF();
....
} // while 1
Main call DispRoutine
call ad_portc
movf ADRESH,W ;Write A/D result to W
call ADCtable
call BinBCD
call Main
;****************************************************************
;* Delay 10mS 10 x 1,000uS *
;****************************************************************
D_10mS movlw 0Ah
movwf temp2
D_a nop
decfsz temp1,1
goto D_a
decfsz temp2,1
goto D_a
retlw 00
;****************************************************************
;* Bin2BCD Converter *
;****************************************************************
BinBCD clrf MSD ;Tens
movwf LSD ;Units
gtenth movlw .10
subwf LSD,W
BTFSS STATUS,C
goto over
movwf LSD
incf MSD, F
goto gtenth
over retlw 0
DispRoutine
movlw b'00000001' ;Activate Right Display
movwf portE
;movf units,0
movf LSD,0
call table
movwf portD
call D_10mS
;clrf portB
movlw b'00000010' ;Activate Left Display
movwf portE
;;movf tens,0
movf MSD,0
call table
movwf portD
call D_10mS
retlw 0x00
ad_portc
;wait for acquision time (20uS)
;(non-critical for this test)
bsf ADCON0,GO ;Start A/D conversion
Wait
btfsc ADCON0,GO ;Wait for conversion to complete
goto Wait
;movf ADRESH,W ;Write A/D result to W
return
table addwf PCL,F ;02h,1 add W to program counter
retlw b'00111111' ; "0" -|F|E|D|C|B|A
retlw b'00000110' ; "1" -|-|-|-|C|B|-
retlw b'01011011' ; "2" G|-|E|D|-|B|A
retlw b'01001111' ; "3" G|-|-|D|C|B|A
retlw b'01100110' ; "4" G|F|-|-|C|B|-
retlw b'01101101' ; "5" G|F|-|D|C|-|A
retlw b'01111101' ; "6" G|F|E|D|C|-|A
retlw b'00000111' ; "7" -|-|-|-|C|B|A
retlw b'01111111' ; "8" G|F|E|D|C|B|A
retlw b'01101111' ; "9" G|F|-|D|C|B|A
retlw b'01110011' ; "P"
retlw b'01101101' ; "S"
ADCtable addwf PCL,F ;02h,1 add W to program counter
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00 ;10
retlw 0x00
retlw 0x01
retlw 0x01
retlw 0x02
retlw 0x02
retlw 0x03
retlw 0x03
retlw 0x04
retlw 0x04
retlw 0x05 ;20
retlw 0x05
retlw 0x06
retlw 0x06
retlw 0x07
retlw 0x07
retlw 0x08
retlw 0x08
retlw 0x09
retlw 0x09
retlw 0x0A ;30
retlw 0x0A
retlw 0x0B
retlw 0x0B
retlw 0x0C
retlw 0x0C
retlw 0x0D
retlw 0x0D
retlw 0x0E
retlw 0x0E
retlw 0x0F ;40
retlw 0x0F
retlw 0x10
retlw 0x10
retlw 0x11
retlw 0x11
retlw 0x12
retlw 0x12
retlw 0x13
retlw 0x13
retlw 0x14 ;50
retlw 0x14
retlw 0x15
retlw 0x15
retlw 0x16
retlw 0x16
retlw 0x17
retlw 0x17
retlw 0x18
retlw 0x18
retlw 0x19 ;60
retlw 0x19
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00 ;70
Where do you take care of this? It seems you update the display about 30 times per second..* Update display only once per second.
Hi,
Where do you take care of this? It seems you update the display about 30 times per second..
Klaus
WHAT kind of problem?i couldnt find where to make a delay without make a problem
Main call DispRoutine
call ad_portc
movf ADRESH,W ;Write A/D result to W
call ADCtable
call BinBCD
[COLOR="#FF0000"]call[/COLOR] Main
Hi,
Your ADC-table is:
Code:If W < 0x10 --> retlw 0 If W >= 61 --> retlw 0 W = W -10 shift W one bit right. ret
Klaus
on a PIC you can never run two routines the same time. Only one after the other.can i run 2 routines same time ?
I have no preference.do u suggest to learn the basic language or keep learning assembly ?
Hi,
I have no preference.
Klaus
John,
You will find Pic Basic Pro to be worth every penny. It will save you hours of coding. On this project and every one to follow.
You will be able to test the value coming from the thermistor several times, and when you get the same value a few times in a row, tell the Micro
to change the LED display to the new reading. This is better than just a delay, because the speed of the temperature value will change upon varying conditions.
-Lisa
John,
If you have programmed in Basic before, this will be easy and faster for you to get results than assembly.
I'd start by simply flashing an led on 1 pin of 1 port, and go from there. Try port B pin 1 for simplicity. No need to worry about the open collector output.
On Pin 1 Port A. Use a high output LED and you will get decent brightness without drawing too much current
from the Micro pin. Be to use a 470 Ohm resistor (Approx) to limit current.
Things should go much easier with Pic Basic Pro.
Good Luck!
-Lisa
' Configure pins for digital operation (uncomment as needed).
' These settings are intended as simple examples. For more detail,
' see the appropriate device datasheet for register descriptions.
'ANSEL = %00000000 ' 16F88, 16F688, 16F690, 16F88x
'ANSELH = %00000000 ' 16F690, 16F88x
ADCON1 = %00000111 ' 16F87x, 16F87xA, 18F452
'ADCON1 = %00001111 ' 18F4620
LED VAR PORTB.1 ' Assign name "LED" to PORTB.0
mainloop:
High LED ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Low LED ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Goto mainloop ' Go back to loop and blink LED forever
End
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?