quick question


Closed Thread
Results 1 to 5 of 5

Thread: quick question

  1. #1

    Default quick question

    I have 4 identical circuits. If I put at the top of each program:

    X var word
    pause x

    and power up all 4 at the same time, will X be a random number on each of them? The idea here is to make all 4 flash an LED but I don't want them to do it at the same time. Will this work or should I generate a random number for X in a more conventional way? Thanks

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: quick question

    Peter, I would personally start one of the 16 bit timers (if it has 1) and then read it and use it as the SEED for the random command whoes output would be scalled and used as the PAUSE variable.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: quick question

    x will most likely be 0 or 65535 when you apply power. Getting a truly random number is actually quite hard. Perhaps a long wire or PCB trace acting as an antenna feeding an analog input and sample it on power on.

    /Henrik.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: quick question

    One way to get a “sort of random number” is to start a timer, and then let the watchdog timer do a reset which will not ruin the timer values.
    Then you can read them and you get different values each time in some limited range that you could multiply or divide.
    The next time the program starts after the reset, the timer values will be non zero before you started the timer. Then service the watchdog timer from then on.

    I left an example here at some stage that allowed a pic to determine from a list of specific values, what speed crystal is running the pic.

    Another way might be to let the POT command do what it does, and time the discharge of a capacitor through a resistor.
    You should be able to fiddle with resistor and capacitor values to make the POT command return inconsistent readings.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: quick question

    Can you add a pot?

    I'd connect it to an analog input, read the value, establish a pause or loop on that value then start main loop.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. A quick question.....
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2010, 15:25
  2. Quick DS18B20 question
    By gti_uk in forum General
    Replies: 4
    Last Post: - 21st June 2009, 18:24
  3. Interrupt Quick Question
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2005, 06:51
  4. quick question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd December 2004, 02:45

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