How can I find the right files on Github?

Code hacking talk

How can I find the right files on Github?

Postby RetireeJay » 2013-Jul-Tue-14-Jul

As far as software modification goes, consider me an absolute newbie. Or even before and below that level ;) The last time I burned new software into an EPROM it was a 2K UV-erasable chip, and I wrote ALL of the code that went into it -- in Assembly. Decades ago.

But... I am thinking of trying to hook up independent motor controllers for my Z axis. And I think the best way to do it would be to redefine three of the pins that are wired to a header already on the board, and use external Pololu motor drivers.

<Aside> Why? I discovered that when I have only one motor connected (the carriage supported out of the way) that I can run the motor up to a speed of 20mm/sec whereas with both motors connected I can't go above 5mm/sec. This is with the motors wired either in parallel or in series. I did cut one of the microstepping jumpers so I'm using 4 microsteps instead of 16 so as not to overload the microprocessor sending out gazillions of step pulses, but the actual speed I could realize at the motors didn't change a bit! </Aside>

So, I go browsing through the software and find this file in PxT's Marlin github site: https://github.com/PxT/Marlin/blob/master/Marlin/pins.h

I have the schematic for the board in front of me, and it shows the Z axis controller pins as follows:
Z-STEP = Pin 47 = PA4-AD4
Z-DIR = Pin 46 = PA5-AD5
Z-ENABLE = Pin 42 = PC7_A15_IC3_CLK0

But in pins.h, I can't find anyplace where the same pin definitions are used. There are several variants (I guess for different board types) but never this one. (I have a standard Printrboard from PB, running standard software for the PB Plus.)

So if I wanted to make a change to the Z pin definitions, how would I do it? What lines in pins.h would I need to modify?
  • 0

Printrbot Plus operational January 2013
Brass threaded rods (5/16" X 18) & nuts for Z axis
GT2 belts & pulleys
Cable chain to reduce probability of fatigue failure in wires
E3D V5 Hot End, 0.4mm nozzle, also 0.8 and 0.25 in use occasionally
PB fan mount + 40mm fan -- using printed mount adapter, not the E3D supplied fan
Injection molded extruder gears
Optical Z "endstop" (custom designed and built)
Have used many pounds of T-Glase filament. Now also doing some work with Ninjaflex SemiFlex
Print on glass with Scotch Craft Stick or other glue stick
User avatar
RetireeJay
My next printer is...
 
Posts: 4830
Joined: 2013-Jan-Wed-13-Jan
Location: Greenville, SC
Reputation: 478

How can I find the right files on Github?

Sponsor

Sponsor
 

Re: How can I find the right files on Github?

Postby Bob-StPaul » 2013-Jul-Sat-02-Jul

Is this so you can get up some good speed before crashing the head into the print bed? :)

Do you often find the z axis moves too slow? (that's actually a serious question.)
  • 0

My printer:
Printrbot JR w/ fan and metric threaded rods.
Bob-StPaul
Waiting for printbed temp...
 
Posts: 137
Joined: 2013-Feb-Wed-17-Feb
Reputation: 2

Re: How can I find the right files on Github?

Postby RetireeJay » 2013-Jul-Sat-07-Jul

When printing with nylon, ooze is a factor, so time spent not extruding is time spent oozing. If I wanted to use z-retraction, I'd want to minimize the time.
Also, its just tedious waiting for the printhead to raise or lower. I typically set it at least 30mm above the printhead at the start of a session, so I can load in the filament and get the printhead "primed".

But, really, this is a software question. I've never programmed in C and I find the huge collection of files quite confusing. I would like to be able to confidently work with the software someday, but I can't even take a baby step. I can't even find the configuration file that sets up the pin assignments for my printer - or else I don't understand how the pin assignments "map" between what's shown in the software and what's shown in the schematic.
  • 0

Printrbot Plus operational January 2013
Brass threaded rods (5/16" X 18) & nuts for Z axis
GT2 belts & pulleys
Cable chain to reduce probability of fatigue failure in wires
E3D V5 Hot End, 0.4mm nozzle, also 0.8 and 0.25 in use occasionally
PB fan mount + 40mm fan -- using printed mount adapter, not the E3D supplied fan
Injection molded extruder gears
Optical Z "endstop" (custom designed and built)
Have used many pounds of T-Glase filament. Now also doing some work with Ninjaflex SemiFlex
Print on glass with Scotch Craft Stick or other glue stick
User avatar
RetireeJay
My next printer is...
 
Posts: 4830
Joined: 2013-Jan-Wed-13-Jan
Location: Greenville, SC
Reputation: 478

Re: How can I find the right files on Github?

Postby extent » 2013-Jul-Sat-08-Jul

The pins referenced in the config are Arduino pin definitions, which provides an abstraction layer between your software pins (in marlin) and the actual hardware pins (on the Atmel, on the schematic). The microcontroller is split up into 8 bit ports, which is what the pin in the schematic is referring to. PA4 = Port A, pin(or bit) 4. To use an arbitrary pin you'll need to find out what arduino pin number that maps to for whichever micro is used on the printrboard.

For any pin that's used in the default configuration you can just search the pins.h file for "printrboard" and see what number each is assigned to already. There's only one section in the file that refers to the printrboard, all it's info is right there.

any pin set to -1 in the config is disabled, that's not an actual pin assignment.
  • 0

backer #48
extent
Printing skirt...
 
Posts: 150
Joined: 2012-May-Thu-03-May
Reputation: 6

Re: How can I find the right files on Github?

Postby RetireeJay » 2013-Jul-Sat-09-Jul

OK, so on the schematic it seems like they are showing both the "abstraction layer" and the actual pinout.

Z pinout.JPG


In other words, Port A, bit 4 (also called AD4) shows up on physical pin 47 and is called "Z-STEP" on the Printrboard (going to the Z motor controller "Step" input).
Port A, bit 5 (also called AD5) is connected to physical pin 46 and is called "Z-DIR" on the Printrboard.

However, here is what https://github.com/PxT/Marlin/blob/master/Marlin/pins.h pins.h lists for the Printrboard, showing Z step and Z Direction on pins 32 and 33

Code: Select all
/****************************************************************************************
* Printrboard Rev. B pin assingments (ATMEGA90USB1286)
* Requires the Teensyduino software with Teensy2.0++ selected in arduino IDE!
* See http://reprap.org/wiki/Printrboard for more info
****************************************************************************************/
#if MOTHERBOARD == 81
#define MOTHERBOARD 81
#define KNOWN_BOARD 1

#define X_STEP_PIN 28
#define X_DIR_PIN 29
#define X_ENABLE_PIN 19
#define X_MIN_PIN 47
#define X_MAX_PIN -1

#define Y_STEP_PIN 30
#define Y_DIR_PIN 31
#define Y_ENABLE_PIN 18
#define Y_MIN_PIN 20
#define Y_MAX_PIN -1

#define Z_STEP_PIN 32
#define Z_DIR_PIN 33
#define Z_ENABLE_PIN 17
#define Z_MIN_PIN 36
#define Z_MAX_PIN -1



So I remain baffled. :? :roll:
  • 0

You do not have the required permissions to view the files attached to this post.
Printrbot Plus operational January 2013
Brass threaded rods (5/16" X 18) & nuts for Z axis
GT2 belts & pulleys
Cable chain to reduce probability of fatigue failure in wires
E3D V5 Hot End, 0.4mm nozzle, also 0.8 and 0.25 in use occasionally
PB fan mount + 40mm fan -- using printed mount adapter, not the E3D supplied fan
Injection molded extruder gears
Optical Z "endstop" (custom designed and built)
Have used many pounds of T-Glase filament. Now also doing some work with Ninjaflex SemiFlex
Print on glass with Scotch Craft Stick or other glue stick
User avatar
RetireeJay
My next printer is...
 
Posts: 4830
Joined: 2013-Jan-Wed-13-Jan
Location: Greenville, SC
Reputation: 478

Re: How can I find the right files on Github?

Postby extent » 2013-Jul-Sat-10-Jul

Physical pin number is not the same as Arduino pin number, the physical pin number for a single logical pin can actually be different even between different packages of the same exact chip. There isn't any relation between the arduino number and the physical pin on the package at all, you'll find that lots of pins even split seemingly randomly between logical ports on the chip.

The only info you need is the port number from the schematic (PA4_AD4), and then use that to look up the arduino pin number for the respective bit (PA4). If the config says it's pin 32 then you can just make a note of that, and that's the pin number you need to use. You can completely ignore the pin number from the physical package.

The 2nd part of the Atmega pin number has to do with what features are available on that pin, I'm pretty sure the _AD4 means that it's the 4th A/D converter on the chip. Other ones like PCINT16/RXD is an interrupt pin with serial receive, SCK/PCINT5 is an interrupt pin with the SPI hardware clock pin, etc, etc.

Also note that analog ports use a different numbering scheme than digital ports in Arduino, (A1 is analog port 1, it also has a digital port number that's somewhere above the maximum number of digital pins for the chip) but you should be able to find documentation about that if you run up into that problem. I don't remember the specifics off the top of my head.
  • 0

backer #48
extent
Printing skirt...
 
Posts: 150
Joined: 2012-May-Thu-03-May
Reputation: 6

Re: How can I find the right files on Github?

Postby RetireeJay » 2013-Jul-Sat-12-Jul

Aaargh - I'm still lost!

I did guess that the AD meant Analog to Digital, and I do understand that many of the Atmel I/O pins are highly configurable as digital in, digital out, analog in, or analog out.

But if I want to re-map the Z motor drive outputs to go to one of the headers on the board, how do I do It?? Obviously physical pin number has a relationship with logical pin number somewhere, and it appears that I need to know that mapping.
The current Schematic shows this relationship:
Z_STEP PA4 Package pin 47
Z_DIR PA5 Package pin 46
Z_ENABLE PC7 Package pin 42 (this pin also has A15, IC3, and CLK0 functions, which I presume are ignored here)

Now here's what the schematic shows for the header that I think I'd like to use:

PrintrboardJumper.JPG


This all seems nice and logical: I have my pick of outputs PC0, PC1, PC2, PD4, PD5, PD6, PD7, PE0, and PE1 to choose from. So I simply need to redefine where my Z_STEP, Z_DIR, and Z_ENABLE signals go. Instead of PA4, PA5, and PC7, I'd use three from the above list.

BUT... :evil: the way the definitions are written in "pins.h" is in terms of logical pin numbers, not port ID's.
For example, #define Z_STEP_PIN 32
It does NOT say #define Z_STEP_PIN PA4; if it said that, I would know exactly what to do!

I can find the physical package pin numbers corresponding to PC0 etc on the schematic, but what is the Arduino logical pin number mapping? Where do I find it?
  • 0

You do not have the required permissions to view the files attached to this post.
Printrbot Plus operational January 2013
Brass threaded rods (5/16" X 18) & nuts for Z axis
GT2 belts & pulleys
Cable chain to reduce probability of fatigue failure in wires
E3D V5 Hot End, 0.4mm nozzle, also 0.8 and 0.25 in use occasionally
PB fan mount + 40mm fan -- using printed mount adapter, not the E3D supplied fan
Injection molded extruder gears
Optical Z "endstop" (custom designed and built)
Have used many pounds of T-Glase filament. Now also doing some work with Ninjaflex SemiFlex
Print on glass with Scotch Craft Stick or other glue stick
User avatar
RetireeJay
My next printer is...
 
Posts: 4830
Joined: 2013-Jan-Wed-13-Jan
Location: Greenville, SC
Reputation: 478

Re: How can I find the right files on Github?

Postby lwalkera » 2013-Jul-Sun-02-Jul

It's more complicated than that even. The pin numbers used by Teensyduino/Arduino functions are different from the fastio stuff that the Marlin motion engine uses, so the same physical pin can map to a different pin number in pins.h depending on what feature it's used in and how it was implemented. Which is why I had to do the changes in the first hunk of this commit: https://github.com/Printrbot/Marlin/com ... 2a202e7067

Let me know what you'd like to change the pins to and I'll look up the right pin numbers.
  • 0

Laine Walker-Avina
Printrbot Beta-tester and Printrboard Designer
lwalkera
Honeycomb infill 25%...
 
Posts: 291
Joined: 2012-Feb-Sat-04-Feb
Location: Folsom, CA
Reputation: 32

Re: How can I find the right files on Github?

Postby RetireeJay » 2013-Jul-Sun-11-Jul

Thanks, Laine! :D

I guess I should start by downloading and getting familiar with the IDE.

Upon reflection, I remember the "normal" way of addressing I/O is through memory or Register addresses. The Atmel chip lists three register bytes per Port (ports A through F); one register for "pins" one for Data Direction, and one for Output (presumably) - so why wouldn't the software use these register addresses? Then I could just define my new definitions for Z motor control in terms of Port addresses and bits. The use of a numerical pin number that does not correlate with physical pin number seems confusing and unnecessary. Even in different chip packages, the pin that Atmel labels Port A bit 0 will always be Port A bit 0, no matter what the physical package calls it numerically.

Anyway, I have a number of irons in the fire right now, and this mod won't take place for several weeks. I was just trying to lay the groundwork.
  • 0

Printrbot Plus operational January 2013
Brass threaded rods (5/16" X 18) & nuts for Z axis
GT2 belts & pulleys
Cable chain to reduce probability of fatigue failure in wires
E3D V5 Hot End, 0.4mm nozzle, also 0.8 and 0.25 in use occasionally
PB fan mount + 40mm fan -- using printed mount adapter, not the E3D supplied fan
Injection molded extruder gears
Optical Z "endstop" (custom designed and built)
Have used many pounds of T-Glase filament. Now also doing some work with Ninjaflex SemiFlex
Print on glass with Scotch Craft Stick or other glue stick
User avatar
RetireeJay
My next printer is...
 
Posts: 4830
Joined: 2013-Jan-Wed-13-Jan
Location: Greenville, SC
Reputation: 478

Re: How can I find the right files on Github?

Postby extent » 2013-Jul-Mon-18-Jul

Because PA0 is going to be the same between packages, but not the same between the 328p and the 2560 or the 32U4, or the SAM3X8E. Remember the arduino isn't just a breakout dev board but fully abstracted hardware. They shuffle pins all over the place to make sure that PWM pins are always under arduino PWM pins, and the serial lines are always in the same place, and when you blink a LED on pin 6 it always blinks pin 6 on the arduino headers. Using direct port manipulation /is/ better (and well over an order of magnitude faster, which is why fastIO libraries exist), but it makes your code chip specific.
  • 0

backer #48
extent
Printing skirt...
 
Posts: 150
Joined: 2012-May-Thu-03-May
Reputation: 6


Return to Hack talk

Who is online

Users browsing this forum: No registered users and 2 guests