Need advice on A/D


Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15

    Default Need advice on A/D

    Hello,

    I am currently working on a project that consists of a Seconds Counter, 2 A/D inputs(1 for Temperature, 1 for monitoring battery voltage). The idea is to take the data and transmit via morse code. I have it all wired up to an 2x16 LCD display, and a piezo speaker until I can get everything running correctly. Currently using a PIC16F88 to test all of this, in the end I will be using a PIC12F675.

    flow should be as follows
    1)Read A/D
    2)Turn on Tx
    3)Send morsecode in this order: Counter, Temperature, Battery Voltage, and Identification
    4)Turn off for 15sec
    5)Repeat

    My problem is, I am not so sure my A/D is working correctly.. my temperature displayed stays at 77degrees F. the voltage input to the processor is 3.16v Im using an LM335z which is calibrated at 10mv/K..and I know its not 109degree's F. more like 73 F...

    I dont mean to come here and get all the answers, although I would love to get some constructive critizism. Not just about problem previously mentioned, but my coding in general..

    Thanks in advance,
    James



    Code is as follows:

    Code:
    'Define LCD connections
    '
    Define  LCD_DREG        PORTB        'LCD data bits on PORTB   
    Define  LCD_DBIT        0                'PORTB starting address
    Define  LCD_RSREG       PORTB        'LCD RS bit on PORTB
    Define  LCD_RSBIT       5               'LCD RS bit address
    Define  LCD_EREG        PORTB        'LCD E bit on PORTB
    Define  LCD_EBIT        4                'LCD E bit address
    Define  LCD_BITS        4                'LCD in 4-bit mode
    DEFINE  LCD_LINES       2               'LCD has 2 rows
        
    ' Define ADCIN parameters
    '
    Define OSC              8                   'Set oscillator at 8MHz
    Define ADC_BITS         8                 'Set number of bits in result
    Define ADC_CLOCK        3                'Set Clock source (3 = rc)
    DEFINE ADC_SAMPLEUS     50           'Set sampling time in uS
    CMCON = 7                                   'Turn comparators OFF
    
    '------( Variables )------
    '
    tx          var byte                     'Transmitter variable
    adval       var byte                    'A/D input for temperature
    adval2      var byte                    'A/D input for . . . .
    tempF       var byte                   'Result of A/D after temperature conversion
    counter     var byte                    'Time variable
    dit         var byte                       'for morse code "dot"
    dah         var byte                       'for morse code "dash"
    ditpause    var byte                     'for morse code pauses between letters/numbers
    wordpause   var byte                    'Pause between words
    i           var byte                          'Variable for subroutine
    dig1        var byte                        'Variable for subroutine
    dig2        var byte
    
    '------( Registers )------
    '             76543210
        TRISA  = %00000001                 'PortA.0 = input, all else = outputs
        TRISB  = %00000000                 'PortB = outputs
        OSCCON = %01110000               '
        ADCON0 = %01000001               'Make AN0 analog inputs, 
        ADCON1 = %00000000               'Format selection/divide clock                              
                                                     'Reference voltage = VDD
        ANSEL  = %00001001                'Sets all A/D off, except RA0 &
    
    '------( Initialization )------
    '
        
        dit       = 4                         'Length of dot in morse code(Lower number is Faster)
        dah       = dit * 3                 'Length of dash in morse code
        ditpause  = dit * 12              'Length of pause between dits & dahs in morse code
        wordpause = ditpause * 5      'Pause between letters/numbers
        counter   = 0                       'Clear time to 0
        Pause 18                             'Wait for LCD to initialize
        LCDOUT $FE, 2, "Loading..."     
    
    '------( Main Code )------
    '    
    Loop:    
        
        pause 1000
        tx = 1
    'PORTA.3 = 1  ' Tx ON
        counter = counter + 1            'Increment time
        
        ADCIN 0, adval                      'Read channel 0 - Temperature
        pause 20
        adcin 3, adval2                      'Read channel 3 - Battery Voltage
        tempf = adval / 10                 '
        Tempf = tempf - 273              '** Conversion from 10mV/K to Fahrenheit**
        TempF = Tempf * 9                '
        tempf = tempf / 5                  '
        tempf = tempf + 32                '      
        
        LCDout $FE, 1
        LCDOUT $FE, 2,$14,$14,$14,$14,$14,$14,$14,$14,$14, "A=", #adval2
        LCDOUT $FE, 2, "Cnt=", #counter                             
        Lcdout $FE, $C0, "F=", #tempf,$14,$14,$14,"ID:N3PX"
    
    '------( Subroutine )------                           
    '
    for i = 2 to 0  step -1              '
        dig1 = counter dig i             'Subroutine to send out :Time
        gosub outdigit                    '
    next i                               
         
    pause 1000                           'Pause before sending next reading
    
    for i = 2 to 0 step -1               '
        dig1 = tempf dig i               'Subroutine to send out :Temperature 
        gosub outdigit                    '
    next i                              
              
    pause 1000                           'Pause before sending next reading
    
    for i = 2 to 0 step -1               '
        dig1 = adval2 dig i              'Subroutine to send out :Battery Monitor
        gosub outdigit                    '
    next i                               
    
    Pause 1000                           'Pause before sending Callsign
    
        gosub a                           '
        gosub num3                     'Subroutine to send out :Callsign
        gosub b                           '
        gosub c                           '
    
      tx = 0           
    'PORTA.3 = 0 'Tx off
       
    Pause 2000                      'Pause before recycling        
    
    goto loop
    
    outdigit:
    
    
    Branchl dig1, [num0,num1,num2,num3,num4,num5,num6,num7,num8,num9]
    Last edited by james; - 15th August 2007 at 17:13.

Similar Threads

  1. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 02:16
  2. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  3. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. 18F2525 A/D, Comparator and Vref modules
    By fbraun in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th May 2005, 23:17

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