Larry, I believe your problem is the following line: RND=TMR0 You declare RND as a word (16bits) and then try to fill it with TMR0 which is a byte (8bits). I believe the programs hangs up waiting for the other 8 bits then resets via the watchdog. Try using TMR1. It's 16 bits. Larry Green wrote: Subject: Re: [PIC]: Pic Basic Pro / Pic 16f818 Problem > > > So I guess my first question is..... > > > where should I post the code in order to get an answer to this problem? > > Posting modest amounts of code on list won't hurt (much :-) ). > > If the problem is PIC specific people here may be able to help. > PIC BASIC specific maybe not. Thanks for replying Russel. The answer need not be PBP specific as I can always add the assembly code if I can get that. The concept I am trying to get working is as follows: I need to generate a pseudo random number which is then used in a time delay loop to produce a random time delay between a button press and a buzzer sounding. The delay needs to be in the range 1-30 seconds (or there about......it is not critical to a second or so but needs to be different for each button press). Once the time is up a new random number is generated and a choice is made between two options. I have included some of the code below which shows key lines (for reference) plus the entire problematic subroutine. The rest of the code works fine. Larry Green VE3YET 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