I'm trying to build a proportional thermostat that dims AC devices on an Arduino Uno. I'm using simple triac dimming; an interrupt tells me when I have a zero crossing of the AC wave, and based on the percent I want to dim the device, I know I need to wait between 0 and 8333 microseconds (60 Hz AC, so 120 half phases) before firing the triac.
8333 us isn't a lot to play with.... I need to get temperatures from multiple DS18B20 probes. From what I can gather, 1-Wire operations require a reset (480 us + 480 us for devices to respond) and at least 60 us to clock a bit in or out. In order to read the scratchpad of one DS18B20 with multiple DS18B20's on the bus, I've got to do:
1. Reset (960 us)
2. Send Match ROM (9 bytes = 4320 us)
3. Send Read Scratchpad (1 byte = 480 us)
4. Read 9 bytes (4320 us)
Total: 10,080 us
In other words, if my math is right, it's longer than the AC cycle I'm trying to dim. Blocking for 10 ms to read the scratchpad isn't acceptable. So it seems like what I need to do is modify or rewrite Paul Stroffregen's OneWire library based around a polling loop. I would loop and check if it's time to fire the Triac, check if it's time to bang a OneWire bit, etc. (And I need to throw in the PID calculation, output to an LCD panel via I2C, possible input/output from serial....)
So I'm wondering:
1. It seems like the timing on banging a OneWire bit must be very precise. The OneWire library code disables interrupts. I don't have a problem disabling interrupts for, say, 60 us, and delaying my check for firing the triac by that much. Compared to the AC sine wave, it isn't a lot of error. But I'd like to write code that would bang a bit in or out, check to see if something else needed to be done (e.g. the triac), bang another bit, etc. As the master determines the clocking of bits in or out, I'd think that some variable delay between individual bits would be acceptable. But what I can't find is an upper limit for that delay. What is the maximum time between reading or writing consecutive bits to a DS18B20 before the device gives up or considers this an error?
2. Has anyone done anything like this before?
Thanks,
Ryan

