Posted on — Leave a comment

Introduction to Numerical Integration using C

Numerical integration plays a crucial role in many applications related to embedded systems, such as control systems, signal processing, and digital filters. However, implementing numerical integration algorithms on embedded systems presents unique challenges due to limited computing resources such as memory, processing power, and clock speed.

To address these challenges, developers must carefully choose numerical integration methods that are well-suited for embedded systems. The choice of method depends on the specific requirements of the problem being solved and the available computing resources.

Some of the most commonly used numerical integration methods in embedded systems include the Trapezoidal Rule, Simpson’s Rule, and the Midpoint Rule. These methods are relatively simple to implement and require minimal memory and processing power, making them well-suited for use in low-power embedded systems.

In addition to these basic methods, more advanced numerical integration methods can also be used in embedded systems with larger amounts of memory and processing power. These methods include Gaussian Quadrature, Monte Carlo Integration, Romberg Integration, Adaptive Quadrature, Runge-Kutta Method, Newton-Cotes Formulas, and Chebyshev Quadrature.

Implementing numerical integration algorithms on embedded systems requires careful consideration of factors such as memory usage, processing power, and clock speed. Developers must also optimize their code to ensure efficient use of available resources and avoid memory leaks, stack overflows, and other common pitfalls.

Despite these challenges, numerical integration remains an essential tool for many applications related to embedded systems. With the right choice of method and careful optimization of code, developers can achieve high accuracy and efficiency in numerical integration calculations on embedded systems.

The Need for Numerical Integration

In many cases, it is not possible to find the exact analytical solution for a definite integral, either due to the complexity of the function or the limits of integration. In such cases, numerical integration provides a useful alternative for approximating the integral by dividing the interval into smaller subintervals, and then computing the area under the curve for each subinterval.

Here’s a list of functions that can solve definite integrals in embedded C:

  • Trapezoidal Rule
  • Simpson’s Rule
  • Gaussian Quadrature
  • Monte Carlo Integration
  • Romberg Integration
  • Adaptive Quadrature
  • Runge-Kutta Method (for solving ODEs)

Each of these methods has its advantages and disadvantages, and the choice of which method to use depends on the specific problem being solved and the available computing resources.

The Trapezoidal Rule and Simpson’s Rule are commonly used in embedded systems with limited RAM. These methods are relatively simple to implement and require minimal memory usage, making them well-suited for use in microcontrollers with limited resources. Additionally, these methods provide reasonably accurate results for many common functions, which further makes them popular choices for numerical integration in embedded systems.

Depending on the availability of RAM, different methods are available.

If the RAM is up to 32K, then integration methods considered, such as:

The Trapezoidal Rule and Simpson’s Rule are commonly used in embedded systems with limited RAM. These methods are relatively simple to implement and require minimal memory usage, making them well-suited for use in microcontrollers with limited resources. Additionally, these methods provide reasonably accurate results for many common functions, which further makes them popular choices for numerical integration in embedded systems.

If the RAM is increased to 60K, then some of the more computationally intensive integration methods can also be considered, such as:

  • Gaussian Quadrature: This method uses a weighted sum of function values at specific points to approximate the integral. It can provide higher accuracy than the Trapezoidal Rule and Simpson’s Rule for certain functions, but requires more memory and computational resources.
  • Monte Carlo Integration: This method uses random sampling to approximate the integral. It can provide accurate results for high-dimensional integrals, but can require a large number of function evaluations to achieve acceptable accuracy.
  • Romberg Integration: This method uses a recursive procedure to improve the accuracy of the Trapezoidal Rule. It can provide higher accuracy than the Trapezoidal Rule and Simpson’s Rule, but requires more memory and computational resources.
  • Adaptive Quadrature: This method adaptively subdivides the integration interval into smaller subintervals to achieve a desired level of accuracy. It can provide accurate results for functions with complex behavior, but can require a large number of function evaluations for high accuracy.

Note that the choice of integration method also depends on the specific requirements of the application and the available computing resources.

With an increased RAM of 512K, there are many numerical integration methods that can be used. Some of the most popular methods include:

  1. Gaussian Quadrature: This method provides high accuracy for a wide range of integrals but requires more memory than the Trapezoidal Rule or Simpson’s Rule.
  2. Monte Carlo Integration: This method involves randomly sampling points within the integration domain and is particularly useful for high-dimensional integrals. However, it requires a larger amount of memory than the Trapezoidal Rule or Simpson’s Rule due to the need to store a large number of random points.
  3. Romberg Integration: This method is a recursive extension of the Trapezoidal Rule and can achieve higher accuracy for a given number of function evaluations. However, it requires more memory to store the intermediate results of each recursive step.
  4. Adaptive Quadrature: This method dynamically adjusts the number of function evaluations based on the local behavior of the integrand, which can lead to higher accuracy for a given number of function evaluations. However, it requires more memory to store the intermediate results of each recursive step.
  5. Runge-Kutta Method: This method is commonly used for solving differential equations but can also be used for numerical integration. It provides higher accuracy than simple integration methods such as Trapezoidal Rule and Simpson’s Rule, but requires more memory to store the intermediate results of each step.
  6. Newton-Cotes Formulas: These are a family of numerical integration formulas that can achieve higher accuracy than simple integration methods. However, they require more memory to store the intermediate results of each step.
  7. Chebyshev Quadrature: This method uses the roots of Chebyshev polynomials to approximate the integral and can achieve high accuracy with fewer function evaluations than other methods. However, it requires more memory to store the coefficients of the Chebyshev polynomials.

Overall, the choice of numerical integration method will depend on the specific requirements of the problem being solved and the available computing resources. With a larger amount of RAM, more memory-intensive methods can be used, which can provide higher accuracy for a given number of function evaluations.

Posted on — Leave a comment

What is turtle.Turtle() in python?

In Python, turtle.Turtle() is a function that creates and returns a new turtle object that can be used to draw graphics on a canvas.

The turtle graphics library in Python provides a simple way to create graphics and animations by allowing you to control a virtual turtle that moves on a canvas. The turtle can be moved around the canvas using commands such as forward(), backward(), left(), right(), etc.

To use the turtle graphics library, you first need to import the turtle module. Then, you can create a new turtle object using the turtle.Turtle() function. For example, the following code creates a new turtle and moves it forward by 100 units:

import turtle

t = turtle.Turtle()
t.forward(100)

You can also customize the appearance and behavior of the turtle object by setting various attributes such as its color, size, shape, and speed. For example, the following code creates a red turtle with a size of 5 and a speed of 2:

import turtle

t = turtle.Turtle()
t.color("red")
t.pensize(5)
t.speed(2)
t.forward(100)

Overall, the turtle.Turtle() function is the starting point for creating and controlling turtle objects in the turtle graphics library.

Posted on — Leave a comment

DIY PCB Etching: How to Make Printed Circuit Boards at Home

Materials:

  • Copper clad board
  • Laser printer and paper
  • Ferric chloride
  • Plastic container
  • Gloves
  • Safety glasses
  • Water
  • Sandpaper
  • Steel wool
  • Drill

Tools:

  • Iron
  • Ruler
  • Scissors

Steps:

  1. Design your PCB using PCB design software or draw it on paper.
  2. Print your design using a laser printer on glossy paper. Be sure to print it in reverse so that the toner transfers onto the copper.
  3. Cut the copper board to the appropriate size using a ruler and scissors.
  4. Clean the copper board with sandpaper and steel wool to remove any dirt, dust, or oxidation.
  5. Heat up the iron to a high temperature and place the printed design onto the copper board.
  6. Apply pressure with the iron onto the paper for a few minutes until the toner melts and transfers onto the copper board.
  7. Once cooled, gently peel off the paper.
  8. Place the board into a plastic container filled with ferric chloride solution and let it sit for around 15-20 minutes.
  9. Shake the container occasionally to ensure the solution reaches all parts of the board.
  10. After 15-20 minutes, remove the board from the solution and rinse it with water.
  11. Use a drill to make holes in the board where necessary.
  12. Your PCB is now ready for use.

Note: Be sure to follow proper safety precautions when handling ferric chloride and wear gloves and safety glasses. Additionally, dispose of the ferric chloride solution properly and do not pour it down the drain.

Free software options for making PCB

  1. KiCAD – https://kicad.org/
  2. EasyEDA – https://easyeda.com/
  3. Fritzing – http://fritzing.org/home/
  4. DesignSpark PCB – https://www.rs-online.com/designspark/pcb-software
  5. ExpressPCB – https://www.expresspcb.com/
  6. FreePCB – https://www.freepcb.com/
  7. gEDA – http://www.geda-project.org/
  8. Osmond PCB – https://www.osmondpcb.com/

FAQ

Question: What trace width be achieved at home?
Answer: The achievable trace width at home depends on various factors such as the PCB fabrication process, equipment and materials used, and the skill level of the person performing the etching. Generally, the achievable trace width can range from around 8 mils (0.2 mm) to 20 mils (0.5 mm) with standard home etching methods. However, it is possible to achieve even smaller trace widths with advanced techniques such as photoresist etching, but these methods require more specialized equipment and materials.

Question: Why do you use mil instead of mm?
Answer: Mil is a commonly used unit of measurement in the electronics industry, particularly for specifying trace widths on printed circuit boards. It is equivalent to 1/1000th of an inch, or about 0.0254mm. While millimeters are a more commonly used unit of measurement in many parts of the world, mils are preferred for PCB design because they allow for finer resolution when specifying trace widths and clearances. Additionally, many PCB design tools are optimized for use with mils, making it easier to create and edit PCB designs using this unit of measurement.

Question: What are the common trace width for some common sections of PCB?
Answer: The common trace width for some common sections of PCB is:

  1. Power traces: 20-30 mils or more, depending on the current carrying capacity required.
  2. Signal traces 6-10 mils, depending on the frequency of the signal and the required impedance.
  3. Differential pair traces: 8-12 mils, depending on the required impedance and the tolerances of the PCB manufacturing process.
  4. Through-hole component pins: 20-30 mils, to ensure sufficient copper coverage around the hole and good solder joint strength.
  5. SMD component pads: 12-20 mils, depending on the size of the component and the PCB manufacturer’s recommendations.

Question: Can we draw all the trace with a single trace width?
Answer: It’s possible to use a single trace width for all traces on a PCB, but it’s not always the best approach. Some sections of the PCB may require wider traces to handle higher current or to reduce voltage drop. Other sections may require narrower traces to fit in tight spaces or to reduce signal crosstalk. It’s important to consider the specific requirements of each section of the PCB and adjust the trace widths accordingly. However, for a simple circuit, using a single trace width may be sufficient.

Posted on — Leave a comment

AVR Input Output Port Programming

In AVR microcontroller programming, input/output ports are used to interface with external devices such as sensors, switches, LEDs, motors, and other peripherals. Here’s an example of how to program AVR input/output ports using C language:

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    // Set PORTB as output and PORTC as input
    DDRB = 0xFF;
    DDRC = 0x00;

    while(1)
    {
        // Read the value of PINC3
        if(PINC & (1 << PINC3))
        {
            // If PINC3 is high, turn on LED connected to PB0
            PORTB |= (1 << PB0);
        }
        else
        {
            // If PINC3 is low, turn off LED connected to PB0
            PORTB &= ~(1 << PB0);
        }
    }
}

In this example, we set PORTB as an output port by setting all of its pins to output mode. We set PORTC as an input port by setting all of its pins to input mode. Then, we use a while loop to continuously check the value of PINC3. If PINC3 is high, we turn on an LED connected to PB0 by setting the corresponding bit in PORTB to high. If PINC3 is low, we turn off the LED by setting the corresponding bit in PORTB to low.

Note that the & and | operators are used to manipulate individual bits in the port registers. The << operator is used to shift the binary value of 1 to the left by a certain number of bits to set a particular bit high or low. The ~ operator is used to invert the value of a bit. The util/delay.h library is used to create a delay between each loop iteration.

Posted on — Leave a comment

How to make comments in python

In Python, you can make comments using the hash symbol (#).

Any text that appears after the hash symbol (#) on the same line is considered a comment and is ignored by the Python interpreter.

For example:

# This is a comment
print("Hello, world!")  # This is also a comment

In the above example, the first line is a comment, and it is ignored by the Python interpreter. The second line is a print statement, which will print “Hello, world!” to the console when executed. The third line is another comment, which is also ignored.

You can also use multi-line comments by enclosing them in triple quotes (“”” “””). For example:

"""
This is a multi-line
comment in Python.
"""

print("Hello, world!")

In this example, the first three lines are a multi-line comment, and they are ignored by the Python interpreter. The fourth line is a print statement, which will print “Hello, world!” to the console when executed.

Posted on — Leave a comment

Removed the faulty touch screen from STM32F429I-DISC1

The LCD display on this touchscreen is having issues. It is not responding to touch. And suddenly the display stopped working. So I cut the foam and suddenly the ribbon tore off completely.

As you can see the screen is completely removed.

It now gives access to all the pins that are being used by the LCD.

I am planning to make a VGA controller using this board since the microcontroller has an LTDC (LCD TFT Controller)

Posted on — Leave a comment

TIP3055 NPN BJT

It is a power transistor capable of handling power dissipation up to 90W for a few microseconds(generally less than 300 microseconds). Also, it has a Vceo of 60 V and a collector current of 15A.

TIP3055 is a widely used NPN power transistor that can handle high power and high voltage applications. It has a maximum collector-emitter voltage of 60V and a maximum collector current of 15A, making it ideal for use in power supplies, audio amplifiers, and motor control circuits. TIP3055 is a versatile transistor that can be used in a variety of circuit designs due to its high current gain and fast switching speeds. Its popularity can be attributed to its low cost, high reliability, and ease of use. With its ability to handle high power and voltage, TIP3055 is a go-to component for any circuit designer looking for a reliable power transistor.

It comes in a TO-247 package.
This is handy as it can be mounted to a heat sink with a nut bolt.

Datasheet Links

ST – https://www.st.com/resource/en/datasheet/tip3055.pdf

Onsemi – https://www.onsemi.com/pdf/datasheet/tip3055-d.pdf

Do all the companies that manufacture TIP3055 have exactly the same pinouts?

The TIP3055 transistor has a standardized pinout, which means that all manufacturers of this transistor must follow the same pinout configuration. The pinout configuration for the TIP3055 transistor is as follows:

  • Pin 1: Base
  • Pin 2: Collector
  • Pin 3: Emitter

Therefore, no matter which company manufactures the TIP3055 transistor, the pinout configuration should always be the same, and you can expect the same pinout configuration for TIP3055 transistors from different manufacturers. However, it is always recommended to check the datasheet provided by the manufacturer to confirm the pinout configuration and other specifications before using the transistor in a circuit.

Posted on — Leave a comment

STM32F103C8T6 Blue Pill

The STM32F103C8T6 development board which is also known as Blue Pill is a small and affordable development board. It is based on the ARM Cortex-M3 processor and features 64KB of flash memory, 20KB of SRAM, and a maximum clock speed of 72MHz. The Blue Pill is a popular choice for hobbyists and developers who want to experiment with embedded systems and microcontrollers. In this blog post, we will take a closer look at the Blue Pill’s schematic diagram and pinout.

Documents

STM32F103C8 Product Page
Datasheet

How to program the stm32f103c8t6?

Step 1: Setting up the development environment

To program the Blue Pill, you will need a development environment that includes the necessary tools and software. A popular choice is the STM32CubeIDE, which is an integrated development environment (IDE) that includes a compiler, debugger, and other tools. You will also need to download the STM32F1xx HAL library, which provides a set of functions for configuring and controlling the microcontroller.

what are the other IDE which can be used to program stm32f103c8t6?

  • Keil MDK: Keil MDK is an integrated development environment (IDE) that supports the ARM Cortex-M processor family, including the STM32F103C8T6. It includes a compiler, linker, debugger, and other tools for developing embedded applications.
  • Eclipse IDE: Eclipse is a popular open-source IDE that supports a wide range of programming languages and platforms, including the STM32F103C8T6. Eclipse provides a plugin called “GNU ARM Eclipse” that includes tools for building and debugging ARM-based projects.
  • Visual Studio Code: Visual Studio Code is a popular open-source code editor that supports a wide range of programming languages and platforms, including the STM32F103C8T6. You can use Visual Studio Code with extensions to provide support for C/C++ development, debugging, and uploading code to the board.

Can IAR Embedded Workbench be used to program?

Yes, IAR Embedded Workbench is another popular IDE that can be used to program the STM32F103C8T6. IAR provides a comprehensive toolchain that includes a C/C++ compiler, linker, and debugger, as well as tools for code analysis and optimization.

Step 2: Configuring the microcontroller

Before writing code for the Blue Pill, you need to configure the microcontroller’s peripherals and registers. This involves setting up clock and power management, GPIO pins, timers, interrupts, and other peripherals, depending on your project’s requirements. The STM32F1xx HAL library provides functions for configuring the microcontroller, which you can use in your code.

Step 3: Writing and compiling the code

Once the microcontroller is configured, you can write your code using a programming language such as C or C++. You can use the STM32F1xx HAL library functions to interact with the microcontroller’s peripherals and registers. Once you have written your code, you need to compile it using the compiler included in your development environment.

Step 4: Uploading the code to the board

Once you have compiled your code, you need to upload it to the Blue Pill board. This involves connecting the board to your computer using a USB cable and using a programming tool such as ST-Link or J-Link to upload the code. You can use the programming tool’s software or your development environment’s built-in upload tool to upload the code.

Schematic Diagram:

The STM32F103C8T6 Blue Pill’s schematic diagram is relatively simple and straightforward. The board features a 3.3V voltage regulator, which is used to provide power to the microcontroller and other components. The board also includes an external crystal oscillator (HSE) and a 32.768 kHz crystal oscillator (LSE) for real-time clock (RTC) functionality.

Other key components on the board include:

Reset circuitry: The Blue Pill features a reset button and an external reset circuit to ensure the reliable and safe operation of the microcontroller.
USB connector: The board includes a USB connector that can be used for programming and communication with the microcontroller.
LED indicators: There are two LED indicators on the board, one for power and one for user-defined purposes.

Pinout:

The STM32F103C8T6 Blue Pill’s pinout is organized into four rows of headers, with a total of 20 pins. Here is a brief overview of the pin functions:

  • PA0 to PA15: These pins are general-purpose input/output (GPIO) pins that can be used for a variety of purposes, including digital input/output and analog input.
  • PB0 to PB15: These pins are also GPIO pins, with the same capabilities as the PA pins.
  • PC13 to PC15: These pins are typically used for the onboard LED indicators, but can also be used as GPIO pins.
  • VDD: This is the 3.3V power supply pin.
  • VSS: This is the ground pin.
  • BOOT0: This pin is used to select between the bootloader and the user code during programming.
  • NRST: This is the reset pin.
  • SWDIO and SWCLK: These pins are used for programming and debugging the microcontroller using the Serial Wire Debug (SWD) protocol.

The STM32F103C8T6 Blue Pill is a versatile and affordable development board that is well-suited for a wide range of projects. Its simple schematic diagram and clear pinout make it easy to work with, even for beginners. With its powerful ARM Cortex-M3 processor, ample memory, and rich set of peripherals, the Blue Pill is a great choice for anyone looking to dive into the world of microcontroller programming.

Posted on — Leave a comment

Convert mA to A

Enter milli Ampere (mA):
Ampere (A)=

Definition

Ampere = One coulomb of charge going through per second

Milliampere = one-thousandth of an ampere

Formula

mA = A / 1000

Where:
mA = milliampere
A = Ampere

Example

Question: How to convert 800mA to A?
Answer:
800 x 10-3 = 800 milliampere
800 / 1000 = 0.8A

deutsche Sprache

Frage: Wie rechnet man 800 Milliampere in Ampere um?
Antwort:
800 x 10-3 = 800 milliampere
800 / 1000 = 0.8A

Posted on — Leave a comment

BD139 Pinout

The BD139 is a general-purpose NPN bipolar junction transistor (BJT). It has three pins:

  1. Base (B)
  2. Collector (C)
  3. Emitter (E)

There are two companies that manufacture the transistor

  1. STMicroelectronics
  2. onsemi

The pinout diagram according to STMicroelectronics is as follows:

When looking at the center hole and keeping the metal side down the pins are arranged from right to left as:

  1. Base (B)
  2. Collector (C)
  3. Emitter (E)

It’s important to note that the metal tab is connected to the Collector pin.

The pinout diagram according to ON Semiconductor is as follows:

When looking at the flat side of the transistor with the pins facing down and the metal tab facing up, the pins are arranged from left to right as follows:

  1. Emitter (E)
  2. Collector (C)
  3. Base (B)

It’s important to note that the metal tab is connected to the Collector pin.