Logo Banner

ELECTRONICS - [BK1786B supply] - [hardware addon] - [page 4/4]

BK1786B Hardware Addon

The used tools

I wrote the software for the microcontroller in the C programming language, using Microchip's MPLAB IDE and the High-Tech C compiler toolsuite. They can be downloaded for free from Microchip's website. I programmed the microcontroller with my Olimex USB PIC programmer [External].

PIC program

Here you can find the complete firmware for the PIC.

Function of the program

The program uses the asynchronous mode of the PIC's USART (Universal Synchronous Asynchronous Receiver Transmitter). The hardware baud rate is preset to 9600. The hardware address is set to 0x00. Please make sure these settings match the actual settings of your BK unit!

The PIC will transmit a request frame each 100 milliseconds. Then it will wait for the next cycle. It uses this waiting time to receive and process any data from the BK unit. Each time a byte is received, an interrupt (TXIF) is triggered. The interrupt handler will then build a data array containing all the received bytes.

After the reception of the 26th byte, the software function processResponse() is called. This function will validate the received data. During the validation process the frame length, checksum and response code are verified. Once the data has been validated successfully, the 10th data byte is analyzed. This byte contains the state of the power supply unit. The third bit of this byte will be evaluated and the PIC will start the orange output LED if this bit is "1". (See Part2 : Communication Aspects for more information about the protocol)

Error codes

My circuit uses a RED flashing LED to indicate any errors. I have implemented 5 different error codes:

Download

Download the PIC source code for this project. The code comes in a ZIP file with the complete MPLAB project.


Copyright ©1998-2022 Vanderhaegen Bart - last modified: August 24, 2013