Shop OBEX P1 Docs P2 Docs Learn Events
The Teacup Port - A Work In Progress - 3D Printer Firmware - Page 4 — Parallax Forums

The Teacup Port - A Work In Progress - 3D Printer Firmware

1246789

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-12 06:55
    I looked at timer.c and it's full of AVR stuff. It seems like you should just study it, and then write a version of timer.c that is specific to the Prop. It appears that the code sets flags, which are then reset by other parts of the Teacup code, so if your lucky there won't be any concurrency issues. Look at timer_ext.c in the simulator directory to see how it's done for the simulator. However, I wouldn't use this version either since it relies on the C library time functions. You should be able to create much more efficient and compact code if you just rely on the Prop counter for timing information.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 10:39
    Dave

    I have the clock timer done already, now I only need the step timer.

    However, I utilized four new files to accomplish the new timer, which are clock_timer.c, clock_timer.h, time_clock.c, and time_clock.h. By introducing these four new files, I have acquired two new warnings. Any possibility that you could take a peek and tell me how to get rid of them? I am not sure where they are coming in. I have attached a new archive with the four files included.
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-12 11:04
    Your new C files have a .cpp extension. Change them to .c and it will compile OK.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 11:14
    Dave
    Your new C files have a .cpp extension. Change them to .c and it will compile OK.

    LOL... I don't know how I missed that obvious error, when it was staring right at me :) A second set of eyes is always a wonderful thing.

    I do all of my editing in VS, within a stripped down MFC project, so naturally when I create new source files, they always have the *.cpp extension.

    Good catch Dave and thanks for taking a peek.

    Bruce
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-12 11:25
    idbruce wrote: »
    I do all of my editing in VS

    Whenever you get around to learning Git & Github, be sure to check out integration with VS. It can certainly make life easier if you prefer to avoid command lines.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-12 11:29
    Nobody writing code should be afraid of command lines.

    I mean, every line of their source code is a command line. Of sorts.

    What's the problem?
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-12 12:09
    You might not understand it (I don't) - but you can't deny that some do.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 13:36
    In timer.c, within the ISR(TIMER1_COMPA_vect) and the void setTimer(uint32_t delay) functions, it almost appears that CNT should be assigned to OCR1A, and then various values would be added to it. At this point, I am just making a comment.
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-12 14:20
    I thought you replaced timer.c by clock_timer.c so you wouldn't need to mess with any AVR stuff. There shouldn't be any reason to set OCR1A to anything.

    I'm curious why you merged the code in the routine clock_tick() into the interrupt routine. Why not just call clock_tick from the routine? That way you don't have to change the clock.c file. Also you probably want to use a variable to hold the target count value, otherwise your loop will take slightly longer than TICK_TIME clock cycles. So the routine would look like this:
    void clock_timer(void *par)
    {
      int count = CNT;
      while(1)
      {
        waitcnt(count += TICK_TIME);
        clock_tick();
        dda_clock();
      }
    }   
    
    Also, your code is adding TICK_TIME to clock_counter_10ms. It should add TICK_TIME_MS.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 18:08
    Dave
    I thought you replaced timer.c by clock_timer.c so you wouldn't need to mess with any AVR stuff. There shouldn't be any reason to set OCR1A to anything
    I have the clock timer done already, now I only need the step timer.

    There are two (2) timers in timer.c,
    /// comparator B is the system clock, happens every TICK_TIME
    ISR(TIMER1_COMPB_vect)
    {
    
    /// comparator A is the step timer. It has higher priority then B.
    ISR(TIMER1_COMPA_vect)
    {
    
    So the routine would look like this:

    Not so fast, you are missing the key aspect of that fuction, which is altering the various clock flags, for the different time intervals. First the flags are set, then you call dda_clock().
    Also, your code is adding TICK_TIME to clock_counter_10ms. It should add TICK_TIME_MS.

    Yep, that was a blunder on my part. I am thankful you caught that. However, I will have to go back and review some of my earlier comments in the thread, because that may be a ket limiting factor in the speed of the firmware.

    EDIT: However, the TICK_TIME code should work just fine, because it is only determining 10MS, 250MS, and 1S intervals. In clock_timer.h, TICK_TIME is defined as follows:
    /// How often we update our clock.
    #define TICK_TIME (2 * ms)
    

    EDIT: On another look, "#define TICK_TIME (2 * ms)". I will have to rework that.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 18:45
    So clock_timer.c should look like this:
    /// maintain state of the clock flags
    void clock_timer(void *par)
    {
    	while(1)
    	{
    		waitcnt(ms + CNT);
    
    		clock_counter_10ms += TICK_TIME;
    
    		if(clock_counter_10ms >= 10)
    		{
    			clock_counter_10ms -= 10;
    			clock_flag_10ms = 1;
    
    			clock_counter_250ms++;
    
    			if(clock_counter_250ms >= 25)
    			{
    				clock_counter_250ms = 0;
    				clock_flag_250ms = 1;
    
    				clock_counter_1s++;
    
    				if(clock_counter_1s >= 4)
    				{
    					clock_counter_1s = 0;
    					clock_flag_1s = 1;
    				}
    			}
    		}
    
    		dda_clock();
    	}                            
    }
    

    And the #define in clock_timer.h should look like this:
    #define TICK_TIME 1
    
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-12 18:51
    TICK_TIME is the number of clock cycles per tick. TICK_TIME_MS is the number of milli-seconds per tick, which is set to 2 in the Teacup code.

    The various clock flags are updated in the clock_tick routine in clock.c.

    I noticed the second timer routine is used only if MOTHERBOARD is defined. I'm not sure what the MOTHERBOARD flag is, but it seems to determine how the code interfaces to the 3D printer. I'll take a look at the second timer routine. I think it can be implemented in the same cog as the other timer.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 18:59
    Dave
    TICK_TIME is the number of clock cycles per tick.

    TICK_TIME is what I say it is :) And I say it is an incrementor of 1. :) Representing 1 MS.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 19:04
    Dave

    The MOTHERBOARD is the various AVR boards that can be utilized.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 19:26
    Dave
    The various clock flags are updated in the clock_tick routine in clock.c.

    You are correct. So I need to change the comment of "/// maintain state of the clock flags" to "/// set state of the clock flags".

    EDIT: However, clock.c will no longer exist, since it is replaced by time_clock.c
    EDIT: The file name was changed due to conflicts with a prop-GCC file named clock.h
  • idbruceidbruce Posts: 6,197
    edited 2015-03-13 05:51
    Whie it is true, that every portion of this port is important, from my standpoint, there are two portions that are more important than any others. The first being the macros that Dave and I worked on, which converted AVR support to Propeller support for all of the IO pins being utilized. Without that conversion, the port wouldn't even be a possibility. The second most important part of the port, is the portion that I am now working on, which is the conversion of AVR support to Propeller support for generating step pulses. Without the proper step pulses, the firmware will be useless.

    For those that may be following along, an understanding of AVR timers is essential to successfully porting this key portion of source code. To help educate myself, I will be using two or more references, but I am adding links to two of the references that I have found most helpful, so that others may also learn and participate in the ensuing discussion.

    AVR130: Setup and Use the AVR® Timers - http://www.atmel.com/Images/doc2505.pdf
    COMMON TIMER/COUNTER THEORY - https://sites.google.com/site/qeewiki/books/avr-guide/common-timer-theory

    The knowledge gained from these resources, and perhaps others, will be used to port the following code to the Propeller chip.

    EDIT: Additionally, I am also including an archive of the last build. This archive represents the current status of this project and port. At the current point, this project will build without error or warning.
    /// initialise timer and enable system clock interrupt.
    /// step interrupt is enabled later when we start using it
    void timer_init()
    {
    	// no outputs
    	TCCR1A = 0;
    }
    
    /// comparator A is the step timer. It has higher priority then B.
    ISR(TIMER1_COMPA_vect)
    {
    	// Check if this is a real step, or just a next_step_time "overflow"
    	if(next_step_time < 65536)
    	{
    		// disable this interrupt. if we set a new timeout, it will be re-enabled when appropriate
    		TIMSK1 &= ~MASK(OCIE1A);
    		
    		// stepper tick
    		queue_step();
    
    		return;
    	}
    
    	next_step_time -= 65536;
    
    	// similar algorithm as described in setTimer below.
    	if(next_step_time < 65536)
    	{
    		OCR1A = (OCR1A + next_step_time) & 0xFFFF;
    	}
    	else if(next_step_time < 75536)
    	{
    		OCR1A = (OCR1A - 10000) & 0xFFFF;
    		next_step_time += 10000;
    	} // leave OCR1A as it was
    }
    
    /*! Specify how long until the step timer should fire.
    	\param delay in CPU ticks
    
    	This enables the step interrupt, but also disables interrupts globally.
    	So, if you use it from inside the step interrupt, make sure to do so
    	as late as possible. If you use it from outside the step interrupt,
    	do a sei() after it to make the interrupt actually fire.
    */
    void setTimer(uint32_t delay)
    {
    	uint16_t step_start = 0;
    
    	// Assume all steps belong to one move. Within one move the delay is
    	// from one step to the next one, which should be more or less the same
    	// as from one step interrupt to the next one. The last step interrupt happend
    	// at OCR1A, so start delay from there.
    	step_start = OCR1A;
    	next_step_time = delay;
    
    	// Now we know how long we actually want to delay, so set the timer.
    	if(next_step_time < 65536)
    	{
    		// set the comparator directly to the next real step
    		OCR1A = (next_step_time + step_start) & 0xFFFF;
    	}
    	else if(next_step_time < 75536)
    	{
    		// Next comparator interrupt would have to trigger another
    		// interrupt within a short time (possibly within 1 cycle).
    		// Avoid the impossible by firing the interrupt earlier.
    		OCR1A = (step_start - 10000) & 0xFFFF;
    		next_step_time += 10000;
    	}
    	else
    	{
    		OCR1A = step_start;
    	}
    
    	// Enable this interrupt, but only do it after disabling
    	// global interrupts (see above). This will cause push any possible
    	// timer1a interrupt to the far side of the return, protecting the 
    	// stack from recursively clobbering memory.
    	TIMSK1 |= MASK(OCIE1A);
    }
    

    Source: Teacup Firmware (See post #1 of this thread for licensing information)
  • idbruceidbruce Posts: 6,197
    edited 2015-03-13 12:47
    Dave

    Since this is the most appropriate place for this information, I am placing it here.

    In reference to our discussion pertaining to F_CPU in the timer thread, there are only six references in the remaining portions of the firmware archived above. Most of these references, with the exception of one, are located within the dda_create function of dda.c With the last remaining reference being used within a define of dda_maths.h.

    If these formulas were rewritten, I am certain that F_CPU could equal 80MHz, provided there is no overflow, and at which point, I believe if written properly, CNT could be used for the timer.
    dda.c(283):
    // changed * 10 to * (F_CPU / 100000) so we can work in cpu_ticks rather than microseconds.
    // timer.c setTimer() routine altered for same reason
    
    dda.c(286 - 288):
    // changed distance * 6000 .. * F_CPU / 100000 to
    // distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing
    uint32_t move_duration = ((distance * 2400) / dda->total_steps) * (F_CPU / 40000);
    
    dda.c(299):
    c_limit_calc = ((x_delta_um * 2400L) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_X) << 8;
    
    dda.c(307):
    c_limit_calc = ((y_delta_um * 2400L) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Y) << 8;
    
    dda.c(315):
    c_limit_calc = ((z_delta_um * 2400L) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Z) << 8;
    
    dda.c(323):
    c_limit_calc = ((e_delta_um * 2400L) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_E) << 8;
    
    dda_maths.h(86):
    #define C0 (((uint32_t)((double)F_CPU / sqrt((double)(STEPS_PER_M_X * ACCELERATION / 2000.)))) << 8)
    

    Source: Teacup Firmware (See post #1 of this thread for licensing information)

    EDIT: On second thought, there is more to it then that..... SetTimer and that value must also be taken into consideration.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-13 21:08
    Dave

    If you get a chance, I would appreciate it, if you could explain this a little more in depth.
    Bruce, the simple answer to your question is to set F_CPU to 20MHz, and then derive your 16-bit counter from CNT using ((CNT >> 2) & 0xffff).
  • idbruceidbruce Posts: 6,197
    edited 2015-03-14 02:22
    Okay....

    I do believe I have a much better grasp of implementing this timer stuff. I was just letting all that AVR mumbo jumbo stuff scare me so much that I failed to see the obvious, I mean it was staring right at and I never even noticed.

    void setTimer(uint32_t delay)

    Will you look at that? The delay parameter is type uint32_t :) This means I should just be able to just add it to CNT :) Which further means that the Teacup firmware should be able to run at 80MHz :)

    Or at least, such is my belief :) However I could be wrong :(
  • idbruceidbruce Posts: 6,197
    edited 2015-03-14 13:35
    Sorry folks

    I went outside of the realm of this thread seeking information pertaining to timers. For the sake of completeness, I am adding a link to that discussion

    http://forums.parallax.com/showthread.php/160416-Duplicating-A-16-bit-Timer-At-16MHz
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-14 20:07
    Bruce, here's the teacup coding running in the simulator mode on the Prop. The Prop-specific timer stuff is in simulator/timer_ext.c. I created a 64-bit timer that consists of CNT in the lower 32 bits, and the number of times CNT has wrapped in the upper 32 bits. This can be simplified to just 16 bits, but I implemented the 64-bit counter because the simulator uses the nanosecond version for debug purposes.

    The program reads the G-Code info from the serial port. I tried the triangle.gcode data and the program outputs data. I think the extra control characters in the output are for setting the display color, which is ignored in the SimpleIDE terminal. The triangle.gcode data is as follows:
    G21
    G90
    G1 X5 F800
    G1 X0
    G1 X20
    G1 X40 Y20
    G1 X0 Y0
    M2
    
  • idbruceidbruce Posts: 6,197
    edited 2015-03-14 23:14
    Dave

    Okay I downloaded it and built it, but... I still have not figure out the proper way to send data through SimpleIDE. Do you just paste it to the terminal?

    EDIT: 64-bit timer interesting.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-15 00:43
    Dave

    I am not saying that this will definitely work at 80MHz, but I think it will.

    Source
    // File created 03/15/2015 with four space tab spacing
    
    /** \file
    	\brief step timer management
    */
    
    #include "step_timer.h"
    #include "simpletools.h"
    #include "dda_queue.h"
    
    /// cog variables
    static int cog = 0;
    static int stack[60];
    
    /// time until next step
    static uint32_t next_step_time;
    
    void step_timer(void *par);
    
    /// initialise timer
    void step_timer_init()
    {
    	next_step_time = 0;
    
    	if(cog == 0)
    	{
    		cog = 1 + cogstart(&step_timer, NULL, stack, sizeof stack);
    	}
    }
    
    /// stop timer
    void step_timer_stop()
    {
    	if(cog > 0)
    	{
    		cogstop(cog - 1);
    		cog = 0;
    	}
    }
    
    /// main loop for queueing step
    void step_timer(void *par)
    {
    	while(1)
    	{
    		waitcnt(next_step_time);
     
    		// Check if this is a real step, or just passing time
    		if(next_step_time > 0)
    		{
    			queue_step();
    			next_step_time = 0;
    		}
    	}
    }
    
    void setTimer(uint32_t delay)
    {
    	next_step_time = (delay += CNT);
    }
    


    Header
    // File created 03/15/2015 with four space tab spacing
    
    #ifndef _STEP_TIMER_H
    #define _STEP_TIMER_H
    
    #include <stdint.h>
    
    /*
    timer stuff
    */
    void step_timer_init(void);
    void step_timer_stop(void);
    void setTimer(uint32_t delay);
    
    #endif /* _STEP_TIMER_H */
    
  • idbruceidbruce Posts: 6,197
    edited 2015-03-15 03:22
    Well it appears that I have some decisions to make :(

    With the intended main portion uncommented, and DEBUG and LOOKAHEAD enabled, there is hub ram overflow. :(
    Project Directory: C:/Documents and Settings/Bruce/My Documents/SimpleIDE/My Projects/Forger/
    
    SimpleIDE Version 1.0.2
    C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/
    C:/Documents and Settings/Bruce/My Documents/SimpleIDE/ Updated on: 2015-02-14
    
    propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2408)
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda.c -o cmm/dda.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda_lookahead.c -o cmm/dda_lookahead.o
    dda_lookahead.c: In function 'dda_join_moves':
    dda_lookahead.c:419:8: warning: 'crossF' may be used uninitialized in this function [-Wuninitialized]
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda_maths.c -o cmm/dda_maths.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda_queue.c -o cmm/dda_queue.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c debug.c -o cmm/debug.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c gcode_parse.c -o cmm/gcode_parse.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c gcode_process.c -o cmm/gcode_process.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c home.c -o cmm/home.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c pinio.c -o cmm/pinio.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c sergcode.c -o cmm/sergcode.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c Adafruit_ADS1015.c -o cmm/Adafruit_ADS1015.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c clock_timer.c -o cmm/clock_timer.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c time_clock.c -o cmm/time_clock.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c step_timer.c -o cmm/step_timer.o
    propeller-elf-gcc.exe -I . -L . -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libsimpletext/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial -L C:/Documents and Settings/Bruce/My Documents/SimpleIDE/Learn/Simple Libraries/TextDevices/libfdserial/cmm/ -o cmm/Forger.elf -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 cmm/dda.o cmm/dda_lookahead.o cmm/dda_maths.o cmm/dda_queue.o cmm/debug.o cmm/gcode_parse.o cmm/gcode_process.o cmm/home.o cmm/pinio.o cmm/sergcode.o cmm/Adafruit_ADS1015.o cmm/clock_timer.o cmm/time_clock.o cmm/step_timer.o -ffunction-sections -fdata-sections -Wl,--gc-sections Forger.c -lsimpletools -lsimpletext -lsimplei2c -lfdserial -lsimpletools -lsimpletext -lsimplei2c -lsimpletools -lsimpletext -lsimpletools
    Forger.c: In function 'parse_sd':
    Forger.c:215:3: warning: 'c' may be used uninitialized in this function [-Wuninitialized]
    c:/program files/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld.exe: cmm/Forger.elf section `.bss' will not fit in region `hub'
    c:/program files/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld.exe: region `hub' overflowed by 1656 bytes
    collect2: ld returned 1 exit status
    Done. Build Failed!
    
    Your program is too big for the memory model selected in the project.
    
  • idbruceidbruce Posts: 6,197
    edited 2015-03-15 03:59
    As mentioned in the previous post, the program is currently too large by 1656 bytes, and without a doubt, it will need to have extra code added, for heater maintenance. In addition, if the program is run from a serial port, this will also increase program size.

    In this projects current status (archived below), DEBUG, LOOKAHEAD, and GCODE_SD are enabled in the config.h file. There are two new warnings, in addition to the build error.

    By simply disabling LOOKAHEAD, the program will fit, however, I consider LOOKAHEAD a necessity.

    Even though this program currently unusable, I believe it is very close to being fully fucntional. As I see it, this program is at the bare minimum to becoming a nice piece of firmware, and by removing any existing code, the firmware will be severely hampered.

    1) Is there any way to further optimize the existing code, to cut down the size?
    2) In addition to the SD card, which I do not want to use to solve this problem, I also have 4MB of flash memory and 128KB of SRAM available. How can I use these resources to overcome this problem.

    Anyhow here is the archive (not working).



    ####WARNING######
    If you decide to work on this project, please ensure that you set the proper IO pins in config.h!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Dave HeinDave Hein Posts: 6,347
    edited 2015-03-15 05:53
    Bruce, I found a problem in my conversion from 80MHz cycles to nano-second cycles. I divided by 12.5 instead of multiplying times 12.5. The corrected timer_ext.c is attached below along with a modified simulator.c. I turned off the debug prints, and moved the definitions for DEFAULT_TIME_SCALE, verbose, trace_gcode and trace_pos to the beginning of simulator.c. If DEFAULT_TIME_SCALE is 0 the program will run as fast as it can. Otherwise the program will run at 1/DEFAULT_TIME_SCALE times real-time speed.

    The code in timer_ext.c runs in a polling mode, where it must be called periodically from the rest of the teacup code. This done by calling sim_time_warp, which is called from the clock function. The advantage to using the polling mode is that the code is single threaded, and runs on one cog. If this isn't fast enough then the code in timer_ext.c would need to run in a separate cog.

    BTW, I enter data just by typing it in. Eventually you will either need to read a file or use a serial port. Reading a file will probably not fit in CMM mode, and you would need to go with XMMC mode. If you don't use files you can remove the file-related code and save some memory.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-15 09:51
    With the following configuration in config.h:
      LOOKAHEAD disabled
      DEBUG enabled
      GCODE_SD enabled

    and with the debug flags now set in the main function as follows:
    	debug_flags |= DEBUG_PID;
    	debug_flags |= DEBUG_DDA;
    	debug_flags |= DEBUG_POSITION;
    	debug_flags |= DEBUG_ECHO;
    

    and reading a GCODE file from the sd card, we now have terminal output :) I must admit it is not working properly, but hey, that is what debug is for :)


    ####WARNING######
    If you decide to run this project, please ensure that you set the proper IO pins in config.h!!!!!!!!!!!!!!!!!!!!!!!!!!!


    Project archive attached below. I am also including a very small GCODE file. Some of the M codes within this file are not supported by Forger. A quick list thrown together shows support for the following codes:
    G0, G1, G4, G20, G21, G28, 
    G30, G90, G91, G92, G161, G162
    
    M0, M2, M3, M5, M6, M7, M82, M83, 
    M84, M101, M103, M104, M105, M106, 
    M110, M111, M112, M114, M115, M116, 
    M119, M130, M131, M132, M133, M134, 
    M136, M140, M240, M241
    
  • idbruceidbruce Posts: 6,197
    edited 2015-03-16 04:14
    I have been taking it easy for the past couple of days, but today, I will be diving in deep once again. I will be seeking out problems that will prevent this firmware from working.

    T o assist me during the debugging process, I will be altering the GCODE test file that I attached above, and after each G1 command, I will be entering a M114 command. This particular command, instructs Forger to report it's current physical position, or in this case, theorhetical physical position. I have not altered the file yet, but when I do, I will amend and attach it to this post.

    As mentioned above, Teacup will not fit into the hub, without disabling LOOKAHEAD. I have decided to move ahead with this project, by resolving other errors, which prevent this firmware from working. When I start getting expected results, from the debugging process, indicating that the firmwarm is functional, then I will attempt to resolve the LOOKAHEAD problem.

    EDIT: Here is the altered GCODE file that I mentioned above, which includes the M114 commands. It now spits out more data, as intended.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-16 12:16
    As it pertains to the last couple of posts.....

    I started the day with good intentions, but as I tried to decipher the terminal output, I became a little flustered, because the output was a mess. So I decided to rewrite portions of the debugging code, so that it would be easier to understand. The archive below contains the results of this endeavor. It is definitely much more comprehendable, and definitely much easier to read.

    With the following configuration set in config.h:
      LOOKAHEAD disabled
      DEBUG enabled
      GCODE_SD enabled

    and with the debug flags now set in the main function as follows:
    	debug_flags |= DEBUG_STEP;
    	debug_flags |= DEBUG_DDA;
    	debug_flags |= DEBUG_POSITION;
    	debug_flags |= DEBUG_ECHO;
    

    and reading a GCODE file from the sd card, we now have much better terminal output.


    ####WARNING######
    If you decide to run this project, please ensure that you set the proper IO pins in config.h!!!!!!!!!!!!!!!!!!!!!!!!!!!


    Additionally, I am also including a different GCODE file for debugging purposes, with the empty lines, comments, and the unsupported M codes removed.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-16 17:27
    I do believe there is a problem with the dda_create function, in fact I know there is one at least, and it is not my fault :)

    If you look at the second DEBUG print command, there are references to a DDA pointer named endpoint. The actual ENDPOINT for creating this DDA, is contained within the "target" parameter of dda_create. And the "dda" parameter of dda_create, is a pointer to a DDA structure, passed from the queue, and the associated values from the "target" parameter are intended to fill the "dda" values for the queue. The first reference to DEBUG is what the second reference to DEBUG should actually look like, or should I say that I am 99.99% positive.

    EDIT: Try adding that first debug to the source code and see the output from that
    void dda_create(DDA *dda, TARGET *target)
    {
    	if(DEBUG_DDA && (debug_flags & DEBUG_DDA))
    	{
    		print("Incoming Target: X:%d,Y:%d,Z:%d,E:%d,F:%d,E_Relative:%d\n", 
    			target->X, target->Y, target->Z, target->E, target->F, target->e_relative);
    	}
    
    	uint32_t steps;
    	uint32_t x_delta_um;
    	uint32_t y_delta_um;
    	uint32_t z_delta_um;
    	uint32_t e_delta_um;
    	uint32_t distance;
    	uint32_t c_limit;
    	uint32_t c_limit_calc;
    
    	#ifdef LOOKAHEAD  
    
    	// Number the moves to identify them; allowed to overflow.
    	static uint8_t idcnt = 0;
    	static DDA* prev_dda = NULL;
    
    	if((prev_dda && prev_dda->done) || dda->waitfor_temp)
    	{
    		prev_dda = NULL;
    	}
    
    	#endif
    
    	if(dda->waitfor_temp)
    	{
    		return;
    	}
    
    	if(DEBUG_DDA && (debug_flags & DEBUG_DDA))
    	{
    		print("Create: X:%d,Y:%d,Z:%d,F:%u\n",
    			dda->endpoint.X, dda->endpoint.Y, dda->endpoint.Z, dda->endpoint.F);
    	}
    
    Source: Teacup Firmware
Sign In or Register to comment.