Simplified equivalent circuit of a 328 digital input?

My first Arduino project (using an ATMega 328) is triggered by a roughly 5V to 0V edge and works fine overall. (It sends a series of servo arm movements.) But I'm still playing with various simple front end circuits to deliver that edge.

I'd like to use the simulation facility (of either LT Spice or my ancient CircuitMaker 2000) to experiment with these. What would be the simplest way to represent one of the digital input pins please? (Both with and without built-in PULL-UP specified in the program.)

Terry

The data sheet shows the input circuit of the pins.

Hi,
328 manual circuits


Tom.. :slight_smile:

I am not sure what exactly you need, for for most purposes the input pin may be considered as a very small (<5 pf) cap to GND. And connected to the neighbour pins via similarly small caps. The pull-up resistor is simply a ~30k resistor.

Thanks @Smajdalf, I think that's probably exactly what I was looking for, as you see from my summary below.

I have yet to try that delightfully simple equivalent, but I'll shortly get to my shed workbench, take a few 'scope screenshots of that breadboarded example, both before and after connecting to D6, then try simulating both. I'll report back when I have the results.

If I didn't specify PULL-UP, but instead included it physically, would the rough equivalent just be the tiny cap?

For this application the protection diodes to Vcc and GND may be important (as shown in the figure 13-1 shown by TomGeorge above).

Thanks Tom. As mentioned, I’m an Arduino novice and although an experienced electronics hobbyist I have no microcontroller know-how, so please bear with me!

Am I right that your top diagram means that, taking for example the circuit I showed this morning, for rough simulation I just need two diodes, one to ground and the other to 5V, plus a small cap of a few pF? Presumably when I use the built in PULL-UP I would also add a 30k resistor to 5V?

Yes, but this is a bad way to test it. Just hook up the real circuit and scope it.

Hi,
Is there a reason for doing this, rather than just connecting your PIRs each to a controller input and in software detect a change in PIR output?

Or is this purely academic?

Tom.... :slight_smile:

“Yes, but this is a bad way to test it. Just hook up the real circuit and scope it.”

As I said, I have several circuits, some almost finished, others still in design. The example was the simplest and does indeed run successfully from the breadboard. And it gives a very similar ‘scope output when the connection to the 328 is removed and the ‘equivalent’ under discussion added instead.

Tom: Certainly not academic! This will be useful when designing future circuits, i.e. before wiring them up. Isn’t that the purpose of simulation?

BTW, only one of these front-ends involves a PIR.

Hi,
If it is going to be in the real world, I would be experimenting in the real world.

Are you over thinking this, we all use the inputs with various sources and have not had to delve so deep into circuit design.

If you are just trying to detect a rising or falling edge, let the software do it.
If you want to OR gate them, let the software do it.

Currently with a hardware OR, you will detect each source, but not be able to determine which source the signal came from.

Tom... :slight_smile:
Each to his own..

Typical simulations in Spice only explore basic circuit operation, because the component models are approximations. To gain confidence in the edge cases, it is better to test actual hardware because the components are complete, and also respond in a real world way to external stimuli, such as EMI and temperature changes, and to changes in other components. Here you are, asking for a component model. You seem content with a very simplified version, indeed it may be the best you can do without input from the manufacturer. If the simulation fails, you have something definite to work with, But a successful simulation means less because of all the factors it may have omitted. I've used Spice for analog circuit testing, but it was just a preliminary stage to building a prototype. With digital, I don't bother because I know the components and design patterns very well and it almost always works the first time (once the stupid mistakes like backwards diodes etc. have been corrected). Your circuit is a kind of analog/digital hybrid so I see why you want to simulate it. Just take the results with a grain of salt.

Tom,

"If it is going to be in the real world, I would be experimenting in the real world."

Definitely real world, and lots of testing and experiment here!

"Are you over thinking this, we all use the inputs with various sources and have not had to delve so deep into circuit design."

Understood, and a fair point. I'm hoping I will eventually be able to shift my focus from hardware electronics to Arduino programs, which sounds like the approach you take and recommend. But meanwhile, given that I'm not a programmer (well, not for about 40 years, and that was probably Basic/FORTRAN), plus my inexperience with Arduino as mentioned before, I tend to take the familar h/w route. Soldering in a few series diodes seems so much easier (and intuitive) than figuring out the precise syntax and sequence of commands to do it by editing my current sketch. Which, as you'll see from my novice code, still even uses frowned-upon Delays rather than the recommended millis() approach, which I have yet to try.

https://www.dropbox.com/s/m62z6lpfkmplhht/CUBE-ServoPlusLED-SwitchD4-Trig01.txt?raw=1

"Currently with a hardware OR, you will detect each source, but not be able to determine which source the signal came from."

Thanks, good point I hadn't considered.

Terry

Thanks @aarg, understood, and I agree with all you say.

See also my reply to Tom for additional perspective.

Some other factors are:

  • I'm trying to relearn what I've forgotten since last serious work about 15 years ago with my schematic and simulation program CircuitMaker 2000 (CM).

  • I'm also making an effort to learn LT Spice because of its much wider use. (I've so far found only one other CM 2000 user on the planet!)

  • My electronics work bench is in my shed, but even in summer I prefer to tackle Arduino programming and CM schematics (and occasional simulation with both CM and LT Spice) here in my house office. Shed is not in wifi range of my office, so transfer of files is by USB stick, complicating work.

  • I transferred my Arduino circuit from a UNO 3 to veroboard and am currently experimenting with that.

I'm not yet as confident about editing that sketch on the bench of my shed workshop (with a Win XP PC BTW) as I am about playing with a few components.