Shop OBEX P1 Docs P2 Docs Learn Events
WRITE versus DATA?? — Parallax Forums

WRITE versus DATA??

agentileagentile Posts: 101
edited 2005-01-11 20:34 in BASIC Stamp
Hello,
· I am working on a data acquisition program.· I am having trouble determining how the WRITE command works.

Summary:
The program reads external data relative to sunlight intensity, places the data into a variable called LIGHT.
The value of LIGHT is then stored into EEPROM.· This is repeated 60 times, once every five minutes.
Selected parts of the code are provided below.·

The problem I have encountered is that if I run the program, and then do a search of the EEPROM memory, there is nothing written in EEPROM spaces 0 to 59.· However, when I use READ to retrieve the data, I get all 60 data without fail.· So, the WRITE command must be working, but why doesn't the data appear in EEPROM memory map?

AG

Code:

Data_Count VAR Byte······· ' counter for number of data collected
Data_Count=0
Index VAR Byte
'
'·························· Main Function
'

Main:
GOSUB init_a2d······························ ' Initialize ADC0804
GOSUB wrt_a2d······························ ' Instruct a2d to send data to pins
GOSUB read_a2d····························· ' Read from a2d data pins
WRITE Data_Count,LIGHT················ ' store value of LIGHT into EEPROM
pause 3000····································· ' pause 5 minutes
Data_Count=Data_Count+1············· ' increment Data_Count
IF Data_Count = 59 THEN download· ' collect·60 data
GOTO Main


download:
FOR Index=0 TO 59
READ Index, LIGHT
DEBUG· DEC LIGHT, CR

Comments

  • achilles03achilles03 Posts: 247
    edited 2005-01-11 19:12
    Write is the command you want to use.· "Data" only writes to the eeprom when you download the program into the stamp.

    In regards to your program, I would check to make sure your code for the ADC is working first... can you post it?

    Also, "pause 3000" pauses for 3 seconds, not 300.

    Also, if you want 60 data points, you should put the IF...THEN command before incrementing the data_count, or just change 59 to 60.

    Lastly, you might just want to upload a program directly that debugs the eeprom memory with the READ command.· Reattaching the BS2 to the computer and trying to debug has never worked for me without closing any current debug windows and redownloading the program.

    Hope that helps,
    Dave
    ·
  • achilles03achilles03 Posts: 247
    edited 2005-01-11 19:14
    Oops, didn't see that last sentence... the memory map only shows data that will be uploaded to the BS2, not data currently in the BS2. Think of memory map as the map of the BS2 when it first starts running.

    Dave
  • agentileagentile Posts: 101
    edited 2005-01-11 19:28
    Dave,

    ·Thanks.· Let me get this straight, the memory map only includes those items which are stored to EEPROM prior to program execution, items such as instructions, and constants.· Because my EEPROM is being written during program execution, the memory map cannot see it, even though it is obviously there.· Is this pretty much what is happening?



    thanks,

    AG
  • achilles03achilles03 Posts: 247
    edited 2005-01-11 19:48
    AG,

    In a nutshell, yes. When you run the memory map, the PBASIC editor is determining what the program would "look like" once it's in the BS2. You don't have to have the BS2 connected to run the memory map either, as it's only dependant on the program.

    Dave
  • agentileagentile Posts: 101
    edited 2005-01-11 20:18
    Dave,

    ·You commented earlier on whether or not my A2D code was working properly.· If you have any experience with the ADC0804, I sure could use some advice.·· As is, the code works, however the output is jittery. I get a consistent 5% swing on my output values for a constant input.· I have tried many things to fix this, and I just don't know what it could be.· I have elimiated the idea that this is due to voltage spiking, because the values are only changing small amounts, and in a consistent pattern.· I sure would like a consistent output.· Anyway, I have included the entire code.· If you have any suggestions.· Please send them along.



    thanks,

    AG



    ' ==============================================================
    '{$PORT COM1}
    '
    ' File......... a2d_driver_v4.bs2
    ' Description.. File to interface the ADC0804 with the BS2
    ' Author....... Andrew Gentile
    ' Created...... Jan. 10, 2005
    ' Updated...... Jan. 11, 2005
    '
    ' ===============================================================



    '{$STAMP BS2}

    '
    ' Set port directions
    '
    DIRD=%0111
    DIRL=$00

    '
    ' Set pin names
    '

    ' Pin #············ function
    '
    ·····
    ·CS CON 15····· ' chip select -- control line (active low)
    ·RD CON 14····· ' Read -- control line (active low)
    ·WR CON 13····· ' Write -- control line (active low)
    ·INTR CON 12··· ' Interrupt -- input from ADC0804 (goes low to indicate EOC)

    '
    ' Variables
    '
    ·LIGHT VAR Byte·· ' digital value of light intensity
    ·EOC VAR Bit····· ' end of conversion signal from ADC0804

    '
    '·························· Main Function
    '


    Main:
    GOSUB init_a2d········· ' Initialize ADC0804
    GOSUB wrt_a2d·········· ' Instruct a2d to send data to pins
    GOSUB read_a2d········· ' Read from a2d data pins

    DEBUG DEC LIGHT,10,13·· ' Send value of LIGHT to screen
    PAUSE 50

    GOTO Main





    '
    ' Subroutine to write to data pins of ADC
    '
    wrt_a2d:
    LOW CS······································ ' Activate chip
    PULSOUT WR,5································ ' Pulse WR low to begin conversion (2uS per unit -- 10uS pulse)
    HIGH CS
    wait_for_intr······························· ' wait for EOC flag from a2d
    EOC=IN12···································· ' poll EOC pin
    IF EOC=1 THEN wait_for_intr················· ' decision
    HIGH CS····································· ' disable chip until next conversion is called
    RETURN


    ' Subroutine to read from data pins of ADC
    '
    read_a2d:
    LOW CS······································ ' Activate chip
    LOW RD······································ ' Hold READ low to fetch data from pins
    LIGHT=INL··································· ' Put data onto low register
    LIGHT=LIGHT REV 8··························· ' Reverse pin order (due to wiring)
    HIGH RD····································· ' Disable READ
    HIGH CS····································· ' Disable chip until next conversion is called
    RETURN


    '
    '···· Subroutine to initialize ADC
    '

    init_a2d:
    LOW CS··········· ' activate chip
    HIGH WR·········· ' hold WRITE as inactive until needed
    HIGH RD
    RETURN


    ' Description of program.
    '
    ' The ADC0804 is activated by setting CS low; a write cycle is initiated by pulsing WR low.··· The chip conversion
    ' time is determined by R and C tied to the CLK pins.· Using R=10k and C=150pF, the conversion time is around 100uS.
    ' A typical cycle of the chip:
    '
    ' A write cycle
    '
    ' Conversion begins by sending CS and WR signals.· The INTR pin will send a low pulse to indicate the conversion is
    ' complete.· When the uC gets the EOC flag, it puts CS high again (WR is normally high, and just pulsed to begin the
    ' conversion).
    '
    ' A read cycle
    '
    ' The converted data is sent to the output pins by sending the CS and RD signals.·· The data can then be retrieved
    ' by the bs2 by reading the appropriate pins.· In this case, the REV command is necessary because the data pins were
    ' wired in reverse order for convenience.
    '
    ' Problems with circuit
    '
    ' Given a constant input, there is variation in the output.· The output variation cycles with a consistent frequency.
    ' The frequency is a function of the duration of the PULSOUT command on line 63.· The longer the pulse, the higher
    ' the frequency.· I have no idea why this happens, although the output is far too consistent for this to be a result
    ' of spiking.· Given the resolution that we are working with, I don't think that this will be a problem.
  • NewzedNewzed Posts: 2,503
    edited 2005-01-11 20:22
    AG, for a start, put a .1uf bypass cap on the ADC input pin.· Cap should be as close to the ADC as possible.· Also put a 1.2K resistor in series with your sensor input.· This should make your ADC output rock-steady.· It does on mine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester?

    http://hometown.aol.com/newzed/index.html
    ·
  • achilles03achilles03 Posts: 247
    edited 2005-01-11 20:34
    AG,
    Newzed's got good advice. If you were taking really fast measurements of a sensor that was changing really fast, then you might not want a cap there, but since it's slow, .1uF will give you a "moving average" over the last few micro/milliseconds.

    One other place you want a cap is between the 5VDC and ground. Your 5VDC reference isn't exactly 5V... it's varying a little bit over time, which can throw off your measurement a little.

    Another possibility is that your sensor is actually varying about 5% over time. Are you taking measurements outside? Remember clounds and sun angle will affect measurements.

    Also, if you're using photocells, remember that they are notoriously inconsistant. Two photocells from the same batch might have a 10% or 20% difference in resistance across them for the same light intensity.

    Dave
Sign In or Register to comment.