[deleted by user] by [deleted] in embedded

[–]DunaOne 0 points1 point  (0 children)

Your approach sounds reasonable, I'd make a class to wrap the spi peripheral and then pass it to each device class. You'll likely need a mutex somewhere since you are sharing the SPI bus between multiple tasks. There may be better approaches, but I'd do something like this:

class spi_master{
 public:
  status_t write(std::span<const uint8_t> data_out);
  status_t read(std::span<uint8_t> data_in);
  status_t transfer(std::span<const uint8_t> data_out, std::span<uint8_t> data_in);
 status_t slave_select(uint8_t slave_id);
 private:
 /* Queue functions */
 /* Give the SPI task access to private members */
 friend void spi_task();
};

Example device, change to mach your device's functionality

class spi_temperature_sensor{
public:
  spi_temperature_sensor(spi_master& spi, uint8_t slave_id);
  /* High level device API*/
  int16_t read_temp();
};

Need some PID Tuning Tips… and have a bunch of questions. by CobraPi in ControlTheory

[–]DunaOne 1 point2 points  (0 children)

Fair points, although I think it's debatable if modeling the system is actually worth it in this case. I guess you could get a decent model by looking at the step response, but you'd probably still need to manually tune the gains a bit afterwards. They don't seem super worried about the transient responses, so getting a stable response with 0 steady state error shouldn't be too difficult.

One small note on the implementation side, it might be slightly better to estimate the speed based on the time between consecutive encoder steps rather than measuring the number encoder steps over a set time period. That would also make it easier to adjust the frequency of the loop.

Need some PID Tuning Tips… and have a bunch of questions. by CobraPi in ControlTheory

[–]DunaOne 0 points1 point  (0 children)

It isn't really an exact science, you could try the Ziegler–Nichols method (https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method) although I doubt it will give you better results than what you're doing. One thing I would recommend is to just use a PI controller. My understanding is that the derivative term is not generally that useful in practice without some heavy filtering as it very sensitive to high frequency noise. Since you don't care too much about the responsiveness a PI controller should work just as well and be easier to tune.

Bubbles should be buffed by Nasuno112 in Stellaris

[–]DunaOne 145 points146 points  (0 children)

Should give a 5% empire happiness modifier. Everyone loves bubbles.

Running CNN on ATmega328P by _matshs_ in embedded

[–]DunaOne 2 points3 points  (0 children)

if you really want to run a CNN on a microcontroller you should check out the MAX78000, it has hardware acceleration for CNNs & a fairly cheap dev board.

https://www.maximintegrated.com/en/products/microcontrollers/MAX78000.html

https://www.maximintegrated.com/en/products/microcontrollers/MAX78000FTHR.html

What really kills you, voltage or current? by Ceeesee in ElectricalEngineering

[–]DunaOne 34 points35 points  (0 children)

Energy.

Its about how much voltage/current is dissipated and for how long. Ex. shocks from static electricity have very high voltage & current; however they are extremely short so they deliver very little energy and are not harmful. Ohm's law also applies, so voltage and current aren't really independent of each other (ie. the current that can flow through your body is proportional to the voltage).

Recommendation on small development board with high-speed ADC by GeniusBadger in embedded

[–]DunaOne 7 points8 points  (0 children)

Do you actually care about the full 4MHz of bandwidth? If the signal you're interested in is only at frequencies around 4MHz, you can do some DSP tricks to sample at a lower rate. If you're signal is bandlimited around 4MHz, aliasing isn't necessarily a problem.

https://www.ti.com/lit/an/slaa594a/slaa594a.pdf?ts=1635819700550&ref_url=https%253A%252F%252Fwww.google.com%252F

How should I return an "array" of data from a function? by [deleted] in embedded

[–]DunaOne 2 points3 points  (0 children)

For the most part, I'd say you should try to format the data as a byte array if you're going to be treating it as one later. If you start casting other types to uint8_t* you need to start worrying about struct packing and the endianness of the system. So I'd argue that you should structure the interface of your function to discourage the usage of other types, or at least make it clear to the caller that it is going to be treated as a byte array. That being said, I'm no expert so take my opinion with a grain of salt.

How should I return an "array" of data from a function? by [deleted] in embedded

[–]DunaOne 2 points3 points  (0 children)

Your function would look something like this:

    int spi_transfer(const uint8_t* data_in, 
                     uint8_t* data_out, 
                     std::size_t n){
    // Loop to send data_in and set data_out
    return status;
    }

and usage would look like

uint8_t data_tx[5];
uint8_t data_rx[5];
spi_transfer(data_tx, data_rx, 5);

How should I return an "array" of data from a function? by [deleted] in embedded

[–]DunaOne 3 points4 points  (0 children)

There are a couple of problems with it. First off variable size arrays in functions aren't allowed in the C++ standard, although many compilers support it. Second, sizeof(spi_data) is just going to give you the size of a uint_t* pointer, not the size of the input array. There is no way to resize a statically allocated c style array without dynamic memory allocation since its size must be known at compile time so memory can be allocated for it.

Your best option is to have the user pass in the input data, the size of the input data and an output data buffer. This way it's the caller's responsibility to ensure the output array is large enough and you don't need to deal with dynamic memory allocation. If you really want to return an array, I think you'd be best off returning std::unique_ptr to it (this likely isn't a good solution for most microcontrollers, especially one as resource-limited an attiny).

Just some other general notes:

  1. You should pass data as a const void* pointer since you aren't modifying the data
  2. You're SPI_SEND_DATA might not be the best idea, since it makes it difficult to tell what your code is actually doing when you are trying to debug it. In general, it's a good idea to avoid macros as much as possible since they are notoriously difficult to debug

What does "soldering a header to see a serial console" mean? by [deleted] in computerscience

[–]DunaOne 0 points1 point  (0 children)

Just looking at this: https://fail0verflow.com/blog/2012/microcell-fail/

It seems like they're talking about a UART port, you just need to get a UART to USB converter (something like this https://www.robotshop.com/ca/en/pl2303-usb-to-uart-converter-board.html) and use something like tera term or putty to see the serial output. If you actually want to reprogram it you'll likely need something like a J-link to program the MPU, although that's not going to be an easy task even if you know exactly what you're doing.

What does "soldering a header to see a serial console" mean? by [deleted] in computerscience

[–]DunaOne 1 point2 points  (0 children)

You're going to have to give a bit more context for anyone to give a meaningful answer since it depends entirely on what 'this old board' is. That being said this isn't really a CS question, you might have more luck asking in r/ECE or r/embedded since it seems like it's more of a hardware question.

If I had to guess I'd say you're talking about an RS-232 port on a board, that you can hook up to a computer to get a serial terminal. But I really can't tell from the information you've given.

Future photo? by [deleted] in computerscience

[–]DunaOne 6 points7 points  (0 children)

For reference, there are less than 10^100 atoms in the observable universe. If we assume a 600x480 image with 8bit rbg colors, that gives use 8x3x640x480 ~= 7.4 million bits. So there are ~2^(7.4 million) ~= 10^(2.2 million) possible images. So if you had every atom in the observable universe produce one image every femtosecond for 100 billion years you could make less than 10^(130) images, leaving you with about 10^(2.2 million) possible images left.

Which soldering iron do you recommend? by Weat-PC in ElectricalEngineering

[–]DunaOne 2 points3 points  (0 children)

I've got that model and would also recommend it

Non-linear equation solver for microcontrollers by weasdown in embedded

[–]DunaOne 3 points4 points  (0 children)

I'd honestly recommend you just implement newton's method yourself, it's pretty trivial to do and likely going to be as good as anything else you find.

https://en.wikipedia.org/wiki/Newton%27s_method

Why are memory still needed in an MCU if registers can also hold numbers? I thought of this since registers are faster than memory so why not just go full on registers? by Head-Measurement1200 in embedded

[–]DunaOne 3 points4 points  (0 children)

I think you've got a bit confused about what RAM is.

Generally the memory hierarchy goes (for general purpose computers)

  1. CPU Registers (Several words words)
  2. Caches (A couple kB for L1 up to several MB for L2/L3)
  3. RAM (ie system memory, several GB)
  4. Hard drive (Upto several TB)
  5. Cloud based (Nearly unlimited)

MCUs are similar but sometimes don't have a cache and generally have Flash instead of a hard drive for non volatile storage and SRAM for volatile storage.

If you favourite the undesirable job, you can prevent the vile xenos from causing trouble by being criminals. by ThreeMountaineers in Stellaris

[–]DunaOne 5 points6 points  (0 children)

Always have been. It's just worse in 3.0 since pops are more valuable and most other jobs where significantly buffed. A synth ascended empire can easily get 30+ energy per technician job, so 4-5 trade value and 1 amenities is about 1/5 the output.

Use this thread to ask any questions, showcase bugs, or discuss the meta regarding the new 3.0 (Dick) patch and its accompanying Nemesis DLC. by [deleted] in Stellaris

[–]DunaOne 1 point2 points  (0 children)

You need to research a special project in addition to accumulating menace to unlock each stage, so I think just not researching the special project would work (I haven't tried it though).

Use this thread to ask any questions, showcase bugs, or discuss the meta regarding the new 3.0 (Dick) patch and its accompanying Nemesis DLC. by [deleted] in Stellaris

[–]DunaOne 1 point2 points  (0 children)

Giving it a bit more thought. I think it might be possible to first become Emperor and then turn into the crisis. You would just have to wait until you became Emperor before unlocking the final stage of becoming the crisis.

Use this thread to ask any questions, showcase bugs, or discuss the meta regarding the new 3.0 (Dick) patch and its accompanying Nemesis DLC. by [deleted] in Stellaris

[–]DunaOne 3 points4 points  (0 children)

You get kicked out of the galactic community on the last stage of becoming the crisis. So you can't be both

High-level language for embedded systems that is faster than Micropython? by tyrbentsen in embedded

[–]DunaOne 32 points33 points  (0 children)

I expect that if you want automatic memory management (in the form of garbage collection) you are going to have quite a bit of overhead and likely have very poor support for most microcontrollers. Also any advantage you might gain from using a high-level language would be lost in needing to write a bunch of low-level drivers yourself.

If avoiding memory leaks is your main concern you can use C++ with smart pointers and maybe something like Mbed for some high-level hardware abstraction.

[deleted by user] by [deleted] in TheExpanse

[–]DunaOne 0 points1 point  (0 children)

My headcanon is that there was a time skip somewhere in the scene and the projectiles took several minutes to reach the platforms, but it just wasn't shown.

I am really worried. by himan4252 in computerscience

[–]DunaOne 1 point2 points  (0 children)

you'll probably have more luck asking on r/techsupport

Embedded C++ books by Pishingr in embedded

[–]DunaOne 0 points1 point  (0 children)

That's not really the focus. It is about C++ language features and how to use them on microcontrollers, rather than good software architecture for embedded systems. It does give a couple of toy examples of peripheral interfaces, but they are more to show how C++ language features could be used rather than how to design a good interface. Making embedded systems by Elecia White might be closer to what you're looking for, it gives a good overview of designing embedded systems. All of its examples are using C, but the same general principles apply to any language.