Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Help in PIC programming?
I am using MikroC Pro for PIC compiler and I having problem with External Interrupt. I am developing Water level controller using PIC 16f628A and I want to trigger external interrupt on RB0/INT pin. When I compile my code my code is compiled but when I practically test it, the RB0 pin acts like GND! in circuit.
My Code is:
sbit OVR_WL at RB2_bit;
//sbit I_WL at RB2_bit; //Input Water sensor
sbit WL_M3 at RB1_bit;//Water level sensor for M3-small motor
sbit M1_M2 at RB3_bit; // Input Pump no.1,2
sbit M3 at RB4_bit; //small motor
sbit M4 at RB5_bit; //large motor
void Overflow(){
if(!OVR_WL){
M3=0;
M4=0;
}
}
void interrupt(){
if(INTCON.INTF==1){
M1_M2=1;
}
else
{
M1_M2=0;
}
INTCON.INTF=0;
}
void Waterlevel_M3(){
if(M3){
if(WL_M3){
M3=0;
}
}
}
void main(){
CMCON=7; //disable comparators
TRISA=0x00; // PortA all O/P
TRISB=0b00000110; // PortB RB1,2,3 are I/P other are O/P
INTCON=0b10010000;
OPTION_REG.INTEDG = 0; // External interrupt on falling edge of RA2/INT pin
M1_M2=0;
do{
if(M1_M2){
delay_ms(1800000);
M3=1;
M4=1;
delay_ms(900000);
M4=0;
Waterlevel_M3();
delay_ms(900000);
Waterlevel_M3();
Overflow();
delay_ms(900000);
Overflow();
Waterlevel_M3();
}
}while(1);
}
1 Answer
- Steve CLv 69 years agoFavorite Answer
Presuming you want the external interrupt triggered by the water sensor (not an external interrupt signal generated by the pic) 1st thing I'd do is disconnect the sensor, and investigate how it reacts. I'd guess the sensor functions somewhat like a a switch to ground, which closes when there's water. If that's the case and you're not putting any power to that switch it's voltage will read as 0V regardless of the state of the switch. If you place a pull up resistor between + and the switch. the voltage between the resistor and the switch, will be + when the switch is open, and near enough to 0V when it's shut.
port B on pics does have internal pull ups that can be enabled, if the pull up for the pin can be enabled you wouldn't need an external pull up . I'm fairly sure pull ups aren't enabled by default. You should also read the data book to ensure the enabling external interrupt pin doesn't disable the internal pull up.
Oh and also keep an eye out for current passing through pin and port. if too much is sunk or sourced the pin/port might cease working- you've got a couple of motors which if driven directly (rather than via transistors) could be too much.