|
@@ -71,7 +71,10 @@ unsigned char soft_pwm_bed;
|
71
|
71
|
#ifdef BABYSTEPPING
|
72
|
72
|
volatile int babystepsTodo[3]={0,0,0};
|
73
|
73
|
#endif
|
74
|
|
-
|
|
74
|
+
|
|
75
|
+#ifdef FILAMENT_SENSOR
|
|
76
|
+ int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only
|
|
77
|
+#endif
|
75
|
78
|
//===========================================================================
|
76
|
79
|
//=============================private variables============================
|
77
|
80
|
//===========================================================================
|
|
@@ -158,6 +161,9 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
|
158
|
161
|
#define SOFT_PWM_SCALE 0
|
159
|
162
|
#endif
|
160
|
163
|
|
|
164
|
+#ifdef FILAMENT_SENSOR
|
|
165
|
+ static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor
|
|
166
|
+#endif
|
161
|
167
|
//===========================================================================
|
162
|
168
|
//============================= functions ============================
|
163
|
169
|
//===========================================================================
|
|
@@ -601,6 +607,21 @@ void manage_heater()
|
601
|
607
|
}
|
602
|
608
|
#endif
|
603
|
609
|
#endif
|
|
610
|
+
|
|
611
|
+//code for controlling the extruder rate based on the width sensor
|
|
612
|
+#ifdef FILAMENT_SENSOR
|
|
613
|
+ if(filament_sensor)
|
|
614
|
+ {
|
|
615
|
+ meas_shift_index=delay_index1-meas_delay_cm;
|
|
616
|
+ if(meas_shift_index<0)
|
|
617
|
+ meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed
|
|
618
|
+
|
|
619
|
+ //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter
|
|
620
|
+ //then adjust as a factor to the Standard Diameter (has an area of 1mm squared)
|
|
621
|
+ //then square it to get an area
|
|
622
|
+ volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/filament_width_nominal*STANDARD_DIA/100.0,2);
|
|
623
|
+ }
|
|
624
|
+#endif
|
604
|
625
|
}
|
605
|
626
|
|
606
|
627
|
#define PGM_RD_W(x) (short)pgm_read_word(&x)
|
|
@@ -702,6 +723,40 @@ static void updateTemperaturesFromRawValues()
|
702
|
723
|
CRITICAL_SECTION_END;
|
703
|
724
|
}
|
704
|
725
|
|
|
726
|
+
|
|
727
|
+// For converting raw Filament Width to milimeters
|
|
728
|
+#ifdef FILAMENT_SENSOR
|
|
729
|
+float analog2widthFil() {
|
|
730
|
+return current_raw_filwidth/16383.0*5.0;
|
|
731
|
+//return current_raw_filwidth;
|
|
732
|
+}
|
|
733
|
+
|
|
734
|
+// For converting raw Filament Width to an volumetric ratio
|
|
735
|
+int widthFil_to_size_ratio() {
|
|
736
|
+
|
|
737
|
+float temp;
|
|
738
|
+
|
|
739
|
+#if (FILWIDTH_PIN > -1) //check if a sensor is supported
|
|
740
|
+filament_width_meas=current_raw_filwidth/16383.0*5.0;
|
|
741
|
+#endif
|
|
742
|
+
|
|
743
|
+temp=filament_width_meas;
|
|
744
|
+if(filament_width_meas<MEASURED_LOWER_LIMIT)
|
|
745
|
+ temp=filament_width_nominal; //assume sensor cut out
|
|
746
|
+else if (filament_width_meas>MEASURED_UPPER_LIMIT)
|
|
747
|
+ temp= MEASURED_UPPER_LIMIT;
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+return(filament_width_nominal/temp*100);
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+}
|
|
754
|
+#endif
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
705
|
760
|
void tp_init()
|
706
|
761
|
{
|
707
|
762
|
#if (MOTHERBOARD == 80) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
|
|
@@ -797,6 +852,17 @@ void tp_init()
|
797
|
852
|
#endif
|
798
|
853
|
#endif
|
799
|
854
|
|
|
855
|
+ //Added for Filament Sensor
|
|
856
|
+ #ifdef FILAMENT_SENSOR
|
|
857
|
+ #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN > -1)
|
|
858
|
+ #if FILWIDTH_PIN < 8
|
|
859
|
+ DIDR0 |= 1<<FILWIDTH_PIN;
|
|
860
|
+ #else
|
|
861
|
+ DIDR2 |= 1<<(FILWIDTH_PIN - 8);
|
|
862
|
+ #endif
|
|
863
|
+ #endif
|
|
864
|
+ #endif
|
|
865
|
+
|
800
|
866
|
// Use timer0 for temperature measurement
|
801
|
867
|
// Interleave temperature interrupt with millies interrupt
|
802
|
868
|
OCR0B = 128;
|
|
@@ -1109,7 +1175,7 @@ ISR(TIMER0_COMPB_vect)
|
1109
|
1175
|
static unsigned long raw_temp_1_value = 0;
|
1110
|
1176
|
static unsigned long raw_temp_2_value = 0;
|
1111
|
1177
|
static unsigned long raw_temp_bed_value = 0;
|
1112
|
|
- static unsigned char temp_state = 8;
|
|
1178
|
+ static unsigned char temp_state = 10;
|
1113
|
1179
|
static unsigned char pwm_count = (1 << SOFT_PWM_SCALE);
|
1114
|
1180
|
static unsigned char soft_pwm_0;
|
1115
|
1181
|
#if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL)
|
|
@@ -1122,6 +1188,10 @@ ISR(TIMER0_COMPB_vect)
|
1122
|
1188
|
static unsigned char soft_pwm_b;
|
1123
|
1189
|
#endif
|
1124
|
1190
|
|
|
1191
|
+ #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1)
|
|
1192
|
+ static unsigned long raw_filwidth_value = 0; //added for filament width sensor
|
|
1193
|
+ #endif
|
|
1194
|
+
|
1125
|
1195
|
if(pwm_count == 0){
|
1126
|
1196
|
soft_pwm_0 = soft_pwm[0];
|
1127
|
1197
|
if(soft_pwm_0 > 0) {
|
|
@@ -1248,10 +1318,39 @@ ISR(TIMER0_COMPB_vect)
|
1248
|
1318
|
#if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1)
|
1249
|
1319
|
raw_temp_2_value += ADC;
|
1250
|
1320
|
#endif
|
1251
|
|
- temp_state = 0;
|
1252
|
|
- temp_count++;
|
|
1321
|
+ temp_state = 8;//change so that Filament Width is also measured
|
|
1322
|
+
|
1253
|
1323
|
break;
|
1254
|
|
- case 8: //Startup, delay initial temp reading a tiny bit so the hardware can settle.
|
|
1324
|
+ case 8: //Prepare FILWIDTH
|
|
1325
|
+ #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1)
|
|
1326
|
+ #if FILWIDTH_PIN>7
|
|
1327
|
+ ADCSRB = 1<<MUX5;
|
|
1328
|
+ #else
|
|
1329
|
+ ADCSRB = 0;
|
|
1330
|
+ #endif
|
|
1331
|
+ ADMUX = ((1 << REFS0) | (FILWIDTH_PIN & 0x07));
|
|
1332
|
+ ADCSRA |= 1<<ADSC; // Start conversion
|
|
1333
|
+ #endif
|
|
1334
|
+ lcd_buttons_update();
|
|
1335
|
+ temp_state = 9;
|
|
1336
|
+ break;
|
|
1337
|
+ case 9: //Measure FILWIDTH
|
|
1338
|
+ #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1)
|
|
1339
|
+ //raw_filwidth_value += ADC; //remove to use an IIR filter approach
|
|
1340
|
+ if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data.
|
|
1341
|
+ {
|
|
1342
|
+ raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128
|
|
1343
|
+
|
|
1344
|
+ raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading
|
|
1345
|
+ }
|
|
1346
|
+ #endif
|
|
1347
|
+ temp_state = 0;
|
|
1348
|
+
|
|
1349
|
+ temp_count++;
|
|
1350
|
+ break;
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+ case 10: //Startup, delay initial temp reading a tiny bit so the hardware can settle.
|
1255
|
1354
|
temp_state = 0;
|
1256
|
1355
|
break;
|
1257
|
1356
|
// default:
|
|
@@ -1260,7 +1359,7 @@ ISR(TIMER0_COMPB_vect)
|
1260
|
1359
|
// break;
|
1261
|
1360
|
}
|
1262
|
1361
|
|
1263
|
|
- if(temp_count >= OVERSAMPLENR) // 8 * 16 * 1/(16000000/64/256) = 131ms.
|
|
1362
|
+ if(temp_count >= OVERSAMPLENR) // 10 * 16 * 1/(16000000/64/256) = 164ms.
|
1264
|
1363
|
{
|
1265
|
1364
|
if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading.
|
1266
|
1365
|
{
|
|
@@ -1276,6 +1375,12 @@ ISR(TIMER0_COMPB_vect)
|
1276
|
1375
|
#endif
|
1277
|
1376
|
current_temperature_bed_raw = raw_temp_bed_value;
|
1278
|
1377
|
}
|
|
1378
|
+
|
|
1379
|
+//Add similar code for Filament Sensor - can be read any time since IIR filtering is used
|
|
1380
|
+#if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1)
|
|
1381
|
+ current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach
|
|
1382
|
+#endif
|
|
1383
|
+
|
1279
|
1384
|
|
1280
|
1385
|
temp_meas_ready = true;
|
1281
|
1386
|
temp_count = 0;
|