Home‎ > ‎PIC18F4550‎ > ‎Tutorial List‎ > ‎

Voltmeter Using RTOS and PIC18F4550

As the name suggest, this project is a simple Voltmeter which can measure Voltage from Range 0-5V and this can be increased, but to make things simple we are going only for a smaller range i.e 0 to 5V.

The specialty of this project is that it used the RTOS for exact timing operations.

Here is the Circuit Diagram



The code for this is written in CCS-PIC-C Compiler, and is available as follow:-

Voltmeter using PIC18F4550 RTOS Code

//RTOS Based Voltmeter Program

#include<18f4550.h>
#device ADC = 10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

#use rs232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)

//LCD PIN CONFIGURATION
#define LCD_ENABLE_PIN  PIN_D2
#define LCD_RS_PIN      PIN_D0
#define LCD_RW_PIN      PIN_D1
#define LCD_DATA4       PIN_D4
#define LCD_DATA5       PIN_D5
#define LCD_DATA6       PIN_D6
#define LCD_DATA7       PIN_D7

#include <lcd.c>

unsigned int16 adc_data;
float voltage;
int8 To_Lcd[10];

//Initializing the RTOS Program
#use rtos(timer = 0, minor_cycle = 100ms)

//Task Called after every 200msec
#task(rate = 200ms, max = 1ms)
void Live()
{
        output_toggle(PIN_B0);        //Toggle the State of LED after 200msec
}

#task(rate = 2s, max = 100ms)
void Get_Voltage()
{
        //Get Voltage and Convert It
        adc_data = read_adc();
        voltage = adc_data * 5;
        voltage = voltage / 1023;
}

#task(rate = 2s, max = 100ms)
void Send_To_LCD()
{
        //Display Converted Voltage at LCD
        sprintf(To_Lcd,"%.4f",(float)voltage);
        lcd_putc("\fVolatge:-");
        lcd_gotoxy(1,2);
        printf(lcd_putc,To_Lcd);
        printf(lcd_putc," Volts");
}

#task(rate = 2s, max = 100ms)
void Send_To_RS232()
{
        //Display Converted Voltage at Serial Port at a Baud Rate of 9600bps
        printf("Volatage = %.4f Volts\n\r",voltage);
}


void main()
{
        set_tris_d(0x00);
        output_d(0x00);
        lcd_init();
        printf(lcd_putc,"  RTOS EXAMPLE!\n");
        printf(lcd_putc,"    VOLTMETER");
        set_tris_a(0xff);
        setup_adc_ports(ALL_ANALOG);
        setup_adc(ADC_CLOCK_DIV_64);
        set_adc_channel(0);
        delay_us(10);
        rtos_run();
}

The video shown below demonstrate how it works in real-time.

Voltmeter using PIC18F4550 (RTOS)

 

For More information Contact us at:-
matlab.academy@gmail.com
Comments