running a background 'thread' every 15ms

Hi,
I would like to run a DS18B20 and a DCF77 receiver at the same time - yet with my limited knowleadge this seems to be impossible at the moment as the DS needs a 750ms delay when queried and the DCF needs to be called every 15ms. So i figured out it would be great to have something call the DCF every 15ms and not wait for the other thing to return data - or save the DCF stuff and go ahead with a real time clock - both options COULD work...
So, my current perspective would be to skip the RTC and use an interrupt to let both things run at (nearly) the same time.. so would that be possible and has someone a small lightbulb to show me where to go to make this work?

Use all 3 pins on the DS18B20 and don't use parasite power, you wont need the 750ms delay then :slight_smile:

Even if you don't want to do that, you can make some code based on the blink without delay example.

Bit of main loop code to give you a some ideas.

    time=millis();

    if (time >= loop2){
    loop2 = loop2 + 15;
    //do your 15ms stuff here 
  }; 

    if (time >= loop3){
    loop3 = loop3 + 750;
    //do your 750ms stuff here 
    // I do read scratchpad of DS1820 followed by next call to update scratchpad with temperature at this point
  };

thanks for the replies.. about the 'use all three pins' - what do you mean? I have connected it with 1 on 5v, 2 as Data and 3 as GND where 1 and 3 are connected via a resistor. to call it i do:

  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  int Temp;
  if ( !ds.search(addr)) {
      //Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

/*  Serial.print("R=");  //R=28 Not sure what this is
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] != 0x28) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }
*/

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }
  Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature

  Temp=Temp>>4;//divide by 16 to get pure celcius readout

so how could i get rid of that 1000ms/750ms delay?

so how could i get rid of that 1000ms/750ms delay?

See my pseudo code. No delays, runs the second if then every 750 ms.

If you did the first

ds.select(addr);
  ds.write(0x44,1);

in setup
and then did

ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }
 //rest of temp conversion stuff / display / whatever

  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

inside the 750 ms if() bit in the pseudo code - hey presto 750 ms delay for the DS1820 with no delay. You can put other stuff in the main loop and it will run whilst its waiting for the DS1820 to get the temperature onto the scratch pad.

I have the same problems. I new with arduino and trying to make one project with 18b20 in background measuring mode... Can you help me to?