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.

[PIC] PIC16F676 5k Potentiometer Analog Read Problem

Status
Not open for further replies.

Ali_Ahmer

Newbie level 3
Joined
Jan 7, 2016
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
34
Hello Respected All Members,

I am New in this Forum and PIC Programming. I need a little help.
I am using PIC16F676 MCU with Internal Oscillator clock and internal MCLR Voltage in MikroC Compiler. I want to read two analog inputs of 5K potentiometer connected at RA4 and RA3 to calculate the LED on/off Delay. I have connected a LED on RA0 (Pin 13) of PIC16f676 MCU. I want to limit its time from 1 second to 10 seconds with respect to 5k Potentiometer.

I have pasted my code below, But it gives me some error. I don't know where i was doing wrong:

Code:
sbit LED at RA0_bit;

unsigned int VR1_Value = 0;
unsigned int VR2_Value = 0;

void main(void) 
{

CMCON = 0x07;   //Turn off Comparators
ANSEL = 0x18;  //AN3 and AN4 as Analog Input
ADCON1 = 0x10;  /* set FOSC/8 as ADC clock source */
ADCON0 = 0x00;  /* select channel 0 and turn off ADC */

TRISA3_bit = 1;   //Analog VR2 input
TRISA4_bit = 1;   // VR1 input

TRISA0_bit = 0; // Led pin as an output

LED = 0;

VR1_Value = ADC_Read(4);  // LED OFF Time
VR2_Value = ADC_Read(3);    // LED ON Time

LED = 0;
Delay_ms(VR1_Value);
LED = 1;
Delay_ms(VR2_Value);


}

This is my Proteus Simulation Design:
Proteus.jpg

And Below is my MikroC compiler Configuration Bit Settings:
MikroC_ConfigurationBIt.jpg
 

You can't pass non constant value to
Code:
Delay_ms() function

It expects a const integer value. Use VDelay_ms() instead.
 
Yes sir, Now program ins working with VDelay_ms() , But please guide me a little more that how i can adjust the calculation for 5k potentiometer for 1s to 10s delay?
 

Also, there is no ground connected on your schematic.
And where is infinity loop at the end of main?
 
Yep I have Attached the GND now ... and replace VDD to U1_VDD. Now code is working with VDelay_ms(VR1_Value); , But now how i can do calculation for 1s to 10s delay for 5k potentiometer?
 

If you need maximum 10 second delay then use this assuming 10 bit ADC.

Code:
unsigned int VR1_Value, VR2_Value;

VR1_Value = (unsigned int)ADC_Read(4) * 10000 / 1024;  // LED OFF Time
VR2_Value = (unsigned int)ADC_Read(3) * 10000 / 1024;// LED ON Time

LED = 0;
VDelay_ms(VR1_Value);
LED = 1;
VDelay_ms(VR2_Value);

It doesn't matter whether you use 5K or 10k pot. It only limits the current. The voltage out of pot should be in the range of 0-5V.
 
Yes Thanks brother.... I have solved it out.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top