Welcome! Log In Create A New Profile

Advanced

Project: Teacup Firmware

Posted by Triffid_Hunter 
Re: Project: Teacup Firmware
October 07, 2012 06:25AM
Quote

I do not see where heater_pwm is set to 30

smiling smiley I meant code line 30, like line 30 of the text file representing the code.

Quote

Maybe one could disable the PWM output by clearing the heater_pwm pointer to zero somehow.

Zeroing heater_pwm doesn't help, as currently everything PWMable is set to do PWM in mendel.c, line 163ff. A good first step would probably to move this initialisation code into heater_init(), ideally in a way which sets up the PWM pins in use, only and allows different initialisation for different pins.

Would definitions like
/***************************************************************************\
...
* Set "strategy" to ...                                                     *
*  - BANG_BANG to disable PWM and use bang bang instead                     *
*  - 76Hz to use low frequency PWM (requires a PWM-able pin)                *
*  - 78kHz to use high frequency PWM (requires a PWM-able pin)              *
*                                                                           *
\***************************************************************************/
//            name      port   strategy
DEFINE_HEATER(extruder, PB3,   76Hz)
DEFINE_HEATER(bed,      PB4,   BANG_BANG)
DEFINE_HEATER(fan,      PB5,   78kHz)
be too complex for newbies? Ideally, making different strategies for different heaters possible.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 07, 2012 06:36PM
To get started, I've moved heater initialisation from mendel.c to heater.c. This enhances encapsulation.

An attempt to initialise only the timers in use was abandoned. This isn't only unneccessary, as pins are still in normal
operation mode unless their bits in TCCR0A/TCCR2A/... are set, even with the timer behind the pins running, it's also at least tricky to sort pins and their timer bits at compile time. Doing the sorting at runtime would cause additional binary size.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 08, 2012 02:10AM
Triffid_Hunter Wrote:
-------------------------------------------------------
...
> no need to avoid 16 bit timers for PWM, just set
> them to 8 bit mode and write to the high word.
> Should already be some code for the mega to do
> that

Cool. I'm testing the PWMs I tried to define for the ATmega32U4 in [github.com] and correcting the _PWM registers. I really did not understand the differences in the different timers and the proper choice of timers and the proper sizes of registers. I had started from the arduino_usb1280.h which has no PWM definitions, and filled them in sloppily.

I discovered I needed to modify the mendel.c code to make the atmega32u4 timer4 stuff initialize better. Patch: teensy.patch -- Ack. that's probably behind Traumflug's changes.


I suppose that the DIO/AIO/PPortPin _PWM definitions should probably be all consistent so one could use DIO15, AIO6, and PB6 interchangeably. If they were different, you could use a #define DIO15_PWM NULL for BANG-BANG output and #define AIO6_PWM &OCR4B for PWM output using the same PB6 pin. Teensy would have 3 PWM-capable pins that could be managed that way.

Edited 2 time(s). Last edit at 10/08/2012 02:18AM by DaveX.
Re: Project: Teacup Firmware
October 08, 2012 08:15AM
Thanks for the patch, DaveX. I think I applied it successfully: [github.com]


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 11, 2012 08:56PM
Using PWM is now optional, even for PWM-able pins: [github.com]

Sometimes things turn out to be very simple once one knows how to do it. And seeing what already worked I was again amazed how carefully written Teacup is.

This heater_set() issue should be fixed, too: [github.com]

Let me know how it works for you, in my setup everything looks good.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 11, 2012 09:00PM
So, its been awhile since I've been able to come back to this project. I'm curious as to the latest printing resolution people are getting out out teacup?
last prints I had were about .2 mm? that was about a year ago. I was reading somewhere that we can get down to .02mm ?

just curious as to how the overall progress has been going.
oh yeah did the endstop discussion ever get resolved? ;-)
Re: Project: Teacup Firmware
October 12, 2012 07:38AM
Uhm. Resolution? Resolution depends on your machine's gearing, microstepping, and similar things. Teacup can deal with up to 4095 steps/mm (could be more at the cost of build volume), so Teacup's resolution limit is 0.00024mm.

In case you refer to erratic behaviour with high steps/mm values, about half a year ago a number of possible integer overflows were fixed. Since then this area is pretty silent.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 14, 2012 11:14AM
Might there be a problem with casting/truncation or something in the EWMA code in temp.c?

On the EWMA_ALPHA = 0.1, I had a problem with some reported temperature values for a AIO clamped to Vref for my unheated bed. Readings would stay at 0 for minutes, then jump and sticking at about 6397.50 C. I saw something similar on my extruder after I went through a printing cycle, after which the g-code program shut down the heat while I thought it was still hot. Some time later, the extruder was showing a similar multi-thousand temp with cold plastic. I also noticed that M111 S1 temps were different than the M105 temps. In one case, with EWMA_ALPHA = 1.0. M105 was about 4C while M111 S1 was showing 93

I've tried the explicit casting in this patch, and it seemed to correct these problems:

v21837:Teacup_Firmware drf$ git diff upstream Gen7 temp.c
diff --git a/temp.c b/temp.c
index 7f348d7..653b1ba 100644
--- a/temp.c
+++ b/temp.c
@@ -297,9 +297,9 @@ void temp_sensor_tick() {
                        #endif
                        #define EWMA_SCALE  1024L
                        #define EWMA_ALPHA  ((long) (TEMP_EWMA * EWMA_SCALE))
-                       temp_sensors_runtime.last_read_temp = (EWMA_ALPHA * temp +
+                       temp_sensors_runtime.last_read_temp = (uint16_t) ((EWMA_ALPHA * temp +
                          (EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime.last_read_temp
-                                                                ) / EWMA_SCALE;
+                                                                             ) / EWMA_SCALE);
                }
                if (labs((int16_t)(temp_sensors_runtime.last_read_temp - temp_sensors_runtime.target_temp)
                        if (temp_sensors_runtime.temp_residency < (TEMP_RESIDENCY_TIME*120))


I also need to verify my ThermistorTable matches my thermistor circuit. I might have mucked mine up while learning git. But still, that shouldn't have caused a difference between the M111 S1 vs M105 readings.


Additionally, attached please find a patch against the Gen7 branch that:

* includes the above EWMA casting patch
* Adds minor comments to the arduino_32U4.h file
* Adjusts Makefile to allow use of some Teensy-specific code: non LUFA usb_serial and a program-teensy target using the teensy_loader_cli
* Modifies config.teensy.h to match my tested configuration.
Attachments:
open | download - teensy_20121014.patch (20.1 KB)
Re: Project: Teacup Firmware
October 14, 2012 06:42PM
Thanks for the patches, DaveX. I applied most of that.

I'm not so convinced with the serial stuff. Is Teensy's usb_serial so much better? Can we drop lufa_serial instead? Does the Teensy refuse to work with lufa_serial? Having two sets of source code for one task should have an important reason.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 15, 2012 12:08AM
Teensy and lufa_serial are refusing to work for me, but maybe I'm doing something wrong.

I seem to remember that I did have the LUFA usb code working on the Teensy back in February, but I think I might have had to redefine things deep in the LUFA tree, somewhere around LUFA/trunk/LUFA/Drivers/Board/TEENSY/LEDs.h or something. I do remember that I kept having problems and hacked together serial_teensy.c because I couldn't figure out what what wrong in my use of LUFA.

Today, when I try LUFA, with lufa_serial/makefile set to MCU = atmega32u4, BOARD=TEENSY I get errors about not having a Joystick.h somewhere. Trying BOARD=USER with a mkdir lufa_serial/Board ; touch lufa_serial/Board/Joystick.h and some munging around of a copy of LUFA/trunk/LUFA/Drivers/Board/TEENSY/LEDs.h in lufa_serial/Board/ LUFA seems to compile, but doesn't enumerate on my Mac. I've seen some hints about some sort of problem with LUFA on Macs, (e.g., maybe [groups.google.com] [forums.adafruit.com] and [groups.google.com] ???) but the solutions seemed like they either worked on mac XOR windows.

I've committed this lufa_serial/* stuff to my fork. I think it is headed towards getting LUFA and teensy working, but it doesn't seem to be working, (at least on my Mac.)

Dropping lufa_serial would break things for the at90usb1287 folks. But maybe a small change in usb_serial.h would fix them up.

Either way, I'm not able to test an at90usb1287, configure LUFA for my hardware, or see if LUFA+teensy is working on Windows right now. I'm stuck with PJRC's usb_serial and my serial_teensy.

Dave
Re: Project: Teacup Firmware
October 17, 2012 07:36AM
Dave, I've taken the (a bit bold) step to replace lufa serial with usb serial. usb_serial.{c|h} is now in Teacup's repository, this gets rid of the external dependency. If there are actually lufa serial users and it breaks something for them, I think we can work that out.

I've also replaced teensy_serial.c with a couple of #defines in serial.h. Looks much cleaner to me.

See the last three commits on the Gen7 branch: [github.com]

Does this work well for you? Your fork and the original repo should be pretty close now.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
October 17, 2012 11:15AM
Traumflug Wrote:
-------------------------------------------------------
> Dave, I've taken the (a bit bold) step to replace
> lufa serial with usb serial. usb_serial.{c|h} is
> now in Teacup's repository, this gets rid of the
> external dependency. If there are actually lufa
> serial users and it breaks something for them, I
> think we can work that out.
>
> I've also replaced teensy_serial.c with a couple
> of #defines in serial.h. Looks much cleaner to
> me.
>
> See the last three commits on the Gen7 branch:
> [github.com]
> /Gen7
>
> Does this work well for you? Your fork and the
> original repo should be pretty close now.


I probably can't test until the weekend, but in the meantime I fiddled with lufa_serial/makefile such that I can make a connection with pronterface. Patch attached. It comments out the dependency on Joystick.h, and makes LUFA track with the processor, speed, and board as defined in the teacup makefile.

This lufa config seems to be sending periodic '?'-marks to pronterface, and not responding reliably to M105s:

#### pronterface log of several M105 commands:
>>>m105
SENDING:M105
ok T:18.50 B:61.50
>>>m105
SENDING:M105
?
>>>m105
SENDING:M105
?
>>>m105
SENDING:M105
?
>>>m105
SENDING:M105
?
>>>m105
SENDING:M105
?
?
>>>m105
SENDING:M105
ok T:18.50 B:61.50
?
?
>>>m114
SENDING:M114
ok X:8.000,Y:-9.000,Z:2.000,E:0.000,F:7800
>>>m114
SENDING:M114
?
>>>m114
SENDING:M114
?
>>>m105
SENDING:M105
?

It seems to do jogs reliably. But reporting commands (M114, M105) seem unreliable unless one waits for the '?'. On the usb_serial side, you can send M114s and get a report as fast as you can hit the return key:

>>>m114
SENDING:M114
ok X:0.000,Y:0.000,Z:0.000,E:0.000,F:0
>>>m114
SENDING:M114
ok X:0.000,Y:0.000,Z:0.000,E:0.000,F:0
>>>m114
SENDING:M114
ok X:0.000,Y:0.000,Z:0.000,E:0.000,F:0
>>>m114
SENDING:M114
ok X:0.000,Y:0.000,Z:0.000,E:0.000,F:0
>>>m114
SENDING:M114
ok X:0.000,Y:0.000,Z:0.000,E:0.000,F:0

#####

In the future, the more monolithic usb_serial direction might be more adaptable to non-AVR processors, such as the ARM Cortex-M4 in the Teensy 3.0.

Edited 1 time(s). Last edit at 10/18/2012 10:01AM by DaveX.
Attachments:
open | download - patch_lufa.patch (3.1 KB)
Re: Project: Teacup Firmware
November 09, 2012 06:51AM
Attached is a patch to createTemperatureLookup.py to update some of the links, add some comments, and add a couple options.

I got confused about the proper choice of resistors/resistor for my electronics, and I very much like having the script calculate the resolution and self-heating power for me. The comments in the generated pointed to old code that doesn't work with r1=0 non-existent schematics, etc..., which made it hard for me to figure out what I was doing wrong (too low an R2 & used an R1 with a 100K thermistor)

Sample output:

// Thermistor lookup table for RepRap Temperature Sensor Boards (http://reprap.org/wiki/Temperature_Sensor_2_0)
// Made with createTemperatureLookup.py (https://github.com/triffid/Teacup_Firmware/blob/master/createTemperatureLookup.py)
//           (patched per [github.com])
// default thermistor lookup table
// You may be able to improve the accuracy of this table in various ways.
//   1. Measure the actual resistance of the resistor. It's "nominally" 4.7K, but that's ± 5%.
//   2. Measure the actual beta of your thermistor:[reprap.org]
//   3. Generate more table entries than you need, then trim down the ones in uninteresting ranges.
// In either case you'll have to regenerate this table, which requires python, which is difficult to install on windows.
// Since you'll have to do some testing to determine the correct temperature for your application anyway, you
// may decide that the effort isn't worth it. Who cares if it's reporting the "right" temperature as long as it's
// keeping the temperature steady enough to print, right?
// Temp*4 table from [github.com]
// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=2700 --beta=4092 --max-adc=1023 --min_adc=20 --multiplier=4 --vadc=5.0
// r0: 100000
// t0: 25
// r1: 0 (parallel with rTherm)
// r2: 2700 (series with rTherm)
// beta: 4092
// min adc: 20 at 0.09765625 V
// max adc: 1023 at 4.9951171875 V
// ADC counts from 20 to 1023 by 52
#define NUMTEMPS 21
// {ADC, temp*4 }, // temp         Rtherm     Vtherm      resolution   power
uint16_t temptable[NUMTEMPS][2] PROGMEM = {
   {  20,   1548}, //  387.20 C,       54 Ohm, 0.098 V, 5.62 C/count, 0.18mW
   {  72,   1080}, //  270.22 C,      204 Ohm, 0.352 V, 1.09 C/count, 0.61mW
   { 124,    920}, //  230.13 C,      372 Ohm, 0.605 V, 0.57 C/count, 0.99mW
   { 176,    823}, //  205.99 C,      560 Ohm, 0.859 V, 0.39 C/count, 1.32mW
   { 228,    754}, //  188.57 C,      773 Ohm, 1.113 V, 0.29 C/count, 1.60mW
   { 280,    699}, //  174.77 C,     1016 Ohm, 1.367 V, 0.24 C/count, 1.84mW
   { 332,    652}, //  163.18 C,     1295 Ohm, 1.621 V, 0.21 C/count, 2.03mW
   { 384,    612}, //  153.02 C,     1620 Ohm, 1.875 V, 0.19 C/count, 2.17mW
   { 436,    575}, //  143.82 C,     2002 Ohm, 2.129 V, 0.17 C/count, 2.26mW
   { 488,    541}, //  135.28 C,     2458 Ohm, 2.383 V, 0.16 C/count, 2.31mW
   { 540,    508}, //  127.16 C,     3012 Ohm, 2.637 V, 0.15 C/count, 2.31mW
   { 592,    477}, //  119.26 C,     3700 Ohm, 2.891 V, 0.15 C/count, 2.26mW
   { 644,    445}, //  111.43 C,     4576 Ohm, 3.145 V, 0.15 C/count, 2.16mW
   { 696,    413}, //  103.47 C,     5729 Ohm, 3.398 V, 0.16 C/count, 2.02mW
   { 748,    380}, //   95.18 C,     7317 Ohm, 3.652 V, 0.16 C/count, 1.82mW
   { 800,    344}, //   86.25 C,     9643 Ohm, 3.906 V, 0.18 C/count, 1.58mW
   { 852,    304}, //   76.21 C,    13374 Ohm, 4.160 V, 0.21 C/count, 1.29mW
   { 904,    256}, //   64.14 C,    20340 Ohm, 4.414 V, 0.26 C/count, 0.96mW
   { 956,    190}, //   47.64 C,    37959 Ohm, 4.668 V, 0.39 C/count, 0.57mW
   {1008,     55}, //   13.89 C,   170100 Ohm, 4.922 V, 1.25 C/count, 0.14mW
   {1016,      1}  //    0.44 C,   342900 Ohm, 4.961 V, 2.19 C/count, 0.07mW
};

Attachments:
open | download - teacupCTL.patch (8.6 KB)
Re: Project: Teacup Firmware
November 09, 2012 01:37PM
Excellent! Thank you, DaveX, committed to the Gen7 branch already.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
November 10, 2012 05:51PM
Here's another one for heater.c to slow down the amega32U4 10bit timer and let DEBUG report on other PWMs:

v21837:Teacup_Firmware drf$ git diff heater.c 
diff --git a/heater.c b/heater.c
index 51ed374..62998e0 100644
--- a/heater.c
+++ b/heater.c
@@ -132,7 +132,10 @@ void heater_init() {
                        TCCR4A = MASK(PWM4A) | MASK(PWM4cool smiley ; // enable A and B
                        TCCR4C = MASK(PWM4D); // and D
                        TCCR4D = MASK(WGM40); // Phase correct
-                       TCCR4B = MASK(CS40);  // no prescaler
+                       TCCR4B = MASK(CS40);  // no prescaler 16MhZ
+       #ifndef FAST_PWM
+               TCCR4B = MASK(CS40) | MASK(CS42) | MASK(CS43); // 16mhz / 4096 /256 
+       #endif
                        TC4H   = 0;           // clear high bits
                        OCR4C  = 0xff;        // 8 bit max count at top before reset
                #else
@@ -425,7 +428,7 @@ void heater_set(heater_t index, uint8_t value) {
                *(heaters[index].heater_pwm) = value;
                #ifdef  DEBUG
                if (DEBUG_PID && (debug_flags & DEBUG_PID))
-                       sersendf_P(PSTR("PWM{%u = %u}\n"), index, OCR0A);
+                       sersendf_P(PSTR("PWM{%u = %u}\n"), index, *heaters[index].heater_pwm);
                #endif
        }
        else {

Re: Project: Teacup Firmware
November 11, 2012 08:27AM
Patch applied to the Gen7 branch, thank you.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
November 14, 2012 11:53AM
Darn. I misread/mispatched the flags. The above patch makes Timer4 slow PWM be 15 Hz. It you want it to match the others' frequencies, then swap CS41 for CS42:

$ git diff -w upstream Gen7 heater.c
diff --git a/heater.c b/heater.c
index df03488..7c5b162 100644
--- a/heater.c
+++ b/heater.c
@@ -138,9 +138,9 @@ void heater_init() {
                        TCCR4A = MASK(PWM4A) | MASK(PWM4cool smiley ; // enable A and B
                        TCCR4C = MASK(PWM4D); // and D
                        TCCR4D = MASK(WGM40); // Phase correct
-                       TCCR4B = MASK(CS40);  // no prescaler
+                       TCCR4B = MASK(CS40);  // no prescaler 16MHz/256
                        #ifndef FAST_PWM
-                               TCCR4B = MASK(CS40) | MASK(CS42) | MASK(CS43); // 16mhz / 4096 /256 
+                              TCCR4B = MASK(CS40) | MASK(CS41) | MASK(CS43); // 16MHz / 1024 /256 
                        #endif
                        TC4H   = 0;           // clear high bits
                        OCR4C  = 0xff;        // 8 bit max count at top before reset


Also here's a bit more for createThermistorTable.py for creating more cut-and-pastable table chunks:

$ git diff -w upstream Gen7 createTemperatureLookup.py 
diff --git a/createTemperatureLookup.py b/createTemperatureLookup.py
index e0b9f27..c9906a5 100755
--- a/createTemperatureLookup.py
+++ b/createTemperatureLookup.py
@@ -32,6 +32,7 @@ Options:
   --min-adc=...        the minimum ADC reading to use. 
   --vadc=...            ADC reference voltage (high leg of R2) same as Vcc
   --vcc=...             Voltage divider supply (high leg of R2)  Unused
+  --table               Format data as one of an array of tables 
 
 It is suggested to generate more values than you need, and delete some of the ones in the ranges
 that aren't interesting. This will improve accuracy in the temperature ranges that are important to you.
@@ -91,9 +92,11 @@ def main(argv):
        vadc=5.0
        vcc=5.0
        mult=4
+       table=False
        
        try:
-               opts, args = getopt.getopt(argv, "h", ["help", "r0=", "t0=", "beta=", "r1=", "r2=", "max-adc=", "min-adc=", "num-temps=", "vcc=","vadc=","mult
+               opts, args = getopt.getopt(argv, "h", ["help", "r0=", "t0=", "beta=", "r1=", "r2=", "max-adc=", "min-adc=",
+                                                      "num-temps=", "vcc=","vadc=","multiplier=","table"])
        except getopt.GetoptError:
                usage()
                sys.exit(2)
@@ -124,6 +127,8 @@ def main(argv):
                        vcc = float(arg)
                elif opt == "--multiplier":
                        mult = float(arg)
+               elif opt == "--table":
+                       table = True
        if r1:
                max_adc = int(1023. * r1 / (r1 + r2))
        else:
@@ -158,8 +163,8 @@ def main(argv):
        print "// Since you'll have to do some testing to determine the correct temperature for your application anyway, you"
        print "// may decide that the effort isn't worth it. Who cares if it's reporting the \"right\" temperature as long as it's"
        print "// keeping the temperature steady enough to print, right?"
-       print "// Temp*%s table from [github.com]" %mult
-       print "// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s --min_adc=%s --multiplier=%s --vadc=%s" % (
+       print "// Temp*%s table from [github.com]" %mult
+       print "// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s --min-adc=%s --multiplier=%s --vadc=%s" % (
                r0, t0, r1, r2, beta, max_adc, min_adc, mult, vadc)
        print "// r0: %s" % (r0)
        print "// t0: %s" % (t0)
@@ -169,10 +174,15 @@ def main(argv):
        print "// min adc: %s at %s V" % (min_adc, min_adc*t.vadc/1024)
        print "// max adc: %s at %s V" % (max_adc, max_adc*t.vadc/1024)
        print "// ADC counts from {min} to {max} by {x}".format(min=min_adc, max=max_adc, x=increment)
+       if table == True:
+               print "// #define NUMTABLES 1    // These three lines open the temptable[NUMTABLES]... array"
+               print "// #define NUMTEMPS %s   //  ...   " %  (len(adcs))
+               print "// uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = { // ..."
+               print "{ //" + " Table 0 chunk for B={b}, R0={r0}, R1={r1}, R2={r2}, Vref={v}".format(par="{",b=beta,r0=r0,r1=r1,r2=r2,v=vadc) 
+       else:
        print "#define NUMTEMPS %s" % (len(adcs))
-       print "// {ADC, temp*%s }, // temp         Rtherm     Vtherm      resolution   power" % (mult)
        print "uint16_t temptable[NUMTEMPS][2] PROGMEM = {"
-
+       print "// {ADC, temp*%s }, // temp         Rtherm     Vtherm      resolution   power" % (mult)
        counter = 0
        for adc in adcs:
                counter = counter +1
@@ -183,7 +193,11 @@ def main(argv):
                resolution = ( t.temp(adc-1)-t.temp(adc) if adc>1 else t.temp(adc) -t.temp(adc+1))
                sep = (',' if counter != len(adcs) else ' ')
                print "   {%4s, %6s}%s // %7.2f C,  %7.0f Ohm, %0.3f V, %0.2f C/count, %0.2fmW" % (adc, int(t.temp(adc)*mult), sep,degC, resistance,vTherm,res
+       if table == False:
        print "};"
+       else:
+               print '}, // remove comma for last table chunk'
+               print "// };   // Closure for the temptable[NUMTABLES] array"
        
 def usage():
     print __doc__

And a third patch to automatically compute and use the dependencies for header files in the Makefile. (I got tired of make clean && make while fiddling with ThermistorTable.h)

$ git diff -w upstream/Gen7 Makefile
diff --git a/Makefile b/Makefile
index f797024..189c710 100644
--- a/Makefile
+++ b/Makefile
@@ -150,7 +151,7 @@ program: $(PROGRAM).hex config.h
        stty 115200 raw ignbrk -hup -echo ixoff < $(PROGPORT)
 
 clean: clean-subdirs
-       rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~
+       rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~ .depend
 
 clean-subdirs:
        @for dir in $(SUBDIRS); do \
@@ -180,6 +181,16 @@ functionsbysize: $(OBJ)
        @echo "  CC        [email protected]"
        @$(CC) -c $(CFLAGS) -Wa,-adhlns=$(<:.c=.al) -o [email protected] $(subst .o,.c,[email protected])
 
+
+depend: .depend
+
+.depend: $(SOURCES)
+       rm -f ./.depend
+       $(CC) $(CFLAGS) -MM $^ > ./.depend;
+
+# pull in dependency info for SOURCES files
+-include .depend
+
 %.elf: $(OBJ)
        @echo "  LINK      [email protected]"
        @$(CC) $(CFLAGS) $(LDFLAGS) -o [email protected] $^ $(LIBS)

Edited 1 time(s). Last edit at 11/14/2012 03:26PM by DaveX.
Re: Project: Teacup Firmware
November 15, 2012 07:36AM
You're quite active, DaveX. That's great!

Now, to save me some work, do the above patches have corresponding git commits?

If the 10-bit PWM timer can do 15 Hz I'd consider this to be actually better than 78 Hz, because 15 Hz is clearly out of the audible range. The non-USB ATmega timers apparently allow no such low frequency, so I had to go with the lowest one available. Perhaps I'm missing something.

Regarding the ThermistorTable: What do you think, can this be written as a, or a number of, gcc preprocessor #defines somehow? This would be a really great thing, copying thermistor table files around could go away. Just define Rtherm, R2, Beta and the preprocessor does everything required. The preprocessor can do integer maths fine and even floating point maths with constants gets optimized away, just function calls like log() should be avoided. The success of optimisation can be judged by the resulting binary size.

BTW., looking at [reprap.org] I'd consider five table entries to be sufficient, 10 entries to be plenty. The current 102 ones in one of the tables (not yours) are clearly just wasting CPU cycles ;-)


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
November 15, 2012 12:03PM
From [github.com] there is:

[github.com] for Autodependencies, but it also has some cruft and things specific to my setup.

[github.com] has the 15Hz to 60Hz change, but the whitespace doesn't match.

[github.com] and
[github.com]
do the table-code for createThermistorTable.py

Maybe it would be possible to do the thermistor-table-creating in CPP, but I sort of like the separate program for tuning the thermistor circuit. I've been generating some --num_temp=800 tables with the voltage, resistance, and resolution comments to understand the resolution tradeoffs and behavior at high & low temps, sort of like your spreadsheet, but less GUI. With TeensyBreadboard I blindly followed Nophead's [hydraraptor.blogspot.com] into using a 100K, R1+R2, 1.5V divider circuit with terrible resolution at room temperature and optimal, but relatively poor, resolution at working temps. My resolution-commented thermistor table helped me figure that out. I currently think the noise I wanted to filter out with the EWMA patch was due to insufficient resolution at room temperatures, making the +/- 1LSB error of the ADC have a significant effect on the measurement.

Perhaps a createThermistorTable.py that loops on repeated options like --BRR2=4092,100000,2179 --BRR2=4190,100000,99170 to create a complete working multi-table ThermistorTable.h would make the process less dependent on cutting and pasting and more Makefile compatible:

ThermistorTable.h: config.h
            ./createThermistorTable.h --num_temps=10 --BRR2=4092,100000,4700 --BRR2=4190,100000,10000 > [email protected]


As for saving cycles, you could probably slow down the temp-sampling an order of magnitude or so, since we're controlling a relatively slow thermal process. (oops. I didn't notice that it scanned from the beginning of the table for every sample. To scavenge cycles, maybe remember the last lookup and then scan downwards to find x0 before scanning upwards to find X1)

Edited 1 time(s). Last edit at 11/15/2012 04:18PM by DaveX.
Re: Project: Teacup Firmware
November 19, 2012 04:28PM
Thanks Dave, all three and a half patches applied. smiling smiley


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
November 27, 2012 09:58AM
I added a 3.7 ohm + 3300uF lowpass filter (fc=1/(2*pi*3.7*3300e-6)=13.0348Hz) on my ATX's +5VSB supply line and cleaned my VCC of a lot of noise. If someone needs to use the EWMA or oversampling/decimation to get stable readings, I think they ought to at least check their power supply ripple. I'm happy to give up the 0.5 volt for the reduced noise.

Mine was 25-100 mVpp with 120Hz and 50kHz+ components, now its less than 2mVpp, within noise on my cheap scope. I get stable temp readings (+/- 1 count or 1/4 degree with my setup) with no EWMA, and even without the thermistor capacitor.

I think the thermistor capacitor was smoothing the thermistor output, but the noise remained on VCC and AVCC, which, with #define REFERENCE REFERENCE_AVCC caused the readings to be noisy.

Edited 1 time(s). Last edit at 11/27/2012 10:53PM by DaveX.
Re: Project: Teacup Firmware
January 03, 2013 09:46AM
I've commited the patch part with early parsing of digits. Let's cross fingers it works.

Also committed a pair of patches wrapping EEPROM configuration. Disabling EECONFIG in config.h reduces code size by some 600 bytes.

Last not least for today, the Makefile-based build process happens in its own folder now. Much more convenient for developers and for the upcoming port to ARM.

All on the Gen7 branch.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
January 26, 2013 10:47PM
Hopefully this is an easy question. What is the best way to make the power-on pin non-inverting. I have Sanguish up and running but the power on logic for the motor driver supply is a FET controlling a relay. The FET needs +5 for ON. So the logic is non-inverting, or just the opposite of the ATX power on logic.
Re: Project: Teacup Firmware
January 27, 2013 05:37AM
Currently an inverted PS_ON pin isn't supported. The functions for the power supply are in pinio.c; shouldn't be too difficult to tweak that.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
January 27, 2013 11:14AM
Sounds good. I figured it would be a simple tweak I just couldn't find the function to change.

Thanks
Bryan
Re: Project: Teacup Firmware
February 04, 2013 03:43PM
I had a bunch of warnings during a recent compile.

I needed to upgrade my avr-gcc to get past this one:

$ make
rm -f build/depend
mkdir -p build
avr-gcc -DF_CPU=16000000L -mmcu=at90usb1287 -g -Wall -Wstrict-prototypes -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Winline -fno-move-loop-invariants -fno-tree-scev-cprop -Os -ffunction-sections -finline-functions-called-once -mcall-prologues -save-temps=obj -MM analog.c clock.c copier.c crc.c dda.c dda_maths.c dda_queue.c debug.c delay.c gcode_parse.c gcode_process.c graycode.c heater.c home.c intercom.c mendel.c pinio.c sd.c serial.c sermsg.c sersendf.c temp.c timer.c usb_serial.c watchdog.c > build/depend
avr-gcc: unrecognized option '-save-temps=obj'
...



Then, for USB chips, with the new compiler, it looks like HOST is predefined for USB-type chips for the Mac AVR 4.6.2 :

v21837:TeacupTriffidGen7_20130204 drf$ make
rm -f build/depend
mkdir -p build
avr-gcc -DF_CPU=16000000L -mmcu=at90usb1286 -g -Wall -Wstrict-prototypes -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Winline -fno-move-loop-invariants -fno-tree-scev-cprop -Os -ffunction-sections -finline-functions-called-once -mcall-prologues -save-temps=obj -MM analog.c clock.c copier.c crc.c dda.c dda_maths.c dda_queue.c debug.c delay.c gcode_parse.c gcode_process.c graycode.c heater.c home.c intercom.c mendel.c pinio.c sd.c serial.c sermsg.c sersendf.c temp.c timer.c usb_serial.c watchdog.c > build/depend
  CC        build/analog.o
In file included from temp.h:4:0,
                 from analog.c:7:
config.h:46:0: warning: "HOST" redefined [enabled by default]
/usr/local/CrossPack-AVR-20121207/lib/gcc/avr/4.6.2/../../../../avr/include/avr/iousbxx6_7.h:951:0: note: this is the location of the previous definition
  CC        build/clock.o
....

Also, I had errors for non-'const' bits in usb_serial:

...
  CC        build/usb_serial.o
usb_serial.c:155:8: warning: type defaults to 'int' in declaration of 'prog_uint8_t' [enabled by default]
usb_serial.c:155:8: error: variable 'prog_uint8_t' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:155:50: error: expected ',' or ';' before 'device_descriptor'
usb_serial.c:173:45: error: variable 'config1_descriptor' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:257:73: error: variable 'string0' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:262:73: error: variable 'string1' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:267:73: error: variable 'string2' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:272:73: error: variable 'string3' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:285:32: error: variable 'descriptor_list' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usb_serial.c:286:19: error: 'device_descriptor' undeclared here (not in a function)
...


The patch attached changes HOST to MOTHERBOARD and adds some 'const's to the USB descriptors. It also treats __AVR_AT90USB1286__ processors like __AVR_AT90USB1287__ chips so I could compile for the AT90USB1286 on a Teensy++2.0, which should be compatible with the AT90USB1287 in the teensylu/printrboard family.

This compiles on my mac, loads into my Teensy++2.0, and communicates with Pronterface, but I've not tested it connected with a printer yet. (Edited to post a 10.6kb patch that changes the .c files as well.)

What hardware are folks using with the arduino_usb1287.h / MCU_TARGET = at90usb1287 configuration of Teacup? It seems like it might be for an AT90USBKEY, but that file doesn't seem match the teensylu or printrboard.

Edited 2 time(s). Last edit at 02/04/2013 07:31PM by DaveX.
Attachments:
open | download - JUNK_TeacupAVR.patch (10.6 KB)
Re: Project: Teacup Firmware
February 05, 2013 08:20AM
Quote

What hardware are folks using with the arduino_usb1287.h / MCU_TARGET = at90usb1287 configuration of Teacup?

Can't tell that, maybe it was some custom made electronics. Nevetheless I applied your patch, except the Makefile change (which is a personal preference, only). Thanks a lot!


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
February 05, 2013 11:09AM
Traumflug Wrote:
-------------------------------------------------------
> What hardware are folks using with the
> arduino_usb1287.h / MCU_TARGET = at90usb1287
> configuration of Teacup?
>
> Can't tell that, maybe it was some custom made
> electronics. Nevetheless I applied your patch,
> except the Makefile change (which is a personal
> preference, only). Thanks a lot!

Thanks. When I was looking at the arduino_usb1287.h, it didn't seem to match the Teensy++2.0 pin mapping, which is what it looks like Teensylu and Printrboard use. Sprinter's [github.com] or
Marlin's lincomatic fork [github.com] look like teensyduino mappings for those firmwares.

Maybe arduino_usb1287.h was built for AT90USBKEY hardware? It seems like the 1287 chip is does host-mode USB, while the 1286 does device mode USB.

Attached is a patch with and arduino_usb1286.h mapping that works for me and might work with Teensyu and Printrboard hardware. The port->pin->signal mapping in the arduino_*.h and config.*.h design make sense for the DIP AVRs, but for SMD devices, it might be a bit confusing. The Printrboard and Teensylu boards configurations for Marlin:MOTHERBOARD=(8|81) and Sprinter:MOTHERBOARD=(8|9) seem to use the Teensyduino mappings.

It compiles and runs on a Teensy++2.0 with the attached patch.
All the non-timer1 PWMs seem to work (per DEBUG M111 S1 in pronterface) on the bare driverboard, but I didn't actually have them attached to circuitry.

Edited 4 time(s). Last edit at 02/06/2013 06:17PM by DaveX.
Attachments:
open | download - Addusb1286.patch (44.1 KB)
open | download - arduino_usb1286.h (14.2 KB)
Re: Project: Teacup Firmware
February 10, 2013 07:30AM
Thanks for the contribution, Dave. I just applied the patch to the Gen7 branch.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Project: Teacup Firmware
February 18, 2013 12:32PM
From Cyberwizard's Lookahead code per [github.com] and [github.com] I've made a patch that seems to print on my atmega32u.

I cut out the leading-axis-tracking, since it didn't seem to be actually using it & was giving me a warning, cuts out some of the emergency-stop code, and compiles and works for !defined LOOKAHEAD path.

It doesn't patch all the config.*.h files--only the config.teensy.h file is tested with actual hardware and filament.

Cyberwizzard's LOOKAHEAD code seems to work better with my mushy, laggy hotend.
Attachments:
open | download - lookahead.patch (40.8 KB)
Sorry, only registered users may post in this forum.

Click here to login