hello!
i using piece of code seems interfere millis function:
does knows workaround or how can use (another) millis timer? use code for theremin sensor , @ same time open more solenoid valves. cannot use delay.
thank much!
i using piece of code seems interfere millis function:
code: [select]
void f_meter_start() {
f_ready=0; // reset period measure flag
i_tics=0; // reset interrupt counter
sbi (gtccr,psrasy); // reset presacler counting
tcnt2=0; // timer2=0
tcnt1=0; // counter1 = 0
cbi (timsk0,toie0); // dissable timer0 again // millis , delay
sbi (timsk2,ocie2a); // enable timer2 interrupt
tccr1b = tccr1b | 7; // counter clock source = pin t1 , start counting now
}
// timer2 interrupt service invoked hardware timer2 every 2ms = 500 hz
// 16mhz / 256 / 125 / 500 hz
// here gatetime generation freq. measurement takes place:
//******************************************************************
isr(timer2_compa_vect) {
if (i_tics==50) { // multiple 2ms = gate time = 100 ms
// end of gate time, measurement ready
tccr1b = tccr1b & ~7; // gate off / counter t1 stopped
cbi (timsk2,ocie2a); // disable timer2 interrupt
sbi (timsk0,toie0); // ensable timer0 again // millis , delay
f_ready=1; // set global flag end count period
// calculate frequeny value
freq_in=0x10000 * mlt; // mukt #ovverflows 65636
freq_in += tcnt1; // add counter1 value
mlt=0;
}
i_tics++; // count number of interrupt events
if (tifr1 & 1) { // if timer/counter 1 overflow flag
mlt++; // count number of counter1 overflows
sbi(tifr1,tov1); // clear timer/counter 1 overflow flag
}
}
does knows workaround or how can use (another) millis timer? use code for theremin sensor , @ same time open more solenoid valves. cannot use delay.
thank much!
comment out line:
you'll more jitter on measuring, it's going allow millis() , delay work.
code: [select]
cbi (timsk0,toie0); // dissable timer0 again // millis , delay
you'll more jitter on measuring, it's going allow millis() , delay work.
Arduino Forum > Using Arduino > Programming Questions > time function millis does interfere with other code
arduino
Comments
Post a Comment