Hardware vs Software

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I am confused on hardware module and software program. Many links refer hardware and software protocol.

Hardware
  • Hardware Uart
  • Hardware SPI
  • Hardware ADC
  • Hardware CAN
Software
  • Software Uart
  • Software SPI
  • Software ADC
  • Software CAN
If microcntroller don't have hardware so there we use software program for serial communication right.


if microcontroller don't have uart module available then then we use software Uart we setup the pin of microcontroller using software program because the pin of microcontroller are software configurable. We can set either input or output. So when we don't have uart module available on microcontroller then we use software Uart.

What is difference between Hardware SPI and Software SPI ?

What is difference between Hardware SPI and Software SPI ?
 

MrChips

Joined Oct 2, 2009
34,807
Hardware SPI means that the MCU (or system) has dedicated hardware to send and receive SPI clock and data. Without dedicated hardware the MCU could perform the same function by toggling input/output pins in order to generate the equivalent SPI clock and data signals.

At the receiving end of the SPI interface, the MCU has to interrogate the CLOCK and DATA inputs in order to properly synchronize with the incoming CLOCK and DATA signals.

There are performance penalties when using software SPI or UART.

Firstly, the MCU will be tied up with delay loops, polling or interrogating the signals. Hence overall performance of the MCU is compromised.
Secondly, the MCU is not capable of running at higher SPI or UART data rates that normally would be possible with dedicated hardware.
 

jpanhalt

Joined Jan 18, 2008
11,087
One disadvantage of hardware communications is that they usually restrict the pins that can be used. That restriction is somewhat avoided with modern chips that have assignable pins. Another limitation of hardware is that occasionally you need more channels than hardware provides, such as with UART.

ADC is not a communication protocol like the serial protocol you list. Moreover, modern chips often have many ADC channels.
 
One point to stress if the question of Hardware vs. Software is confusing is the concept of "dedicated". This might be a sticking point for the TS here and in a previous thread.

So, as @MrChips wrote "Hardware SPI means that the MCU (or system) has dedicated hardware to send and receive SPI clock and data. Without dedicated hardware the MCU could perform the same function by toggling input/output pins in order to generate the equivalent SPI clock and data signals."

This means, essentially, that it is not just Hardware vs. Software, but dedicated hardware vs. general purpose hardware that can be controlled by software to achieve an approximation of what the dedicated hardware is doing in examples of SPI and UART. Without any hardware at all (some GPIO, for example), there is no software SPI as is being discussed.

Moreover, the "dedicated" hardware has some level of "software" dedicated to the function. That is, the instructions to control the functions may exist within the hardware, but they exist.
 
Last edited:

MrChips

Joined Oct 2, 2009
34,807
Anticipating a question on software ADC and DAC to arrive, here are some answers.

Very low end MCU or early MCU may have no hardware ADC or DAC.
Some may have any combinations of single/multiple ADC, DAC, analog comparators.

On the DAC (digital-to-analog converter), you can generate an analog voltage using PWM (pulse-width modulation).
You can also generate low resolution analog voltages using n-pins of digital outputs by using external resistors or external DAC chip.

On the ADC (analog-to-digital), we usually think of converting an analog voltage to a digital value. However the concept of ADC is not limited to measuring voltages only. ADC can also mean measuring a resistance (e.g. a thermistor, or strain gauge) or a capacitance (e.g. humidity sensor).

Without having an internal ADC hardware, you can measure resistance and capacitance using a single digital input/output MCU pin by measuring frequency or period. Use two pins if you wish to measure electrical conductivity in solutions.

With internal or external analog comparator, you can measure analog voltages in a similar fashion, with or without using constant current sources.
With internal or external analog comparator and an internal or external DAC you can create a tracking ADC or successive approximation ADC.

Thus, yes, you can create a software ADC with minimal hardware resources.
 
Top