Software and hardware design experience and skills in the development process of PIC microcontroller - Database & Sql Blog Articles

Single chip microcomputer STM32L151CCU6
SMD aluminum electrolytic capacitor
1206RGB (single)
Probe domestic switch needle KG-300K, needle head diameter is 3.0mm, normally open switch needle
Supply SMD LED Light Emitting Diode SMD LED LED Beads 0603, 080

This article provides insights and practical tips gathered from the author’s experience in PIC microcontroller development, aiming to help others improve their own projects.

1. How to Further Reduce Power Consumption

Power efficiency is a key concern for battery-powered devices. The PIC16C×× series MCUs are known for their low power consumption, with an operating current of less than 2mA at 4MHz under 5V. To further reduce power usage while still meeting performance needs, one effective approach is to lower the operating frequency. For example, when running at 32kHz on 3V, the current can drop to as low as 15μA. However, this may slow down certain operations like mathematical computations. In such cases, using an RC oscillator allows you to increase the frequency temporarily during critical calculations.

The method involves connecting a resistor (R1) between an I/O pin (e.g., RB1) and the OSC1 pin. When the system is in low-speed mode, RB1 is set to 0. During high-speed tasks, RB1 is set to 1, which charges a capacitor quickly, increasing the oscillation frequency. After the task completes, RB1 is reset to 0, returning the system to low-power mode. R1 should be chosen carefully—too small a value may prevent proper oscillation, so it's typically recommended to use more than 5kΩ.

Another way to reduce power is by using the "sleep" instruction. When the CPU enters sleep mode, power consumption drops to just a few microamps. This is especially useful for waiting for events or implementing delays. For instance, you can use "sleep()" in a delay loop, allowing the system to remain idle until an interrupt wakes it up. It's important to manage the WDT (Watchdog Timer) and interrupts properly to avoid unexpected behavior.

Example 1 (Mplab-C): Delay() { for (i=0; i<=10; i++) SLEEP(); } Example 2 (Masm): Delay: movlw .10 movwf Counter Loop1: Sleep decfsz Counter goto Loop1 return

2. Handling the RBIF Bit in INTCON

The RBIF bit in the INTCON register indicates whether a change has occurred on PORT B. However, the interrupt enable bit in INTCON does not affect the status of RBIF itself. If RBIF is already set before enabling the interrupt, it could trigger an unintended wake-up. Therefore, it's essential to clear RBIF before enabling the interrupt and again after processing the event to avoid errors.

3. Writing PIC Programs in Mplab-C

When embedding assembly code in C programs, each line between #asm and #endasm must be on its own line. Otherwise, the compiler will throw an error. For example:

Example 3: While(1) { #asm ... #endasm } /* This will not compile correctly */ While(1) { #asm ... #endasm } /* This compiles correctly */

3.2 Safe Addition and Multiplication

In Mplab-C, multiplication and addition operations may not behave as expected due to data type limitations. For instance, multiplying two 8-bit variables may result in an overflow. To avoid this, it's safer to break the operation into steps:

Example 4: unsigned int a = 200; unsigned int b = 2; unsigned long c; c = a; c *= b; /* This ensures correct calculation */

3.3 Understanding Multiply/Divide Functions

The PIC microcontroller's RAM space is limited, and the Mplab-C compiler does not release memory used for multiplication and division functions. This means that variables may conflict with internal registers used by these operations. To prevent unexpected results, it's best to review the generated assembly code and ensure no overlap occurs. For example, the multiplication function may use addresses like 0x13, 0x14, 0x19, and 0x1A. Always check the disassembled code before finalizing your program.

4. Programming with EPROM Chips

For users without a hardware emulator, EPROM chips are commonly used for debugging. However, each time a program is modified, the chip must be erased and reprogrammed, which can be time-consuming and reduce the chip's lifespan. Fortunately, if the changed bit is from '1' to '0', you can reprogram the chip without erasing the previous content. This is especially useful for small adjustments during debugging.

During testing, it's common to make minor changes. If these changes allow for a '1' to '0' transition, you can continue programming without erasing. Also, using the NOP instruction can help during debugging. If an instruction is removed, replace it with NOP first. After compiling, the original program can be reused without issues.

Finally, be cautious when programming EPROM chips, especially with newer fuse-based security features. Once the security fuse is set to '0', the chip can be reprogrammed without being erased. This is a useful feature but must be handled carefully to avoid unnecessary waste.

High Voltage Transmission Line

We have got 220kV Transmission Line Steel Pole Quality Certificate from Power Industry Steel Tower Qualified Inspection & Test Center from 2001 year.

Our steel poles are made from quality sheet through bending, forming, automatic welding and hot galvanization. We can reach one-run machining length of 14m and can bend sheet of thickness up to 45mm. We adopt advanced welding procedures, automatically weld main joints and reach rank-II welding quality. We supply more than 4000ton Substation Structure for our clients every year.

Transmission Line Steel Pole, Utility Pole, Steel Tubular Pole, High Voltage Transmission Line

JIANGSU XINJINLEI STEEL INDUSTRY CO.,LTD , https://www.steel-pole.com