View previous topic :: View next topic |
Author |
Message |
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
12F675 - Interrupt does not work |
Posted: Thu Oct 04, 2007 5:12 am |
|
|
I make an intellectual seat heater for my car. Here is the schematic:
When I turn the RV1 an interrupt must occur. But it does't. Where is my mistake?
Here is the code:
Code: |
#include <12F675.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES BANDGAP_HIGH
#use delay(clock=4000000)
#define HEATER PIN_A2
#define GREEN PIN_A1
#define RED PIN_A5
short int was_off;
int mode=0, oldmode=0;
int16 count; //max 7200 for 30 min
#int_RA
void RA_isr(void)
{
mode=read_adc();
count=0;
}
void main()
{
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_div_4);
enable_interrupts(INT_RA);
enable_interrupts(GLOBAL);
while (1)
{ //mode=read_adc();
if (mode>250)
mode=255;
if (mode<10)
mode=0;
if(mode!=oldmode) //regulator was changed
{
if (was_off) //2 min full power after start
{ if (count<240){ //maximum setting
output_high(heater);
output_low(GREEN);
output_high(RED);
delay_ms(250);
was_off=false;
}
}
else
{
if(count<=7200)
{
switch (mode)
{
case 0: { //minimum setting
output_low(heater);
output_low(GREEN);
output_low(RED);
delay_ms(255);
break;
}
case 255: { //maximum setting
output_high(heater);
output_low(GREEN);
output_high(RED);
delay_ms(255);
break;
}
default:
{
output_high(heater); //------------/
delay_ms(mode); //low-freq PWM/
output_low(heater); //- T=255ms -/
Delay_ms(255-mode); //------------/
if ((mode>10)&&(mode<=80))
{
output_high(GREEN);
output_low(RED);
}
if ((mode>80)&&(mode<=160))
{
output_high(GREEN);
output_high(RED);
}
if (mode>160)
{
output_low(GREEN);
output_high(RED);
}
break;
}
}
}
}
Count++;
}
if(count>7200) // turn all off after 30 min of inactivity
{
output_low(heater);
output_low(GREEN);
output_low(RED);
oldmode=mode;
was_off=true;
sleep();
}
}
} | [/code] |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Thu Oct 04, 2007 5:39 am |
|
|
INT_RA refers to a digital change on the input pin - not analogue. |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Thu Oct 04, 2007 5:52 am |
|
|
OK, I turn it from min to max (from 0 to 5V) - it is a digital change. No effect. |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 04, 2007 6:00 am |
|
|
You need the pin to be set as a digital input. As soon as you program it for analog, interrupts are no longer available on the pin. Doesn't matter what voltage you apply, if it is analog, there is no interrupt input.
If (for instance), you wanted an interrupt when the voltage rose above a digital level, while still performing analog input, then connect the signal to GP3 as well, and use 'INT_RA3'. This will occur when the signal changes beyond the digital thresholds, and you can read the voltage on RA0, with the analog statements.
Best Wishes |
|
|
|