Need help with BASIC code for PICAXE

Discussion in 'The Projects Forum' started by twd8, Jul 17, 2012.

  1. twd8

    Thread Starter New Member

    Jul 17, 2012
    2
    0
    I'm trying to build an xray timer, which measures an xray pulse to help with calibration. I managed to build the device using the PICAXE 08 kit and wrote the program for the device using BASIC. I tried to write the code so that I could save some of the measurements to the EEPROM. This way, I could access the measurements later even if the device was accidentally turned off. However, the value that the device saves (the variable I designated to be b21 saves this value), changes once I get out of the do loop. Playing around, I found out that somehow the line "write w6, w3" is responsible for this change (found on line 25 below. I'm pretty certain that none of the variables overlap, and I've been stuck on this issue for a really long time. Does anyone know the reason why? Thanks!

    This is an isolated part of my entire code (and where the issue lies)
    Code ( (Unknown Language)):
    1.  
    2. symbol LED = B.1
    3. symbol pc = B.2
    4. symbol sw = pinC.4
    5.  
    6. main:
    7.  
    8. setfreq m32
    9.  
    10. let b10 = 0
    11.  
    12. readadc pc, b0
    13. sertxd (#b0, 13, 10)
    14. w3 = 0
    15. if b0>10 then
    16.    
    17.     do
    18.         readadc pc, b0
    19.         sertxd (#b0, 13, 10)
    20.         write b21, b20
    21.         let b20 = b0
    22.         pause 80
    23.         inc w3
    24.     loop until b0<10
    25.    
    26.     write w6, word w3
    27.     let w2 = 0
    28.    
    29.     read b21, b24
    30.     sertxd ("b24 = ", #b24, 13, 10)
    31. endif
    32.  
    33. goto main
    34.  
     
  2. Rbeckett

    Member

    Sep 3, 2010
    205
    32
    TWD,
    You may get a better reply if you give the Picaxe forum a shout. They do code and snippets all the time and it is in Basic and suited for their devices. Worth a look anyway.
    Bob
     
  3. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,575
    230
  4. twd8

    Thread Starter New Member

    Jul 17, 2012
    2
    0
    OK, thanks!
     
Loading...