Someone else suggested a WDT issue, and I might be inclined to agree. Did you include the "DEFINE NO_CLRWDT 1" statement? If you did, did you make sure that the Watchdog timer bit was cleared in the configs? It might be a good idea to clear it anyway. As for a problem writing the 8-bit value into a 16 bit variable, I don't think that's a problem, but you can circumvent it by doing this: RND.byte1 = 0 RND.byte0 = TMR0 ... etc. in place of the RND = TMR0 statement. Mike H. >Related Setup Code >----------------------------- >'set timer >option_reg = %11011000 'set TMR0 to internal clock > >'set variables >RND VAR WORD 'set RND as variable > >Problem Subroutine >---------------------------- >PB3SUB: >Low PBCONTROL 'turn off PB's >Low GLED 'turn off Green LED >High RLED 'turn on Red LED >RND=TMR0 'load TMR0 into RND >Random RND 'randomise RND >RND = (RND // 31) + 1 'returns a number between 1-31 >For LOOP1=1 TO (RND*1000) 'pause for RND secs >Next LOOP1 >RND=TMR0 'load current TMR0 into RND (different >value) >Random RND 'randomise RND a 2nd time >Low RLED 'turn off Red LED >RND = (RND // 31) + 1 'returns a number between 1-30 >IF RND>=15 Then >GoTo PB1SUB 'if RND is higher than mid point run PB1 >sub-routine >Else >GoTo PB2SUB 'if RND is lower than mid point run PB2 >sub-routine >EndIF >GoTo MAIN > >Note >------- >The above subroutine currently runs to the end of line two and then hangs >until >the button is released (which is odd as the first line turns off the push >button.......unless it cycles through so quickly it is sampling the button >state >again before it is released). > >If I 'rem' out all the lines that relate to 'RND' or 'Random' and add a >delay >between 'High RLED' and 'Low RLED' the red LED comes on for the duration of >the >delay (this leads me to believe my problem lies with either my method of >trying >to read the value of TMR0 or with the 'Random' command. > >If anyone can shed any light on this or suggest a way of achieving my goals >I >would appreciate the info. > >-- >http://www.piclist.com hint: PICList Posts must start with ONE topic: >[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > >Chuck Hellebuyck >Electronic Products >chuck@elproducts.com >**** Home of the BasicBoard Development Platform********* >Great for learning, teaching and developing electronic, programmable >robotics and other embedded applications. Starter packages from $149.95. >http://www.elproducts.com > >--------------------------------- >Do you Yahoo!? >Yahoo! Photos - Get your photo on the big screen in Times Square > >-- >http://www.piclist.com hint: The list server can filter out subtopics >(like ads or off topics) for you. See http://www.piclist.com/#topics _________________________________________________________________ Make your home warm and cozy this winter with tips from MSN House & Home. http://special.msn.com/home/warmhome.armx -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.