Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
    i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

    i wrote this program , bit it do not display the right inotmation:


    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7
    ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
    ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %00010001 ' Configure and turn on A/D Module

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    input1 var word : input2 var word

    TRISA = %11111111 ' Set PORTA to all input

    Pause 500

    loop: ADCIN portA.2, input1
    ADCIN portA.3, input2

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value1: ", DEC input1 ' Display the decimal value
    lcdout $FE,$C0, "Value2: ", dec input2
    Pause 200

    Goto loop
    End

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
    i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

    i wrote this program , bit it do not display the right inotmation:


    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7
    ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
    ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %00010001 ' Configure and turn on A/D Module

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    input1 var word : input2 var word

    TRISA = %11111111 ' Set PORTA to all input

    Pause 500

    loop: ADCIN portA.2, input1
    ADCIN portA.3, input2

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value1: ", DEC input1 ' Display the decimal value
    lcdout $FE,$C0, "Value2: ", dec input2
    Pause 200

    Goto loop
    End
    What did it display? How are you hooked up?

    The thing I had in mind is keeping Vref+ and Vref- on Vdd and Vss (battery power). One A/D input is connected to the diode, .7v, which should always stay the same (give or take a bit depending on temperature). The output number from the A/D will be a ratio of that diode (.7v) to the battery voltage., the lower the number, the higher the battery voltage.

    For example, if the battery voltage was actually .7v (just for arguments sake, I know it would never be that low), and the diode voltage was .7v, the A/D output would be 1023.
    If the battery voltage was 4.8v and the diode was .7, .7 divided by 4.8 multiplied by 1024 (full scale A/D reading) would be 149 (149.3). So, 149 would be full charge.
    Taking that same train of thought, if the battery voltage was 3.6v (.9v/cell, battery dead), .7 divided by 3.6 multplied 1024 would be 199 (199.1) which would mean dead battery.

    Are ya following me here?

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

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