ESR-Meter – Update

I got the code working. Apparently there is a bug in picbasic that gives problem with the AD on a 16F690. Therefore I made my own code to get the analogue value.

The code:

  Device 16F690
 Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_OFF, MCLRE_OFF
 XTAL = 8
 OSCCON = %01110111

 Dim spanning As Word
 Dim esr As Float
 
 Declare LCD_DTPIN PORTC.4
 Declare LCD_ENPIN PORTC.3
 Declare LCD_RSPIN PORTB.6
 Declare LCD_LINES 2 

 TRISA.2 = 1 
 ADCON0 = %10000001
 ANSEL = %00000100 
 ANSELH = %00000000
 
 ADIN_RES = 10 
 ADIN_TAD = FRC 
 ADIN_STIME = 500 

 Symbol lcdTijd = 600
 Clear
 Cls
 Print At 1, 1, "ElektronicaStynu"
 Print At 2, 1, " ESR-Meter V1.2 "
 DelayMS lcdTijd
 Print At 1, 1, "lektronicaStynus"
 DelayMS lcdTijd
 Print At 1, 1, "ektronicaStynus."
 DelayMS lcdTijd
 Print At 1, 1, "ktronicaStynus.b"
 DelayMS lcdTijd
 Print At 1, 1, "tronicaStynus.be"
 DelayMS lcdTijd
 
 Cls
 Print At 1, 1, " ESR-Meter V1.2 " 
 Print At 2, 1, " ESR = , "
 Print At 2, 16, $FE,$40,$00,$0E,$11,$11,$11,$0A,$1B,$00



While 1 = 1 
 GoSub AD_in
 spanning = spanning - 480
 esr = spanning / 19
 If esr > 27 Then
 Print At 2, 9, "Open "
 Else 
 Print At 2, 9, DEC2 esr , " "
 EndIf
 DelayMS 550 


Wend
AD_in:
 ADCON0 = %10001001 
 DelayMS 510
 ADCON0.1 = 1 
 While ADCON0.1 = 1 : Wend
 spanning = 0
 spanning.HighByte = ADRESH
 spanning.LowByte = ADRESL


Return
End

The hex file

Leave a Reply

Your e-mail address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.