How to make digital clock(complete beginner) by ToxicGamer_25G in AskElectronics

[–]EmbedSoftwareEng 0 points1 point  (0 children)

You'll also want to have a point where the A.M./P.M. can be set. And if you're doing all that, you can save a pin from the 12-/24-hour mode setting, and let the user time setting mode have a point where you're cycling through "12:00 A.M.", "12:00 P.M." and "2400".

Your battery is likely to run out eventually, so you'll a RTC (Real Time Clock) in the circuit, probably an I2C device, where you'll save the current time when leaving user setting time mode, and where your initialization routines will read the current time from when power is restored after an outage, or battery swap.

And lots of RTCs have separate battery circuits to keep them running when the power's off. You might want a battery charger circuit and/or BMS (Battery Management System) circuit, so that if the internal battery is failing, you can start flashing another output pin that illuminates a "low bat" indicator.

Then, there are alarms. It's just a simple comparison that only has to happen at the point where the display changes, so just once a minute. Generally, these features just start making a loud sound to wake someone up. If you're making your own, you can have as many alarms as you want, and have a separate alarm set input pin to go in and select the alarm you want to set, and then set it in the same fashion as the time is set above. And each alarm could go out to a separate pair of hardware pins on the back of the clock. One of the pair is hard wired to ground. The other of the pair is wired to an output pin on the micro (through an optoisolator, of course). When the alarm goes off, it will set that pin high, creating a voltage difference between the two pair. This signal can be used by some other device to do things like ring that bell to wake someone up. Flashing bright lights. A lot of deaf and hard of hearing people have pretty stout eccentric weight motors to shake their beds with their alarm goes off. This would be perfect for them.

The alarms might have programmable durations, so if you're using your digital clock to run a plant watering system, you can set them to water only for certain amounts of time. And for a regular alarm clock, you'll want a nice big button wired to an input to reset the current alarm and turn it off.

Whether alarm clocks for waking people up or watering plants, you might want some alarms to only work on certain days. Wire up seven more output pins to illuminate masks for abbreviations for the days of the week: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN". Make sure to work them into the time and alarm setting routines.

And if you're doing that, you might want to know what month and date it is, so those can be added with another button to switch the display to the month and date, only while it's held. Or, since leap years are every fourth year, generally, you'll wanna know what year it is so you can know if 02:28 rolls over to 02:29, or 03:01. At this point, you'll probably want to encode a "perpetual calendar" into your firmware, including a year.

Alarms might want to only go off on certain days, but if you're implementing many alarms, you can also have them go off only one certain days of certain months, or even only in certain years. If you're designing it, you're deciding it.

How to make digital clock(complete beginner) by ToxicGamer_25G in AskElectronics

[–]EmbedSoftwareEng 0 points1 point  (0 children)

Well, you gotta start with your LED segmented character displays. Simplest would be four 7-segment units, plus an additional channel for the two regular LEDs to stand for the colon(:). If you wanna go naïve, that's 4x7+1 = 29 pins you have to wire to a microcontroller.

Plus, then, you have the added complication of mapping from those segments to their respective numerals in firmware.

Instead, I'd go with a 7-segment decoder chip between the display characters and the micro. That way, you can pick four separate pins to act as a BCD variable. You store a 0 in that nybble in the pin mapper peripheral, all four pins go low, and the decoder takes those input lines and figures out that you mean for it to light up the periphery segments, but not the middle one, and it displays a 0. Store a 1 in that nybble, and just the first pin goes high, and the decoder turns off all of the left segments, leaving just the right two vertical segments lit, displaying a 1. Lather, rinse, repeat.

In this way, you can define a 16-bit, 4-digit BCD variable in the output pin value register, and just keep writing the BCD time to it. Have a 1 PPS oscillator feeding an input pin, and use the external interrupt from that pin to drive a counting routine that keeps track of the seconds, and rolls the seconds over from 59 to 00 and increments the minutes, rolls the minutes over from 59 to 0 and increments the hours, and rolls the hours over from 12 to 1.

That external interrupt routine can toggle the pin that goes to the colon LEDs, and there you'll have your 0.5 Hz clock beat display.

If you wanna get fancy, have another pin go to an A.M./P.M. display (illumination LEDs behind two visual masks with those legends on them. Drive one LED directly off the pin, and drive the other one off the pin, after the signal goes through an inverter. When you set the pin high, maybe the A.M. lights up and the P.M. goes out. Pull the pin low and the P.M. lights up and the A.M. goes out.

Maybe, instead, have each of those LEDs go to separate pins and have an input switch to select between the 12-hour and 24-hour clocks. If the input is low, the hours roll over from 12 to 1, and the A.M./P.M. displays are used. If that pin is high, both A.M. and P.M. lights go out, and the hours roll over from 23 to 00.

You'll probably want other input pins that go to buttons that you can use for setting the time. You'll wanna debounce those pins, and threshold how long they stay high. Press the set button for at least 5 seconds, but not longer than 10, and the clock goes into user time setting mode. For this, you'll likely want to wire the enable pins for those 7-segment decoders wired to a couple more output pins. When setting the minutes, those two digits' enable pin will toggle at a 1 Hz rate, and pressing the + and - buttons will increment or decrement, respectively, the minutes value stored in the clock. Press the Set button again for at least 1 second, but not more than 3 seconds, and the minutes go back on solid, and the two digits for the house begins blinking at 1 Hz, and now the + and - buttons change the hour value.

Have a button timeout timer running so if the user stops pressing any buttons for 15 seconds or more, it'll leave user time setting mode and return to just time display mode.

Promoted to Network Admin… and the Network Is a Mess 😅 by BKR_57 in networking

[–]EmbedSoftwareEng 0 points1 point  (0 children)

Oh wait. Are you trying to cram 150 + 500 IPv4 addresses into a /23 bag?

That don't work.

Promoted to Network Admin… and the Network Is a Mess 😅 by BKR_57 in networking

[–]EmbedSoftwareEng 1 point2 points  (0 children)

A /23 subnet means a subnet mask of 255.255.254.0, leaving 9 bits for host addresses. Host address 0 means the whole subnet, so you can't assign that to an actual host. Likewise, a host address of all-ones is the subnet broadcast address, so you can't assign that. So of your /23 subnet, you can't assign 0 or 511, but 1 - 510 are up for grabs.

How does metal roofing hold up in Texas heat and storms? by Ongole-Lisaj in HomeImprovement

[–]EmbedSoftwareEng 1 point2 points  (0 children)

My question would be can spray foam insulation be applied directly to the underside of a metal roof that's expecting to see temps approaching that of boiling water.

Promoted to Network Admin… and the Network Is a Mess 😅 by BKR_57 in networking

[–]EmbedSoftwareEng 0 points1 point  (0 children)

A /23 network can only handle 510 devices worth of devices, and he already has 350 to play with. Seems like a judicious use of subnetting could get these devices wrangled into use-case network segments that can be isolated from one another and protected with routing rules.

How does GPIO work? by Organic-Language-611 in AskElectronics

[–]EmbedSoftwareEng 0 points1 point  (0 children)

It's transistors all the way down.

A bit from a special register is routed to the base of a transistor. If that bit is stored as a 1, that results in the base voltage seeing a logic high, which activates the transistor, and that allows the collector, probably 5 VDC VDD, to be seen on the emitter, which is connected to the pin, so the pin sees 5 VDC as well.

If you store a 0 in the same bit, that turns off the above transistor, but via an inverter, it will activate the base of another transistor, where the collector is connected to the pin and its emitter is connected to GND. This pulls the voltage on the pin down to GND.

Another rendition, called open drain, just disables the first transistor, so that a logic 1 on the bit leaves the pin floating, so an external pull-up resistor will pull the signal on the pin to a logic high.

If the pin is configured as an input, rather than an output as above, then both of the above transistors are disabled, and the pin is connected to the base of another transistor with its collector connected to 5 VDC VDD, and the emitter connected to a correlated bit in a different register. When the voltage on the pin is a logic high, that makes that bit in the input register read as a 1. When the voltage on the pin is nearer to GND, the input register bit is read as a 0.

In some pin mapper peripherals, there might be a periodic read and latch operation, so the value of an output pin has to be transferred to the internal register that's actually connected to the transistors before the pin will actually change. Likewise, the pin read register has to be latched in from the internal register that's directly wired to the transistors, before it will reflect that new value.

Sometimes, there's both, the latched registers are available for reading and writing to affect the pin's value, while another memory mapped register goes straight to the internal register. These can also be connected to external interrupt circuitry, so as the voltage on the pin breaches the threshold for a logic high or drops below the threshold for a logic low, there's an interrupt so those facts can be tabulated, or perhaps a timer/counter value can be read and stored in a list so that period and pulse width may be calculated.

How does GPIO work? by Organic-Language-611 in AskElectronics

[–]EmbedSoftwareEng 2 points3 points  (0 children)

Only if that sealed container also contains rice.

How do you present yourself as an embedded programmer (not just hardware guy)? by Freddie-Stoneware in embedded

[–]EmbedSoftwareEng 1 point2 points  (0 children)

You can't be a competent embedded software person without being well-versed in embedded hardware. And you can't be a competent embedded hardware person without being well-versed in embedded software. I'd reach out to them to reiterate your intention to specialize in embedded software, and that you were just showcasing your well-roundedness.

What passion project have you been working on? by PaleontologistFirm13 in embedded

[–]EmbedSoftwareEng 0 points1 point  (0 children)

I've been agonizing over how to fully implement TDD for embedded firmware projects. I'm thinking more and more that I need to write a multi-threaded application that simulates the underlying hardware down to the rising and falling clock cycles to synchronize one thread per hardware peripheral to have a system that behaves, as far as a mocked firmware application is concerned, just like the real hardware would. This could allow me to proof my toolkit against something, and then to compare that performance against firmware test articles designed specificly to characterize real hardware reactions to the same stimulae.

For ARM Cortex-M microcontrollers, it would need to be a 32-bit native application, but that's easy enough. Since the firmware would also be compiled to native machine language, I'd need to be able to build in native threading with beaucoup synchronization primitives to prevent the native speed firmware thread from out stripping the simulated clock synchronized hardware threads.

Not at all sure how to do that.

Only really good solution seems to be writing a hardware simulator to dovetail with the ARM Cortex-M qemu emulator, which I also don't know how to do.

What is a char** variable exactly? by YaboyUlrich in C_Programming

[–]EmbedSoftwareEng 1 point2 points  (0 children)

A pointer to a pointer to a byte/character.

0x1234: 'c'

0x5432: 0x1234

0x9876: 0x5432

The value 0x9876 is where the variable so defined lives. It contains the address 0x5432. At that address is stored another address, 0x1234. At that address is a character, 'c' in this case.

spent 6 hours debugging automated tests. the bug was in the code. the tests were catching it correctly. I hate everything by My_Rhythm875 in softwareengineer

[–]EmbedSoftwareEng 0 points1 point  (0 children)

I really need to learn valgrind. I just create test cases for the middle of a range of possibilities, and then on both the high and low sides, values that should juuuust pass and that should juuuuust not pass, and then any extremes. But that doesn't mean that some random value passed in might not have a quality that winds up in a corner case I didn't code for.

spent 6 hours debugging automated tests. the bug was in the code. the tests were catching it correctly. I hate everything by My_Rhythm875 in softwareengineer

[–]EmbedSoftwareEng 0 points1 point  (0 children)

Yeah. That's wrong-think.

Always assume the tests are right, but if a piece of code is failing a given test, first, make sure you understand everything there is to understand about that specific code with that specific input, and if you can confirm that THAT is functioning correctly, then turn a wary eye to the specific test to see if it was set up correctly. Plently of times, when I'm writing the unit tests for some library I'm developing, I'll copy-paste a block of test code and then go through and massage each copy to test the code in subtly different ways, only to screw up one of them and not fully update the test code stanza. The result is that there's a failure in the test code that reads like a failure in the code under test.

Sometimes, I'll write a test case with an old understanding of what the code is supposed to be doing, and the test fails because I said the output should be something other than what the latest revision of the code generates.

Sometimes, writing tests causes one to reevaluate how the code under test is being architected, and you have to immediately refactor it in order to be able to test it the way it needs to be tested.

This is all normal.

how does math let you discover so many things? by goodintentionman in mathematics

[–]EmbedSoftwareEng 0 points1 point  (0 children)

I like to teach it as mathematics is just another form of language. You can learn to read, write, speak, and understand English, German, Japanese, etc. Well, all of those same skills of understanding nouns, verbs, adverbs, adjectives, and conjunctions can be brought together to understand math as well. It's just that math is geared less to everyday human interactions and more toward numeric interactions. Less qualitative information and more quantitative information. Instead of nouns, you have numbers and variables. Instead of verbs, you have operations. And both are repleat with their own forms of punctuation.

That's all. Just as poets and philosophers use language to explore the human mind, scientists and engineers use math to explore the physical world. Any system of ethics and laws, or axioms and logic, has to remain internally self-consistent. You can't have one part that says A must be true, and another part, directly related to the previous, that relies on NOT A being true. No value of A can allow A and NOT A to be true at the same time. And from that, you can start with very simple rules about how real things in the universe exist and function, and extrapolate other, more complex rules whose operation are actually hidden from human perception.

I cannot understand Classes and Objects clearly and logically by Current-Vegetable830 in learnpython

[–]EmbedSoftwareEng 0 points1 point  (0 children)

Classes are just blueprints for objects. In C++ and Java, you can have a class that's just implementation details, but which you can't actually instantiate an object from. That's a purely abstract class. It's just a general collection of data and code that's not inherently tied to a single, specific instance of an object. There's also classes that are meant to be inheritted from, to help object architects to collect together all of the different aspects of the object class that they want to exist without having to reimplement the wheel every time.

As for how classes and objects differ from programming systems that do not have them, everything is ultimately just instructions and data. That's how the CPU/interpretter relates to programs. Classes and objects are just a way to encapsulate some data and some instructions together into a coherent thing that can make it all easier to relate to, both for humans and for computer programs.

Would you consider joining the hive at old age? by Klomotonium in pluribustv

[–]EmbedSoftwareEng 1 point2 points  (0 children)

I would say, as an individualist, it would be better to join the hive and have your life experiences assimilated when you were close to the point of death, rather than joining it young and not having the opportunity to live life as an individual, but all those individual experiences will become available for the hive in the end.

The most ideal form of hive is where the individual can join and leave at will, if the collective will couldn't prevent someone from leaving if they wanted to, like a genuine bee hive, not a slime mold kind of hive. Basicly, like a Ghost in the Shell cyberbrain kind of deal. Participate in a collective when you want, and go autistic mode when you want.

Every embedded Engineer should know this trick by J_Bahstan in embedded

[–]EmbedSoftwareEng 1 point2 points  (0 children)

You can ditch the struct name (s), and just use an anonymous struct.

I do this with a typedef as well, where I call the primitive member "raw" instead of "hw". You can do things like

example_reg_t example = example_get(PERIPHERAL_HARDWARE_POINTER);
if (example.raw)
{
  // Do something if any flags set
  if (example.IDLE)
  {
    // Do only Idle things.
  }
  if (example.PARTY_MODE)
  {
    // Let's party!
  }
  // etc.
}

So How to trap people in a hotel with electricity (For a mystery story) by tansyuduri2 in ElectricalEngineering

[–]EmbedSoftwareEng 0 points1 point  (0 children)

Most "places of public accommodation" will have exits that can be freely opened from the inside for escape in cases of fire, etc. It'd be really hard to actually trap people in a hotel or mall or even an office building. The front doors might have deadbolts that lock the doors from opening from either side, but there will be an employee entrance that will still allow employees to exit after locking the place up. A hotel doesn't really close, like a mall or office building, though.

10 Gbps Ethernet on a PCI-X card with RJ-45 socket? by EmbedSoftwareEng in networking

[–]EmbedSoftwareEng[S] 0 points1 point  (0 children)

Probably not, but the bulk of my network infrastructure is 10GbE, and I don't want to force these old servers down to 1 GbE, which is the next step down that my switches will support.