所有关于电路

关于7段显示问题

mike_the_begginer

线程启动

mike_the_begginer

12月7日,2019年加入
95年
你好,我想要建立一个使用Arduino焊接站。焊台的工作方式,但是代码可能有一个错误,显示不更新。当我转动锅,然后显示(7段3位数)显示的值读取从锅里,但没有更新显示为烙铁加热。
请查看代码和告诉我你的想法吗?

焊接站:
# include < PID_v2。h > # include < max6675。h > int thermoDO = 12;int thermoCS = 10;int thermoCLK = 13;MAX6675热电偶(thermoCLK thermoCS thermoDO);/ /保护int relay_pin = A5;/ /这个数组包含段需要打开显示数字0 - 9字节const位数[]= {B00111111、B00000110 B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};int digit_common_pins [] = {A2、A3、A4};/ /普通针的三重7-Segment LED显示屏int max_digits = 3; int current_digit = max_digits - 1; unsigned long updaterate = 1000; //Change how fast the display updates. No lower than 500 unsigned long lastupdate; int temperature = 0; //Define Variables we'll be connecting to double Setpoint, Input, Output; double heaterTemp; //Define the aggressive and conservative Tuning Parameters double aggKp = 4, aggKi = 0.2, aggKd = 1; double consKp = 1, consKi = 0.05, consKd = 0.25; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT); void setup() { DDRD = B11111111; // sets Arduino pins 0 to 7 as outputs for (int y = 0; y < max_digits; y++) { pinMode(digit_common_pins[y], OUTPUT); } //We do not want to drive the soldering iron at 100% because it may burn, so we set it to about 85% (220/255) myPID.SetOutputLimits(0, 220); myPID.SetMode(AUTOMATIC); lastupdate = millis(); Setpoint = 0; pinMode(relay_pin, OUTPUT); digitalWrite(relay_pin, LOW); delay(1000); digitalWrite(relay_pin, HIGH); } void loop() { // Read temperature heaterTemp = thermocouple.readCelsius(); Input = (0.779828 * heaterTemp) - 10.3427; //Display temperature if (isnan(heaterTemp) or Input >= 432) // No TC Connection OR over-temperature { while (true) { digitalWrite(relay_pin, LOW); digitalWrite(11, LOW); PORTD = B00000000; } } if (millis() - lastupdate > updaterate) { lastupdate = millis(); temperature = Input; } //Read setpoint and transform it into degrees celsius(minimum 150, maximum 350) double newSetpoint = analogRead(1); newSetpoint = map(newSetpoint, 0, 1023, 150, 400); //Display setpoint if (abs(newSetpoint - Setpoint) > 3) { Setpoint = newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50){ show(50); } else { show(temperature); } } void show(int value) { int digits_array[] = {}; boolean empty_most_significant = true; for (int z = max_digits - 1; z >= 0; z--) //Cycle through each digit { digits_array[z] = value / pow(10, z); //We now take each digit from the number if (digits_array[z] != 0 ) empty_most_significant = false; //Do not display leading zeros value = value - digits_array[z] * pow(10, z); if (z == current_digit) { if (!empty_most_significant || z == 0) { //Check to see that we do not have leading zeros and display the current digit PORTD = digits[digits_array[z]]; //Remove ~ for common cathode } else { PORTD = B00000000; } digitalWrite(digit_common_pins[z], HIGH);//Change to LOW for common cathode } else { digitalWrite(digit_common_pins[z], LOW);//Change to HIGH for common cathode } } current_digit--; if (current_digit < 0) { current_digit = max_digits; //Start over } }
mike_the_begginer

线程启动

mike_the_begginer

12月7日,2019年加入
95年
勒:通过修改循环(),它似乎工作。是正确的吗?Arduino正确阅读MAX6675,在正确的时间间隔?
C:
无效循环(){如果(米尔斯()- lastupdate > updaterate) {lastupdate =米尔斯();/ /读取温度heaterTemp = thermocouple.readCelsius ();输入= (0.779828 * heaterTemp) - 10.3427;/ /显示温度如果(isnan (heaterTemp)或输入> = 432)/ /不TC连接或过热{虽然(真正的){digitalWrite (relay_pin、低);digitalWrite(11、低);PORTD = B00000000;}}温度=输入;}/ /读取选点并将其转换成摄氏度(最低150,最高350)双newSetpoint = analogRead (A1);newSetpoint =地图(newSetpoint 0, 1023, 150, 400);/ /显示定位点如果(abs (newSetpoint -定位点)> 3){选点= newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50) { show(50); } else { show(temperature); } }
最后的编辑:
KeithWalker

KeithWalker

2017年加入7月10日
1563年
很困难,非常耗时,试图消除漏洞别人的项目,因为我们不能运行它,看看是怎么回事。我建议你试着消除漏洞使用串行监控程序。
你工作循环一次,添加系列。打印语句来显示相关变量的值。把延迟(1秒?)的循环,这样你有时间阅读结果。每次你样本变量,记录它们,然后停止程序。注释掉系列。打印行和添加更多的在下次操作程序的一部分。审查结果时,您可以看到这个项目是做什么,你会有一个好的迷路的地方。
E

eetech00

加入2013年6月8日
2292年
看,甚至Arduino同意我,需要改进。这个版本的IDE是免费的,但您还需要一个JTAG接口,据我所知,不是免费的。
和这只包括那些董事会JTAG接口。
董事会的TS没有具体说明。
都是合理的建议。

您可以使用串口打印语句,但它们是皮塔饼来管理。
SamR

SamR

3月19日,2019年加入
3149年
或者你可以停止滚动在串行监控来看看是怎么回事。编写代码的串行监控可能不是“最好”的解决方案,但它是你必须在Arduino IDE。
AlbertHall

AlbertHall

加入2014年6月4日
11030年
微芯片MPLAB-X,例如:
特定值时停止程序写入到一个特定的变量。
在模拟器运行该程序,不需要硬件和时间计划的任何部分与模拟外部输入。
mike_the_begginer

线程启动

mike_the_begginer

12月7日,2019年加入
95年
在不同的论坛搜索之后,我发现了问题:MAX6675模块需要阅读至少250毫秒间隔。在最初的代码,程序比250 ms的阅读更频繁。我修改了程序如下所示,工作原理:


焊接站:
# include < PID_v2。h > # include < max6675。h > / / MAX6675模块数据大头针int thermoDO = 12;int thermoCS = 10;int thermoCLK = 13;MAX6675热电偶(thermoCLK thermoCS thermoDO);/ /保护针int relay_pin = A2;/ / int led_pin = 8;/ /这个数组包含段需要打开显示数字0 - 9字节const位数[]= {B00111111、B00000110 B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};int digit_common_pins [] = {A3、A4、A5}; //Common pins for the triple 7-Segment LED display int max_digits = 3; int current_digit = max_digits - 1; unsigned long updaterate = 700; //Change how fast the display updates. No lower than 500 unsigned long lastupdate, lastupdate_max; int temperature = 0; //Define Variables we'll be connecting to double Setpoint, Input, Output; double heaterTemp; //Define the aggressive and conservative Tuning Parameters double aggKp = 4, aggKi = 0.2, aggKd = 1; double consKp = 1, consKi = 0.05, consKd = 0.25; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT); void setup() { DDRD = B11111111; // sets Arduino pins 0 to 7 as outputs for (int y = 0; y < max_digits; y++) { pinMode(digit_common_pins[y], OUTPUT); } //We do not want to drive the soldering iron at 100% because it may burn, so we set it to about 85% (220/255) myPID.SetOutputLimits(0, 220); myPID.SetMode(AUTOMATIC); lastupdate = millis(); lastupdate_max = millis(); Setpoint = 0; //pinMode(led_pin, OUTPUT); pinMode(relay_pin, OUTPUT); //digitalWrite(led_pin, LOW); digitalWrite(relay_pin, LOW); delay(1000); digitalWrite(relay_pin, HIGH); // turns on the relay to let the current flow to the soldering iron heater } void loop() { if (millis() - lastupdate_max > 250){ lastupdate_max = millis(); // Read temperature heaterTemp = thermocouple.readCelsius(); Input = (0.779828 * heaterTemp) - 10.3427; //estimate the temperature of the iron's tip, by reading the temperature of the iron's heater //Display error if (isnan(heaterTemp) or Input >= 432) // No TC Connection OR over-temperature { while (true) { digitalWrite(relay_pin, LOW);//cuts off the power to the soldering iron digitalWrite(11, LOW);//turns off the PID output PORTD = B00000000; // Turns off the entire display //digitalWrite(led_pin, HIGH); } } } //Display temperature if (millis() - lastupdate > updaterate) { lastupdate = millis(); temperature = Input; } //Read setpoint and transform it into degrees celsius(minimum 150, maximum 400) double newSetpoint = analogRead(A1); newSetpoint = map(newSetpoint, 0, 1023, 150, 400); //Display setpoint if (abs(newSetpoint - Setpoint) > 3) { Setpoint = newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); // compute the pid output //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50) { show(50); //display 50 if the estimated temperature is below 50C } else { show(temperature); //display the temperature } } void show(int value) { int digits_array[] = {}; boolean empty_most_significant = true; for (int z = max_digits - 1; z >= 0; z--) //Cycle through each digit { digits_array[z] = value / pow(10, z); //We now take each digit from the number if (digits_array[z] != 0 ) empty_most_significant = false; //Do not display leading zeros value = value - digits_array[z] * pow(10, z); if (z == current_digit) { if (!empty_most_significant || z == 0) { //Check to see that we do not have leading zeros and display the current digit PORTD = digits[digits_array[z]]; //Remove ~ for common cathode } else { PORTD = B00000000; } digitalWrite(digit_common_pins[z], HIGH);//Change to LOW for common cathode } else { digitalWrite(digit_common_pins[z], LOW);//Change to HIGH for common cathode } } current_digit--; if (current_digit < 0) { current_digit = max_digits; //Start over } }
线程启动 类似的线程 论坛 回复 日期
l 作业帮助 5
微控制器 6
E 无线射频设计& 6
年代 微控制器 5
年代 数字设计 1