Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

low output voltage

Status
Not open for further replies.

SneaKSz

Member
Hi,

when I declare my pins as ouput and I want to illuminate a LED , the output voltage is 1.7V.

Code:
//#include <18f14k50.h> 
//#include <htc.h>
#include <pic18f1xk50.h> 


        #define PLLEN    = OFF ,     
        #define CPUDIV   = NOCLKDIV  ,
        #define USBDIV   = OFF         
        #define FOSC     = HS
        #define FCMEN    = OFF
        #define  IESO     = OFF
        #define  PWRT     = ON
        #define  BOR      = ON
        #define  BORV     = 30
        #define  WDT      = OFF
        #define  WDTPS    = 1
        #define  MCLRE    = ON
        #define  LPT1OSC  = OFF
        #define  STVREN   = ON
        #define  LVP      = OFF
        #define  XINST    = OFF       // Extended Instruction Set
        #define  CP0      = ON
        #define  CP1      = ON
        #define  CPB      = ON
        #define  WRT0     = ON
        #define  WRT1     = ON
        #define  WRTB     = ON       // Boot Block Write Protection
        #define  WRTC     = OFF
        #define  EBTR0    = OFF
        #define  EBTR1    = OFF
        #define  EBTRB    = ON

	

  #define LCD_PORT		LATC		//	;set constant LEDPORT = 'PORTC'
  #define LCD_TRIS		TRISC		//	;set constant for TRIS register
 //volatile bit LCD_RS @ (unsigned)&LATC*8+4;
			//;LCD handshake lines
  #define LCD_RS LATC4
  #define LCD_RW LATC5
  #define LCD_E	 LATC6


void main(void)
{
  	TRISC = 0;  //	set PortC all outputs
	ANSEL=0x00;
	ANSELH=0x00;
	WPUB=0x00;

	while ( 1)
{
	LATC=0b11111111;
}
	}

I can't see what I'm doing wrong. I've set the bits as digital output.

Someone can see what I'm doing wrong?

Thanks in advance
 
1.7 V sounds like it could be the LED dragging the voltage down if there is no resistor or only a small resistor. That PIC doesn't have a very good output drive capability. The data sheet says:-

Output High Voltage
VDD-0.7 V
IOL = 3.5mA, VDD = 5V
IOL = 3mA, VDD = 3.3V
IOL = 2mA, VDD = 1.8V

2 - 4 mA should light an LED, but it won't be bright. You really need a transistor or another gate to amplify the output to drive an LED.
 
Hello Diver300,

Thanks for the info , but these LED's are from the development board , I've tested them in ASM and there I had a 5V output and the LED's work well, there is a resistor connected between the output ping and the anode of the LED.
 
Can you look at the output with an oscilloscope? Is the LED lighting at all? If not is the voltage being generated by the LED? LEDs will generate some forward current in sunlight. The voltage you get is about the forward voltage that you would get with a current of a few microamps.
 
I do not have an oscilloscope here , but the led is lighting up a little but , when I change the Vdd from 3.3 to 5V the LED illuminates brighter. I think it's a setting because it works well if I use the ASM code.
 
The config is just not good , I can't see where the error is ( compiler HI TECH )
Code:
//#include <18f14k50.h> 
#include <htc.h>
//#include <pic18f1xk50.h> 

//insert these lines before main(){} in main.c to set the fuses for programming automatically
__CONFIG(1, HS & PLLDIS & FCMDIS & IESODIS); //for freq>8Mhz and <20Mhz, use XT instead of HS for <8Mhz
__CONFIG(2,BORDIS & WDTDIS & PWRTEN); //BORDIS=brown out reset disabled, WDTDIS=watch dog timer disabled
__CONFIG(3,MCLREN & HFSTABLE); 
__CONFIG(4,XINSTDIS & DEBUGDIS & LVPDIS & STVREN); //DEBUGDIS=debug disabled, LVPDIS=low voltage programmin disabled
__CONFIG(5,UNPROTECT & CP0 & CPB & CPD ); //unprotected
__CONFIG(6,WRTEN); //flash write enabled


  #define LCD_PORT		LATC		//	;set constant LEDPORT = 'PORTC'
  #define LCD_TRIS		TRISC		//	;set constant for TRIS register
 //volatile bit LCD_RS @ (unsigned)&LATC*8+4;
			//;LCD handshake lines
  #define LCD_RS LATC4
  #define LCD_RW LATC5
  #define LCD_E	 LATC6
 // volatile bit LCD_RS @ (unsigned)&LATC*8+4;

void main(void)
{

 	TRISC = 0x00;//	set PortC all outputs
	ANSEL=0x00;
	ANSELH=0x00;
	WPUB=0x00;
LATC=0xFF;

while(1);
	}
 
Last edited:
You do have a resistor in series with the LED?
 
Yes a resistor is placed in serie with the LED, with the C18 compiler and a other config , the LED's illuminate bright.
 
4700 Ohm. When I use the same code but in C18 ( other config method ) , the LED's illuminate( development board ) .

It's the config that doesn't work , strange problem , I defined the config like it should be , but still no LED's on PORTC illuminate and after installing C18 compiler and changing the config , it worked directly !
 
Last edited:
1.7 V sounds like it could be the LED dragging the voltage down if there is no resistor or only a small resistor. That PIC doesn't have a very good output drive capability. The data sheet says:-

Output High Voltage
VDD-0.7 V
IOL = 3.5mA, VDD = 5V
IOL = 3mA, VDD = 3.3V
IOL = 2mA, VDD = 1.8V

2 - 4 mA should light an LED, but it won't be bright. You really need a transistor or another gate to amplify the output to drive an LED.

You are looking at the wrong spec. That is the output high voltage, meaning, while you are sourcing 3.5ma with 5V VDD, the voltage will be at least 4.3V. The pic18f14k50 can source/sink up to 25ma per pin. In practice it is usually much higher than vdd -0.7 at 3ma. On a side note, that chip is the cheapest micro with hardware USB that I know of.
 
Hi,

when I declare my pins as ouput and I want to illuminate a LED , the output voltage is 1.7V.

Code:
//#include <18f14k50.h> 
//#include <htc.h>
#include <pic18f1xk50.h> 


        #define PLLEN    = OFF ,     
        #define CPUDIV   = NOCLKDIV  ,
        #define USBDIV   = OFF         
        #define FOSC     = HS
        #define FCMEN    = OFF
        #define  IESO     = OFF
        #define  PWRT     = ON
        #define  BOR      = ON
        #define  BORV     = 30
        #define  WDT      = OFF
        #define  WDTPS    = 1
        #define  MCLRE    = ON
        #define  LPT1OSC  = OFF
        #define  STVREN   = ON
        #define  LVP      = OFF
        #define  XINST    = OFF       // Extended Instruction Set
        #define  CP0      = ON
        #define  CP1      = ON
        #define  CPB      = ON
        #define  WRT0     = ON
        #define  WRT1     = ON
        #define  WRTB     = ON       // Boot Block Write Protection
        #define  WRTC     = OFF
        #define  EBTR0    = OFF
        #define  EBTR1    = OFF
        #define  EBTRB    = ON

	

  #define LCD_PORT		LATC		//	;set constant LEDPORT = 'PORTC'
  #define LCD_TRIS		TRISC		//	;set constant for TRIS register
 //volatile bit LCD_RS @ (unsigned)&LATC*8+4;
			//;LCD handshake lines
  #define LCD_RS LATC4
  #define LCD_RW LATC5
  #define LCD_E	 LATC6


void main(void)
{
  	TRISC = 0;  //	set PortC all outputs
	ANSEL=0x00;
	ANSELH=0x00;
	WPUB=0x00;

	while ( 1)
{
	LATC=0b11111111;
}
	}

I can't see what I'm doing wrong. I've set the bits as digital output.

Someone can see what I'm doing wrong?

Thanks in advance

I don't understand how this would have compiled. #define statements do not use = signs. In C18, those options are set using the #pragma directetive, for example:
#pragma config PLLEN = OFF, WDT = off
 
Looking again, since you never used any of those things you defined, the bad code wouldn't be inserted anywhere so it would compile.
 
Looking again, since you never used any of those things you defined, the bad code wouldn't be inserted anywhere so it would compile.

Thanks , the code that U quoted was from the Hi tech compiler . That has to be something with __config(1,....)

This is the working config for C18 :

Code:
#include <p18f14k50.h> 
#include <xlcd.h>
#include <delays.h>
//#include <usart.h>
//#include <htc.h>
//#include <pic18f1xk50.h> 
# include <string.h>


	#pragma config    CPUDIV = NOCLKDIV
	#pragma config    USBDIV = OFF  
	#pragma config    FOSC = HS
	#pragma config    PLLEN = OFF 
	#pragma config    FCMEN = OFF
	#pragma config    IESO = OFF 
	#pragma config    PWRTEN = ON
	#pragma config    BOREN = ON
	#pragma config    BORV = 30
	#pragma config    WDTEN = OFF
	#pragma config    WDTPS = 1
	#pragma config    MCLRE = ON
	#pragma config    HFOFST = ON 
	#pragma config    STVREN = ON 
	#pragma config    LVP = OFF
	#pragma config    BBSIZ = OFF 
	#pragma config    XINST = OFF
	#pragma config    CP0 = ON 
	#pragma config    CPB = ON 
	#pragma config    CPD = ON 
	#pragma config    WRT1= ON 
	#pragma config    WRTB = ON 
	#pragma config    WRTC = ON 
	#pragma config    WRTD = ON 
	#pragma config    EBTRB = ON

Thanks !
 
Last edited:
Please post the exact code that produces the problem along with the offending compiler clearly labeled
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top