前几天想做个电动山东煎饼机, 用arduino控制一个步进来旋转饼铛然后热电偶控制电热丝加热. 步进用的是TB6560, 热电偶用的是max6675. 热电偶用的是定时interrupt, 每100ms进行一次interrupt. 现在的问题是每次打断之后热电偶读出来的温度值都是第一次的值........然后打断会打断步进的脉冲信号 (示波器看的). 打断目前可以接受, 可以慢慢搞, 但是热电偶涉及到防火安全, 所以现在要弄好才能放心测试. 希望大家帮着看看为什么.
示波器显示每次打断的热电偶的clock 和cs的信号正常, 但是热电偶没办法拆下来测所以没法说. 热电偶和步进的程序单着都挺好, 和一起就不成了.
谢谢大伙儿了.
- #include <TimerOne.h>
- #include <AccelStepper.h> //用的是accelstepper library
- #include <max6675.h>
- #define stepdir 6
- #define stepclk 5
- #define TIMER_US 100000 // 100mS set timer duration in microseconds
- volatile bool in_long_isr = false; // True if in long interrupt
- int thermoDO = 9;
- int thermoCS = 10;
- int thermoCLK = 11;
- int coilpin = 13;
- const int t_want = 90;
- AccelStepper stepper(stepdir,stepclk);
- MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
- void setup()
- {
- pinMode(stepclk, OUTPUT);
- pinMode(stepdir, OUTPUT);
- pinMode(coilpin, OUTPUT);
- stepper.setMaxSpeed(300);
- stepper.setSpeed(300);
- Timer1.initialize(TIMER_US); //
- Timer1.attachInterrupt( timerIsr ); // attach the ISR routine here
- Serial.begin(9600);// use Arduino pins
- Serial.println("MAX6675 test");
- delay(500);
- }
- void loop()
- {
- stepper.runSpeed();
- }
- void timerIsr() //timer1 做的interrupt
- {
- // digitalWrite( LED0, digitalRead( LED0 ) ^ 1 ); // Toggle LED 0
- volatile long i=0;
- interrupts(); // Enable interrupts
- //checkcoil();
- int temp = thermocouple.readCelsius();
- if (temp >= t_want)
- digitalWrite(coilpin, LOW);
- else if (temp <= t_want)
- digitalWrite(coilpin, HIGH);
-
- Serial.print("C = ");
- Serial.println(temp);
- noInterrupts();
- }
- //void checkcoil() //热电偶检查温度调整电热丝的程序, 赚到了isr里面
- //{
- // int temp = thermocouple.readCelsius();
- //
- // if (temp >= t_want)
- // digitalWrite(coilpin, LOW);
- //
- // else if (temp <= t_want)
- // digitalWrite(coilpin, HIGH);
- //
- // Serial.print("C = ");
- // Serial.println(temp);
- // return;
- //}
复制代码 |