MCU Examples.com
PIC Microcontroller Project Examples, free source codes and resources collection.


Automated checking weighing system

Software design

For testing the system a prototype had to be developed and the program was developed according to the prototype developed. The microcode was developed using MPLAB. Since a prototype was developed the following assumptions were made.

  1. The Reflective IR Sensor is modelled as a button switch where a button press and release indicates that the sensor had detected a package.
  2. The two pneumatic arms are modelled as two LEDs where the motion of the arm is represented by an LED lit for a particular amount of time.
  3. Strings of data coming from the weighing scale to the microcontroller are modelled as strings of data provided to the microcontroller from the computer using the hyper terminal.
  4. A Data Packet from the weighing scale is assumed to be as in the diagram below.

 

The software was developed according to the flow chart given and based on the assumptions made. The program utilizes the USART module of the PIC16F877A microcontroller and the interrupts. Most weighing scales output RS-232 serial data therefore the USART [Asynchronous Mode] module was used. A data reception is identified by an interrupt. Serial transmission from the PIC is also used for the testing purposes where it is used to transmit the data received back to the computer’s Hyper Terminal.

Initially all required PORTS, Interrupts and Modules are initialized. When the button switch is pressed it means that a package is being detected by the Reflective IR sensor. After a package is detected a delay is given such that the delay time is the time taken for a package to come on to the weighing scale. Practically the weighing scale would be transmitting serial data packets continuously and when the package is on the scale it will be transmitting the weight value in a data packet. Since there is no scale available the computer is used to input serial data to the microcontroller manually in the prototype developed so when the delay is given (delay for the package to come to the weighing scale) the program awaits for data and when data is entered to the microcontroller from the computer a interrupt takes place and program goes to the interrupt routine. In the interrupt routine each data byte received is saved and altogether 40 data bytes are saved. Each time a byte is saved, the saved byte is transmitted to the computer where it is printed in the Hyper Terminal. This allows us to see whether the typed character is transmitted and saved properly. Once all 40 bytes are saved again they are transmitted to the computer one by one in the order which they were received. When 40 bytes have been saved the starting point of a saved data packet is identified by identifying the starting point of the data packet. When the starting point is identified it is assumed that the weight value of the package is located at the 3rd place from the starting point. This identified value is the 100th place value of the weight value and the next successive byte is the 10th place value of the weight value and the following weight value is the unit place value. These three values are saved in the PIC and they are converted to a binary value and added together to get the weight of the package. Then this value is checked with the desired weight limit 225±5g. If the package weight is within the set weight limit pneumatic arm 1 will be activated in the real situation but in the prototype this is modelled as a LED lit up (connected to PORTB, 4th pin) for a particular period of time. If the package weight is above or below the weight limit pneumatic arm 2 is activate where it is modelled as another LED connected to PORTB, 3rd pin.