hi,
i use 50Hz ac powered motor control on arduino mega with triac circuit.(isr0 triggering triac every ~5ms)
it working succes but, motor speed loss occurs when i get temperature by ds18b20 for a short time.
i searched the source of the problem on ds18b20 library but no avail (parasite mode already closed, changed delays, waitforconversations setted false).
i changed triac control timer: timer1 to timer3 , result is same.
i think; external interrupts turning off to read the temperature but i couldnt find solution.
unsigned long delaysn=0;
float tsi,temmpn;
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(62);
DallasTemperature sensors(&oneWire);
//triac control area//
#include <TimerOne.h>
float Value = 0; volatile int z = 0; volatile boolean zero_cross = 0;
int AC_pin = 6; double dim = 340; int freqStep = 20;
void zero_cross_detect() {
zero_cross = true;
z = 0;
digitalWrite(AC_pin, LOW);
}
void dim_check() {
if (zero_cross == true) {
if (z >= dim) {
digitalWrite(AC_pin, HIGH);
z = 0;
zero_cross = false;
}
else {
z++;
}
}
}
void setup() {
//triac control area//
pinMode(2,INPUT_PULLUP);
pinMode(AC_pin, OUTPUT);
attachInterrupt(0, zero_cross_detect, RISING);
Timer1.initialize(freqStep);
Timer1.attachInterrupt(dim_check, freqStep);
Serial.begin(9600);
//ds18b20
sensors.begin();
}
void loop() {
if ((millis()-delaysn)>=1000){delaysn=millis();
//ds18b20
sensors.requestTemperatures();
temmpn=sensors.getTempCByIndex(0);
Serial.println("dallas : " + String(temmpn)+" C");
}
}
My guess is that you have a rather high frequency of timer 1 interrupts and because the OneWire library disables interrupts for about 15µs for every bit transferred from or to the DS18B20 it might influence the duty cycle of your motor more than it likes.
15 us (less than one cycle) shouldn't have any effect on the motor's speed, unless it happens very frequently.
It does make me wonder. That timer1 library probably uses a timer compare interrupt, which should trigger at a specific value.
Is it possible that if this value is missed (it's reached during the time the DS18B20 is read, but the timer does continue to run) that the interrupt is completely missed at all? That would mean it'd only trigger when the timer rolls over, which may take quite long when using a 16-bit timer.
Standard OneWire library doesn't use a timer interrupt.
As about 15us delay - it's for each bit and regular transaction may have around hundred bits or so.
ds18b20 need max 12bit data transfer(setted 9bit), that means 15*12= 180us, it does not affect.
I agree with wvmarle , it missed a cycle but not timer1 cycle, it missed one 50hz frequency cycle.(or one interrupt missed, because without interrupt would not be triggered triac)
onewire library is using noInterrupts();
does this lead to the missed interrupt?
is there a way? im not need adress verification, im using only one ds18b20.
I guess I shouldn't use any library for this measurement.
and i noticed: it works fine when i disconnected ds18b20 connector, codes when processing; if i disconnect port its working fine when i connect again it slowing down.