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.

Analog Lab help needed

Status
Not open for further replies.

Shake_ECET209

New Member
Hi guys, im writing a program that takes two analog voltages VA[0] and VA[1]. whenever a switch is closed on port B0, blink a LED on portb4 for 100ms only if voltage VA[0] exceeeds voltage VA[1].

I am trying to modify a previous code form another lab, I am kinda lost. I just need to add a switch at b0 and blink an led at b4 for 10mms only if the voltage at Va[0] exceeds Va[1]

Thanks for any help guys


Code:
#include<C:\Program Files\Microchip\Third Party\PICC\Devices\16f88.h>
#fuses INTRC_IO, NOWDT, PUT, NOMCLR, NOBROWNOUT
#use delay(clock=4000000)
unsigned char value;
void setup_16F88();
void infiniteloop(void) ;

void main() 
{	setup_16F88();
	infiniteloop() ;
} 

void setup_16F88(void)
{	set_tris_a(0xbf); 		//Define all possible input Bits as Input
	set_tris_b(0x00); 		//Define as all output bits

/*Setting Analog comparator mode in which there are two analog comparators Comp1 and Comp2. Our analog inputs are applied on Channel AN1 and AN2, the output is available on C2OUT, which is either a ‘0’ or ‘1’. The input to other comparator COMP1 are AN0 and AN3 and the output is available on C1OUT bit. AN0 and AN3 input ports are grounded in this configuration. */

	setup_adc_ports(sAN0|sAN1 |sAN2 |sAN3); 
	delay_us(20); 	// for stabilization
	setup_comparator(A0_A3_A1_A2); 	//A0 and A3 input to Comp1 with output at C1OUT
					//A1 and A2 input to Comp2 with output at C2OUT
}

void infiniteloop(void) 
{	while(1) 
	{ 	output_b(C2OUT);  // the C2OUT is a single bit, put on port_B0.
	}  
}
 
Last edited:
How many Lab's do you have to do?

Anyway, I cant see what the RS232 is doing here apart from just printing out text to the serial port?

I dont see any output for a buzzer in the code you posted, however, I would imagine it would be on portb as that is configured as output.

To remove the RS232 just remove the #use RS232 section and any printf's in the code.

You would be better off leaving an LCD or 232 port connected for debugging the main purpose of comparing voltages.

Speaking of which, have you looked up the comparitor peripheral, i'm not 100% sure the F88 has one, also in your #include, you shouldn't need the full path, just #include 6f88.h
 
lol thanks Wilksey
we have 16 labs altogether
this is 15

This is what I have so far, I am trying to compare the analog voltages from A0 and A1 and, whenever the switch on B0 is closed then an led will blink on b4 for 100 ms ONLY if the voltage Va[0] exceeds Va[1].

I dont get how to add a switch at B0 and LED at B4


Code:
#include<C:\Program Files\Microchip\Third Party\PICC\Devices\16f88.h>
#fuses INTRC_IO, NOWDT, PUT, NOMCLR, NOBROWNOUT
#use delay(clock=4000000)
unsigned char value;
void setup_16F88();
void infiniteloop(void) ;

void main() 
{	setup_16F88();
	infiniteloop() ;
} 

void setup_16F88(void)
{	set_tris_a(0xbf); 		//Define all possible input Bits as Input
	set_tris_b(0x00); 		//Define as all output bits



	setup_adc_ports(sAN0|sAN1 ); 
	delay_us(20); 	// for stabilization
	setup_comparator(A0_A1); 
}

void infiniteloop(void) 
{	while(1) 
	{ 	output_b(C1OUT);  // the C1OUT is a single bit, put on port_B0.
	}  
}
 
This is where I am at now, I just need to throw in a switch on PortB so that whenever the switch goes from low to high an LED at port B4 will light up for 100ms, IF VA[0] is greater than VA[1]





Code:
#include<16f88.h>
#device ADC=8
#fuses INTRC_IO, NOWDT, PUT, NOMCLR, NOBROWNOUT
#use delay(clock=4000000)
unsigned char value;
void setup_16F88();
void infiniteloop(void) ;

void main() 
{	setup_16F88();
	infiniteloop() ;
} 

void setup_16F88(void)
{	set_tris_a(0xbf); 	
	set_tris_b(0x00); 	
	setup_adc_ports(sAN0 |sAN1);


	setup_adc_ports(sAN0|sAN1); 
	delay_us(20); 
	setup_comparator(A0_VR_A1_VR); 	
}

void infiniteloop(void) 
{	while(1) 
	{ 	output_b(C2OUT);  // the C2OUT is a single bit, put on port_B0.
	}  
}
 
Here's some pseudo code that might get you started.
Code:
void infiniteloop(void) 
{
    while(1) 
    { 	
        while(RB0==1);    //wait for no key press
        while(RB0==0);    //wait for key press
        if(C2OUT==1){
            output_b(1);  // the C2OUT is a single bit, put on port_B0.
            delaymS(100);
        }
    }  
}

Mike.
 
Thanks

Nice, Thanks for the help guys.

Ive been working on my project so i kinda fell behind on my lab and it was due yesterday.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top