Strange ADC behaviour


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi guys,

    some changes made but still Porta.0 is running the show

    If i change the input on porta.0 it changes my "fixed" reading on porta.1

    What i did :

    Turned on the Vref+ and with a voltage drop through resistors i managed to get 1.6V vref in porta.3 and added this in my code:
    ADCON1 = %10100011

    Also added a pauseus between readings
    pauseus 1000

    placed on LCD the original adc reading followed by the math result
    lcdout $fe,2, dec tes1, " PA1 ", dec volt, " "
    lcdout $fe,$c0,dec te0," PA0 ", dec temp, " "

    Acetronics,

    you said that you re-wrote my code and it worked...

    One question:

    Have you made any changes ?

    I dont know where to turn now

    .

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by ruijc View Post

    Acetronics,

    you said that you re-wrote my code and it worked...

    One question:

    Have you made any changes ?

    .
    Hi, Ruijc

    I did not make any noticeable change to your " functionnal " program ( = the part that runs )

    BUT ... as I told you, The config section took me ~ 50 lines.

    Here is your headache : The processor config lines !!!

    Code:
    '*****************************************************************************
    '*****************************************************************************
    '09/12/2007
    '
    'Lecture de 2 temp avec LM35 ( ambiant  temp ... LOL ! )
    '
    'PIC 16F88 @ 4Mhz
    
    '*****************************************************************************
    'Config
    
    @	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_ON & _INTRC_IO
    
    @ 	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    
    OSCCON 	= %01101110 'Internal RC w/ I/Os
    
    INTCON	= 0
    PIE1	= 0
    PIE2	= 0
    CMCON	= 7
    CVRCON 	= 0
    
            
    '*****************************************************************************
    'DEFINEs
    '*****************************************************************************
    
    'OSC
    
    DEFINE osc 4
    
    '*****************************************************************************
    '
    'ADC
    
    DEFINE ADC_BITS 10 ' Set number of bits in result ( 8 or 10 bits )
    
    'DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    
    '*****************************************************************************
    '
    'LCD 
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS 4
    
    DEFINE LCD_COMMANDUS 2000
    
    '*****************************************************************************
    'ADC parameters
    
    ADCON0	= %11000000 ' clock source
    ADCON1 	= %10000011 ' set porta.0 and .1 analog and right justify result
    ANSEL 	= %00000011 ' Porta.0 and  .1 used by ADC
    
    '*****************************************************************************
    ' variables
    
    va1 	var word
    va2 	var word
    temp 	var word
    volt 	var word
    
    LM351 	con 0
    LM352	con 1
    
    CLEAR
    
    '*****************************************************************************
    'I/O's
    
    PORTA = %00000000
    PORTB = %00000000
    
    TRISA = %00000011
    TRISB = %00000000
    
    '*****************************************************************************
    'PINS
    
    LM35_1	var PORTA.0 
    LM35_2	var PORTA.1 
    a2		var PORTA.2 
    a3		var PORTA.3 
    a4		var PORTA.4 
    MCLR	var PORTA.5 
    a6		var PORTA.6 
    a7		var PORTA.7 
    
    DATA1	var PORTB.0
    DATA2	var PORTB.1
    DATA3	var PORTB.2
    DATA4	var PORTB.3
    
    R_S		var PORTB.4
    E		var PORTB.5
    b6		var PORTB.6
    LED		var PORTB.7
    
    
    '*****************************************************************************
    '*****************************************************************************
    '
    '*****************************************************************************
    'Init LCD
    
    pause 500 'init LCD
    lcdout $fe,1 'clear LCD
    
    
    loop:
    
    ADCIN LM351, va1 ' 15 °C ... 150 /5000*1024 = 30.72 ... 30 = NOT GOOD !!!
    ADCIN LM352, va2
    
    'temp = (va1 */ 500 ) >> 2
    temp = (va1*125)
    temp = temp.Highbyte
    
    'volt = (va2 */500) >> 2
    volt = (va2*125)
    volt = volt.Highbyte
    
    high portb.7
    
    lcdout $fe,2,"VOLTAGE..",dec (volt/100),".",dec2 volt,"V"
    lcdout $fe,$c0,"TEMP.....",dec (temp/100),".",dec2 volt,"V"
    
    pause 250 
    
    Goto loop
    
    End
    as you can see it ....no great change to what you did ...


    IT IS FORBIDDEN TO YOU TO PASTE THAT CODE ... before having understood YOU MUST CONFIGURE the registers and ports by YOURSELF !!!

    PbP cares for some ... yes, but only some "general use" ones.

    Also try to show a "readable" listing where you ( mostly ! ) and others can find if you've programmed the "good" registers or not ...

    And for the end ... remember to separate the "config zone" and the "working zone" ... setting registers in the "working zone" must be kept ONLY if changes have to be made while running ...


    Here we are ... PbP doesn't do everything for you ...that's it

    Especially read those F...manual and Datasheet !!!


    Keep on ... thinking you're good at pics ... you'll become really good one day !!!

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

Similar Threads

  1. Strange Behaviour - Simple code+DT_INT+16F676
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th February 2010, 18:53
  2. Strange behaviour of my PBP code.
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th August 2009, 20:20
  3. Strange Serout Behaviour
    By bluesmoke in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2009, 04:12
  4. Strange behaviour from PIC16F877 on TMR0
    By mikebar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th August 2006, 01:31
  5. strange int behaviour
    By tom in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2005, 15:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts