Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Help pin I/O

2 posters

Go down  Message [Page 1 of 1]

1Help pin I/O Empty Help pin I/O Sun Jun 20, 2021 2:21 pm


What is the difference in creating the pins in the following ways?

1) -----------------------------------------------------------------------

   QStringList pinList;                              // Create Pin List

   pinList // Inputs:
           << "IL01 SDA"//type: Input, side: Left, pos: 01, label: "SDA"
           << "IL03 SCL"
           << "IR01 A0"
           << "IR02 A1"
           << "IR03 A2"
           // Outputs:
   init( pinList );                   // Create Pins Defined in pinList
   Ssd1306::Ssd1306( QObject* parent, QString type, QString id )
      : Component( parent, type, id )
      , eI2C( id.toStdString() )
      , m_pinSck( 270, QPoint(-48, 48), id+"-PinSck" , 0, this )
      , m_pinSda( 270, QPoint(-40, 48), id+"-PinSda" , 0, this )
      //, m_pinRst( 270, QPoint(-32, 48), id+"-PinRst" , 0, this )
      //, m_pinDC ( 270, QPoint(-24, 48), id+"-PinDC"  , 0, this )
      //, m_pinCS ( 270, QPoint(-16, 48), id+"-PinCS"  , 0, this )

3) ------------------------------------------------------------------------

   m_pin.resize( 1 );

   QString pinId = m_id;
   QPoint pinPos = QPoint(-8-8,-Cool;
   m_pin[0] = new Pin( 180, pinPos, pinId, 0, this);
   m_pin[0]->setLabelText( "+" );
   m_pin[0]->setLabelColor( QColor( 0, 0, 0 ) );
   m_ePin[0] = m_pin[0];

I created a component with only one pin created the way 2) ,
set as input    "eLogicDevice::createInput( &m_in_pin );"
I can read the status  "eLogicDevice::getInputState( 0 );"
but i can't use it as an output, i tried:

   m_input[0]->setOut( false );
   m_input[0]->setImp( m_outImp); or m_input[0]->setImp( high_imp);
   m_input[0]->setOut( false );
   m_input[0]->setVoltHigh( 5 ); or m_input[0]->setVoltHigh( 0 );


but the pin does not change state

2Help pin I/O Empty Re: Help pin I/O Sun Jun 20, 2021 3:57 pm



1) Creates Pin in Heap (can only be used with LogicComponents)
2) Creates Pins in Stack (automatic allocation).
3) Creates Pin in Heap (using "new").

None of those cretaes I/O capabilities.

To make an input work as output you need to set it's characteristics first:
- Output High Voltage. setVoltHigh( double v )
- Output Low voltage. setVoltLow( double v )
- Output Impedance. setImp( double imp )
Now that Pin is configured as Output.

Then you can set the output state:
setOut( true ); // Set Output to High
setOut( false ); // Set Output to Low

If you want to use as an input again you need to:
- Set Output to low.
- Change to high impedance.

In your case I think you just need to set Output High Voltage in the Component constructor (it is 0 by default).

Then you can change betwen Input and Output just changing impedance.

But you don't need to set Output impedance every time, only when you want to switch betwen Input and Output.
Note: setImp( m_outImp) calls stampOutput();


All this has changed in 0.5.16.
Now it is much simpler, for example:
- eSource dissapears and there is a new IoPin class that has many features, for example changing Pin modes in one function: Input, Output, Output open, Source.

- LogicComponent and eLogicDevice are unified, so using method 1 will create IoPins with I/O capabilities directly.

3Help pin I/O Empty Re: Help pin I/O Mon Jun 21, 2021 10:25 pm


I tried it without getting the desired result.
Maybe something is still missing.
The data line has a pull-up resistor that holds it at 5V
Arduino brings it to 0 for 18 ms, and switches the input to the input
the component after detecting 0V for 18ms later after
30 us leads to 0V for 70 us then releases rise to 5V.

5V _____                      Arduino                 __      __________....
              |                                                |  |    |
              |                                                |  |    |
0V           --------------------------------------   -----

I attach the code if you want to take a look at it
Help pin I/O AttachmentComponent.zip
You don't have permission to download attachments.
(3 Kb) Downloaded 1 times

4Help pin I/O Empty Re: Help pin I/O Tue Jun 22, 2021 2:44 am



There are a few issues...

But basically simulation time has nothing to do with our time, so using timers or usleep is useless.

for example all this happens exactly is the same moment in simulation time.
And the first setOut( false ); is not even seen by the circuit:
void Dht22::writeAcknowledge() {
    m_input[0]->setOut( false );
    m_input[0]->setImp( m_outImp);
    m_input[0]->setOut( true );

To do what you want you need to register to the simulation clock, and count cycles until the required simulation time is reached.
To see how it works you can have a look at sr04.cpp.

Again this has changed in 0.5.16 and it is now much easier to do things like this.

Sponsored content

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum