News:

;) This forum is the property of Proton software developers

Main Menu

Temp Reading Value Interference To Another Port

Started by swsalun, Oct 07, 2021, 10:04 AM

Previous topic - Next topic

swsalun

Hi Member,
I need some advice and solution from you guys.
I have a problem, I wrote a code of temperature, this temperature working is correct and no problem, but the problem is during reading the value will interference to another port reading at MyRPM_1 = ADIn 0, it mean MyRPM_1 display showing seem's like always changing value not fix value, if I remove this temperature connection and make it MyRPM_1 will stable reading.

Below are my code:

;----------------------- Use the Fuse Configurator plug-in to change these settings -------------------------
Device = 16F877A
Declare Xtal = 4
Declare Reminders Off
@ CONFIG_REQ = 0
Asm-
__Config 0x3F7A ;FOSC_XT, WDTE_OFF, PWRTE_ON, BOREN_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, CP_OFF
 Endasm-
Declare Reminders On
'Malika Ibrahim Deraw
;**** End of Fuse Configurator Settings *********************************************************************

' __Config 0x3F7A ;FOSC_XT, WDTE_OFF, PWRTE_ON, BOREN_ON, LVP_ON, CPD_OFF, WRT_OFF, DEBUG_OFF, CP_OFF
 
All_Digital =true

Declare LCD_Type 0                 'Text type
Declare LCD_DTPin PORTD.4          'Assigns data lines to D4-D7
Declare LCD_ENPin PORTD.1          'Enable pin
Declare LCD_RSPin PORTD.0          'RS line pin
Declare LCD_Interface 4            '4 or 8 line interface
Declare LCD_Lines 4                'Lines in the display
Declare Float_Rounding = On
Declare Float_Display_Type = LARGE

Declare Adin_Res = 10             '10-bit result required
Declare Adin_Delay = 50           'Allow 50us sample time
 
ADCON1 = %00000100 

TRISA = %11111111               
TRISB = %11100000               
TRISC = %00000000
TRISD = %00000000
TRISE = %011

'------------------------------------- Prepare Comparator CMCON -----------------------------------------------
CMCON = 7                       'CMCON = 0b00100101; => select mode 7 (101) 
'------------------------------------------------------------------- ------------------------------------------
 
'--------------------------- Variable Addressing --------------------------------------------------------------
Dim

'-------------------------------------Variable For Temeperature------------------------------------------------
Dim ADC_Value   As Word     
Dim Temperatur  As Float   
'-------------------------------------End Temperature-----------------------------------------------------------
 
'------------------------------ Temperature -----------------------------------------------------------
       
  If Temperatur > 100.0 Then       'If Temperature Over Than 100 Celcius
      TmpLed = 1                  'Low LED is ON
    Else                          'Then
       TmpLed = 0                 'Low LED is OFF
    EndIf
   
   Print At 3,12,"T:",Dec2 Temperatur,223,"C"   'Display Value Here
   
   
'--------------------------------------------------End Of Temperature----------------------------------
'-------------------------------------------------
   
    MyRPM_1    = ADIn 0        'Input ADC with the value AN0/RPM1
    DelayUS 10
    MyRPM_2  = ADIn 1          'Input ADC with the value AN1/RPM2
    DelayUS 10
   
    ADC_Value = ADIn 4        'Input ADC with the value AN4/Temperature
    DelayUS 2
   

    MyRPM_1 = (Formula Here)
    MyRPM_2 = (Formula Here)
    Temperatur = ADC_Value*150/19712  'This Value ADC Input   
   

End
   

Here are my ADC Input :
    MyRPM_1    = ADIn 0        'Input ADC with the value AN0/RPM1
    DelayUS 10
    MyRPM_2  = ADIn 1          'Input ADC with the value AN1/RPM2
    DelayUS 10
   
    ADC_Value = ADIn 4        'Input ADC with the value AN4/Temperature
    DelayUS 10

    ADDED PIN 5 (RA3/AN3/VREF+) Connected to 5VDC
    ADDED PIN 2 (RA0/AN0) as MyRPM_1 or ADIn 0
    ADDED PIN 3 (RA1/AN1) as MyRPM_2 or ADIn 1
    ADDED PIN 7 (RA5/AN4) as ADC_Value or ADIn 4 / Temperature
    PIN 4 (RA2/AN2/VREF) Connected to Ground

My question is, with above connection and configuration, why my Temperature reading make an interference to ADIn 0 PORT, what is wrong ?, please help me and provide me a solution.

Just note: Don't added PIN 36 (RB3/PGM) to connect to your RS or EN (LCD PIN) or DATA PIN, (You Can't Appears Any Text There)


Thanks.


 
   

John Lawton

Pay attention to the section in the datasheet about acquisition time (page 130).
https://www.microchip.com/content/dam/mchp/documents/MCU08/ProductDocuments/DataSheets/39582C.pdf
Check that you are running the ADC at the right clock speed and allowing enough delay when switching ADC channels.

I'm not sure how the ADin command works, but it is good practice to poll for the GO/DONE bit to be cleared (see page 129) before taking the reading.

John

Pepe

must put ADC_Value = ADIn 3 for ADCON1 = %00000100

if you wish ADC_Value = ADIn 4 must put ADCON1 = %00000010

swsalun

Quote from: John Lawton on Oct 07, 2021, 11:25 AMPay attention to the section in the datasheet about acquisition time (page 130).
https://www.microchip.com/content/dam/mchp/documents/MCU08/ProductDocuments/DataSheets/39582C.pdf
Check that you are running the ADC at the right clock speed and allowing enough delay when switching ADC channels.

I'm not sure how the ADin command works, but it is good practice to poll for the GO/DONE bit to be cleared (see page 129) before taking the reading.

John
Hi John,
Thank you for a suggestion.
I added this ADCON0 = 0b00000001   ' //Turn ON ADC and Clock Selection
ADRESH = 0           
ADRESL = 0
but still doesn't changes.
Can you please give me some sample here, I try to add to my code and test it.

Thanks.
Salun.

swsalun

Quote from: Pepe on Oct 07, 2021, 02:11 PMmust put ADC_Value = ADIn 3 for ADCON1 = %00000100

if you wish ADC_Value = ADIn 4 must put ADCON1 = %00000010
Hi Pepe,
Thanks for advice, I did it already before, but nothing changes.

Thanks.
Salun.

Stephen Moss

Quote from: swsalun on Oct 07, 2021, 10:04 AMHere are my ADC Input :
    MyRPM_1    = ADIn 0        'Input ADC with the value AN0/RPM1
    DelayUS 10
    MyRPM_2  = ADIn 1          'Input ADC with the value AN1/RPM2
    DelayUS 10
   
    ADC_Value = ADIn 4        'Input ADC with the value AN4/Temperature
    DelayUS 10

You need to look at your ADCON1 setting, you only show it as %00000100 which is AN4-AN7 & AN2 = Digital I/O and AN0, AN1 & An3 = Analogue Input. Therefore your result for reading AN4 would always be either 1024 or 0 as it is set to digital I/O.
If you are wanting to read an I/O pin as Analogue sometimes and digital other times then you would need to change the values in this register applicably.
Quote from: swsalun on Oct 07, 2021, 10:04 AMthe problem is during reading the value will interference to another port reading at MyRPM_1 = ADIn 0, it mean MyRPM_1 display showing seem's like always changing value not fix value, if I remove this temperature connection and make it MyRPM_1 will stable reading.
Have you checked the input signal with an oscilloscope to see it if is being affected by the setting of the I/O port when this happens. 

Quote from: John Lawton on Oct 07, 2021, 11:25 AMI'm not sure how the ADin command works, but it is good practice to poll for the GO/DONE bit to be cleared (see page 129) before taking the reading.

I may be wrong but as I recall it selects the ADC Channel and then constantly polls the Go_Done bit until it is cleared, so although the command is useful for beginners I prefer to use the ADC interrupt so that other code can execute during the ADC conversion.