Welcome! Log In Create A New Profile

Advanced

Analog vs Digital PIN assignment

Posted by v1talogy 
Analog vs Digital PIN assignment
July 20, 2018 10:49AM
Hello,

How are the pins declared analog or digital?

[*EDIT* after Dust's input. What I mean is how does the FW know which physical pin to use on the board? I have two pins declared the same value, yet the FW reads the input from two different physical pins]

To keep things short and simple I will say what I am doing, and that it is working. My problem is I do not understand how it is working.

Basically I have a toggle switch connected to the X-Min Endstop pin on a RAMPS1.4 board, the pin is assigned as follows:

#define TOGGLE_SWITCH  3

Then I have a filament width sensor connected to AUX_1 peripheral, with the pin assigned as follows:

// Use the RAMPS 1.4 Analog input 3 on the AUX_1 connector
#define FILWIDTH_PIN        3 // ANALOG NUMBERING

(Note that the default is normally pin 5 on AUX_2, for my configuration I switched it to pin 3 on AUX_1.)

I have set up some basic code to change the output based on the state of the toggle switch, and when I run the FW the output of the filament width sensor is correct. Then, when I toggle the switch, the output is displayed accordingly and correctly. Which means the two pins, and their assignment, are not interfering with each other. I do not understand why not?

I know the sensor pin must be analog (input), its digital counterpart is 57 (A3 or D57), and the digital pin, well that conforms to the default configuration.

I am using this png file for the PIN verification. Please offer me any insight into this, I have been on the marlin site and github, but have found no clear indication on this distinction (between analog and digital).

Thank you.

Edited 3 time(s). Last edit at 07/21/2018 09:22AM by v1talogy.
Re: Analog vs Digital PIN assignment
July 20, 2018 10:04PM
If the pin can be analog or digital is part of the chip hardware

not all pins can be analog, but most can be digital

the naming/numbering convention is a arduino standard.

or are you just asking whats the difference?

digital pins can be 0 or 5v, nothing else, ie binary
analog pins can be in 4096 voltages from 0 through to 5v

Edited 1 time(s). Last edit at 07/20/2018 10:05PM by Dust.
Re: Analog vs Digital PIN assignment
July 20, 2018 10:20PM
I am asking what is the distinction between analogue and digital pins.
Essentially I have this:

#define TOGGLE_SWITCH  3
#define FILWIDTH_PIN         3

When I "use" the TOGGLE_SWITCH in the SW it produces a different output than if I were to use the FILWIDTH_PIN in the same code.

I do not understand how these two #defines are distinguished from one another.

Edited 1 time(s). Last edit at 07/20/2018 10:21PM by v1talogy.
Re: Analog vs Digital PIN assignment
July 21, 2018 12:17AM
the two lines are the same

the code probably has a #ifdef or #ifndef section that look for the defined names
Re: Analog vs Digital PIN assignment
July 21, 2018 04:21AM
Thank you for your input Dust,

These two definitions/pins are used very sparingly in the firmware. I had a look at your suggestion of possible inclusion and/or exclusion via #defines and could find no evidence of that being the case.

On looking at my second post I realize how absurd this seems. I define the TOGGLE_PIN to be an input and high pullup, and that is about it [in setup()]. The state of the pin is then later read and the output changed depending on the result.
That is:
    if (READ(TOGGLE_PIN)) -> do something
    else -> do something else
The FILWIDTH_PIN is used as default in the Marlin firmware, as when the #define FILAMENT_WIDTH_SENSOR is uncommented in the Configuration.h. The only change I made is to use a different AUX pin, 3 instead of 5.

The LCD screen is updated every second. The width of the filament is being displayed and updated every second, and this works great. I also display another variable (which I made 2.0 or 5.0 for testing purposes)
to display the state of the toggle switch. When the switch is toggled the display is updated accordingly, either 2.0, or 5.0, constantly....

The two physical input pins are on different places on the RAMPS board -> and this is the part that really confuses me. How does the FW know which physical pin to use?

Edited 2 time(s). Last edit at 07/21/2018 09:23AM by v1talogy.
Re: Analog vs Digital PIN assignment
August 08, 2018 06:31PM
I dident find it eather, but the comment after the define of the analog pin makes me think it is somewher defined as an analog only pin and therefore refers maybe on fastIO only to to analog numbering

Edited 1 time(s). Last edit at 08/08/2018 06:32PM by kabelfrikkler.
Sorry, only registered users may post in this forum.

Click here to login