Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877A problem digital output from pins

Status
Not open for further replies.

Thunderhorse312

Member level 1
Joined
May 7, 2012
Messages
32
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,286
Activity points
1,526
Hi, i am having problems with the output pins of my PIC16F877A microcontroller because whenever i turn an output pin on there is less than 5 Volts found in that certain pin (i.e. RB0). I need the 5 volts to drive my relay also using a relay driver. I saw from my voltmeter that only 4 to 3 volts are outputted on the pins i turn on. How do i provide an output of 5V?

here's my code
Code:
#include <htc.h>
#include <pic16f877a.h>
#include "delay.c"
#define _XTAL_FREQ 20000000
__CONFIG(0x3FFE);


unsigned int ADCRead(unsigned char channel)
{
	
		

	unsigned char l_byte, h_byte;		//Variables in exchange for ADRESL and ADRESH
	unsigned int ADR;					//stores the Analog to Digital input value

	
	
	ADCON0 = 0x81;						//sets what channel to be used for analog input
	DelayUs(50);						//acquistion time delay
	GO_DONE = 1;						//start the A/D conversion

	while(GO_DONE == 1); 				//wait for the bit to be cleared

	l_byte = ADRESL;					//set l_byte as ADRESL
	h_byte = ADRESH;					//set h_byte as ADRESH

	ADR = (h_byte << 8)|l_byte;			//shift ADRESH 8 places to the left and be ORed with ADRESL


	return ADR;

}



	void main(void)
		{
			#define Weight25 469
			#define Weight30 474
			#define Weight31 475
			#define Weight35 479
			#define Weight36 480
			#define Weight40 484
			#define Weight41 485
			#define Weight46 490
			#define Weight47 491
			#define Weight52 496
			#define Weight53 497
			#define Weight58 502
			#define Weight59 503
			#define Weight64 508
		        #define Weight65 509
			#define Weight70 514
			#define Weight71 515
			#define Weight76 520
			#define Weight77 521
			#define Weight82 526
			#define Weight83 527
			#define Weight88 532
			#define Weight89 533
			#define Weight94 538
		//	#define Weight95 539
		//	#define Weight100 544
			unsigned int Ch0,i;		//initialize variable for Analog input voltage

			CMCON = 7;				//disable comparator
			PORTD = 0;
			TRISD = 0;
			PORTB = 0;
			TRISB = 0;

			ADCON0 = 0x81;
			ADCON1 = 0xC0;

		while (1)
				{
				

				Ch0 = ADCRead(0);

					if (Ch0 >= Weight25)
					{
						if (Ch0 <= Weight30)
							{
								RB0 = 1;
							}
							else
								{
								RB0 = 0;
								}

					}
					else
					{
								RB0 = 0;
					}



					if (Ch0 >= Weight31)				//weight 31 - 35
					{
						if (Ch0 <= Weight35)
							{
								RB1 = 1;
							}

							else
								{
								RB1 = 0;
					}
					}
					else
					{
								RB1 = 0;
					}


					if (Ch0 >= Weight36)					//weight 36 - 40
					{
						if (Ch0 <= Weight40)
							{
								RB2 = 1;
							}

							else
								{
								RB2 = 0;
								}
					}
					else
					{
								RB2 = 0;
					}


					if (Ch0 >= Weight41)					//weight 41 - 46
					{
						if (Ch0 <= Weight46)
							{
								RB3 = 1;
							}
							else
								{
								RB3 = 0;
								}

					}
					else
					{
								RB3 = 0;
					}


					if (Ch0 >= Weight47)					//weight 47 - 52
					{
						if (Ch0 <= Weight52)
							{
								RB4 = 1;
							}
							else
								{
								RB4 = 0;
								}

					}
					else
					{
								RB4 = 0;
					}


						if (Ch0 >= Weight53)					//weight 53 - 58
					{
						if (Ch0 <= Weight58)
							{
								RB5 = 1;
							}

							else
								{
								RB5= 0;
								}
					}
					else
					{
								RB5 = 0;
					}


						if (Ch0 >= Weight59)					//weight 59 - 64
					{
						if (Ch0 <= Weight64)
							{
								RB6 = 1;
							}
							else
								{
								RB6 = 0;
								}

					}
					else
					{
								RB6 = 0;
					}


						if (Ch0 >= Weight65)					//weight 65 - 70
					{
						if (Ch0 <= Weight70)
							{
								RD0 = 1;
							}

							else
								{
								RD0 = 0;
								}
					}
					else
					{
								RD0 = 0;
					}



						if (Ch0 >= Weight71)					//weight 71 - 76
					{
						if (Ch0 <= Weight76)
							{
								RD1 = 1;
							}
								else
								{
								RD1 = 0;
								}

					}
					else
					{
								RD1 = 0;
					}


		        	if (Ch0 >= Weight77)					//weight 77 - 82
									{
										if (Ch0 <= Weight82)
											{
												RD2 = 1;
											}
												else
												{
												RD2 = 0;
												}

									}
									else
									{
												RD2 = 0;
									}

					if (Ch0 >= Weight83)					//weight 83 - 89
									{
										if (Ch0 <= Weight89)
											{
												RD3 = 1;
											}
												else
												{
												RD3 = 0;
												}

									}
									else
									{
												RD3 = 0;
									}


}

return;

}

In this code i am trying to open a pin from PORTB and PORTD so that i could drive relays. Thanks!
 

Hi, i am having problems with the output pins of my PIC16F877A microcontroller because whenever i turn an output pin on there is less than 5 Volts found in that certain pin (i.e. RB0). I need the 5 volts to drive my relay also using a relay driver. I saw from my voltmeter that only 4 to 3 volts are outputted on the pins i turn on. How do i provide an output of 5V?

here's my code
Code:
#include <htc.h>
#include <pic16f877a.h>
#include "delay.c"
#define _XTAL_FREQ 20000000
__CONFIG(0x3FFE);


unsigned int ADCRead(unsigned char channel)
{
	
		

	unsigned char l_byte, h_byte;		//Variables in exchange for ADRESL and ADRESH
	unsigned int ADR;					//stores the Analog to Digital input value

	
	
	ADCON0 = 0x81;						//sets what channel to be used for analog input
	DelayUs(50);						//acquistion time delay
	GO_DONE = 1;						//start the A/D conversion

	while(GO_DONE == 1); 				//wait for the bit to be cleared

	l_byte = ADRESL;					//set l_byte as ADRESL
	h_byte = ADRESH;					//set h_byte as ADRESH

	ADR = (h_byte << 8)|l_byte;			//shift ADRESH 8 places to the left and be ORed with ADRESL


	return ADR;

}



	void main(void)
		{
			#define Weight25 469
			#define Weight30 474
			#define Weight31 475
			#define Weight35 479
			#define Weight36 480
			#define Weight40 484
			#define Weight41 485
			#define Weight46 490
			#define Weight47 491
			#define Weight52 496
			#define Weight53 497
			#define Weight58 502
			#define Weight59 503
			#define Weight64 508
		        #define Weight65 509
			#define Weight70 514
			#define Weight71 515
			#define Weight76 520
			#define Weight77 521
			#define Weight82 526
			#define Weight83 527
			#define Weight88 532
			#define Weight89 533
			#define Weight94 538
		//	#define Weight95 539
		//	#define Weight100 544
			unsigned int Ch0,i;		//initialize variable for Analog input voltage

			CMCON = 7;				//disable comparator
			PORTD = 0;
			TRISD = 0;
			PORTB = 0;
			TRISB = 0;

			ADCON0 = 0x81;
			ADCON1 = 0xC0;

		while (1)
				{
				

				Ch0 = ADCRead(0);

					if (Ch0 >= Weight25)
					{
						if (Ch0 <= Weight30)
							{
								RB0 = 1;
							}
							else
								{
								RB0 = 0;
								}

					}
					else
					{
								RB0 = 0;
					}



					if (Ch0 >= Weight31)				//weight 31 - 35
					{
						if (Ch0 <= Weight35)
							{
								RB1 = 1;
							}

							else
								{
								RB1 = 0;
					}
					}
					else
					{
								RB1 = 0;
					}


					if (Ch0 >= Weight36)					//weight 36 - 40
					{
						if (Ch0 <= Weight40)
							{
								RB2 = 1;
							}

							else
								{
								RB2 = 0;
								}
					}
					else
					{
								RB2 = 0;
					}


					if (Ch0 >= Weight41)					//weight 41 - 46
					{
						if (Ch0 <= Weight46)
							{
								RB3 = 1;
							}
							else
								{
								RB3 = 0;
								}

					}
					else
					{
								RB3 = 0;
					}


					if (Ch0 >= Weight47)					//weight 47 - 52
					{
						if (Ch0 <= Weight52)
							{
								RB4 = 1;
							}
							else
								{
								RB4 = 0;
								}

					}
					else
					{
								RB4 = 0;
					}


						if (Ch0 >= Weight53)					//weight 53 - 58
					{
						if (Ch0 <= Weight58)
							{
								RB5 = 1;
							}

							else
								{
								RB5= 0;
								}
					}
					else
					{
								RB5 = 0;
					}


						if (Ch0 >= Weight59)					//weight 59 - 64
					{
						if (Ch0 <= Weight64)
							{
								RB6 = 1;
							}
							else
								{
								RB6 = 0;
								}

					}
					else
					{
								RB6 = 0;
					}


						if (Ch0 >= Weight65)					//weight 65 - 70
					{
						if (Ch0 <= Weight70)
							{
								RD0 = 1;
							}

							else
								{
								RD0 = 0;
								}
					}
					else
					{
								RD0 = 0;
					}



						if (Ch0 >= Weight71)					//weight 71 - 76
					{
						if (Ch0 <= Weight76)
							{
								RD1 = 1;
							}
								else
								{
								RD1 = 0;
								}

					}
					else
					{
								RD1 = 0;
					}


		        	if (Ch0 >= Weight77)					//weight 77 - 82
									{
										if (Ch0 <= Weight82)
											{
												RD2 = 1;
											}
												else
												{
												RD2 = 0;
												}

									}
									else
									{
												RD2 = 0;
									}

					if (Ch0 >= Weight83)					//weight 83 - 89
									{
										if (Ch0 <= Weight89)
											{
												RD3 = 1;
											}
												else
												{
												RD3 = 0;
												}

									}
									else
									{
												RD3 = 0;
									}


}

return;

}

In this code i am trying to open a pin from PORTB and PORTD so that i could drive relays. Thanks!




first simply on and off that perticular pin and check output voltage. ensure that 5V is coming or not..
 

The 16f877a will output 5V on its output pins provided the supply to it is 5V and the load current is very small. If you are drawing any significant current then the output voltage will drop.
 

What relay driver are you using? Most use bipolar transistors so it's the current being drawn by the driver that causes the voltage drop and it's normal to do so.

Incidentally, although not wrong, it's more conventional to put #define blocks before the code in C as the values can't be changed by the program anyway. #defines are only used at compile time with the particular one you chose being hard coded into the program.

Brian.
 

Did you ensure that the 5V supply stays constant and does not drop to 3 or 4 volts? Measure the voltage across the VDD and VSS and see if the voltage is fixed at 5V or not.

What is the amount of current drawn from the I/O pin?

Take a look at figure at Figure 18-16 on page 206 of the 16F877A datasheet.

Here it is:
21_1340377003.png


Voltage at the output pin decreases as current draw increases. So, the driver may be drawing an amount of current that causes the voltage to drop to 3 to 4 volts.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top