16F876 problem... absolutely baffled


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    46

    Default 16F876 problem... absolutely baffled

    I've got the following code shown below. In order for it to work I need to put a pause in of 8 ms or greater or else the serout2 command outputs 0s. In other words, if the pause is set to 10 ms I get good data but if the pause is set to 5 seconds or there is no pause at all, I get 0s. Does this occur because my control pins for the AD converter are accessing different ports? This issue has been baffling me for some time.

    The 16F876 I am using is a surface mount SOIC chip or else I would check it by moving my control lines to different I/O pins.

    I hope somebody can give me some insight.

    Kind Regards,
    Eric

    DEFINE OSC 20 ' define oscillator to be 20Mhz
    ADCON1 = 7
    include "MODEDEFS.bas"

    ' Power connections

    MainPower VAR PORTC.3

    ' Communication connections
    TX VAR PORTA.0

    ' AD converter connections
    sclk VAR PORTC.1 ' SPI clock out from BS2 to AD2543
    sdo VAR PORTC.0 ' SPI data out from BS2 to AD2543 sdi
    sdi VAR PORTA.5 ' SPI data in from AD2543 sdo to BS2
    ADcs VAR PORTA.3 ' AD2543 chip select, active low

    ' *********************** [ CONSTANTS ] ************************
    ' Sensor Constants
    TiltX Con 2

    ' [ VARIABLES ]
    Result VAR WORD
    ADch var Byte

    high MainPower
    Adch = TiltX

    '[ MAIN PROGRAM ]
    Main:
    pause 8
    gosub ReadAD
    serout2 TX, 16468, [dec result, 13]
    goto Main


    ' read the AD converter
    ReadAD: ' entry point to give result as millivolts
    LOW ADcs ' select chip
    SHIFTOUT sdo,sclk,MSBFIRST,[ADch<<8\12]
    SHIFTIN sdi,sclk,MSBPRE,[result\12] ' get result, 12 bits
    HIGH ADcs ' deselect chip
    RETURN

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    When you remove pause 8, do always got 0s as results?

    what about if you use SEROUT instead of SEROUT2?

    Since you have a internal USART why not simply use it??? but i figure everything is already place/set on board now...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2004
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I am using the SEROUT2 for a speedier baud rate. If I remove the PAUSE 8, I get nothing but zeros in the serout2. The ADRead subroutine works great on its own and the SEROUT2 works great on its own; however when the two are combined there is a problem. Still can't figure it out.

  4. #4
    L_Gaminde's Avatar
    L_Gaminde Guest


    Did you find this post helpful? Yes | No

    Default

    Try two things put the pause 8 right before you adc read and second put the pause 8 at the end of your adc read just before return. you could be trying to read the adc too fast.

    Look up the adc chip and check the speed of reading or see if there is a way to do multiple reads and if its different than single reads. also check the state that you are leaving the adc in just before the return command you may need a low there and a high to low just before the shiftin command.

Similar Threads

  1. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  2. 16F876 ADC problem
    By Douwe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th June 2006, 19:38
  3. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  4. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59
  5. Serin2 problem on 16F876
    By jrt4fun in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th May 2004, 17:24

Members who have read this thread : 1

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