Hi all,
Firstly this is only sandbox code so it's a bit spaghetti like, the idea here is that when INT3 is high the timer is started which will be a long debounce (this is due to the fact this is going to be a) A very deliberate action with consequences if it 'fires in error' and B) It's going to have to be done by physically bridging INT3 high with a wire!
Now Ed thought I could start Timer1, count the flags a few times then compare, however in the simulator:
INT3 interrupts MAIN and starts timer.
Timer1 is 'doing it's thing'
The interrupt flag never changes, just remains at zero.
As INT3 works correctly I am happy that the interrupt vector is working, I know the INT3 doesn't do anything at the moment but I was building in stages and that can come later once I've got this flag working. I thought it would be quite trivial but I guess I'm missing something. As far as I can see internal interrupts are set.
#define PULSE LATAbits.LATA0 //define pin RA0 as PULSE pin
#define DIR LATAbits.LATA1 //define pin RA1 as DIRECTION pin
#define SPEED PORTBbits.RB0 //Define SPEED H/L Pin
int BCOUNT;
void interrupt high_isr (void){ //High priority interrupt
//set up TIMER1 Count
if (PIR1bits.TMR1IF == 1){
PIR1bits.TMR1IF = 0;
BCOUNT++;
}
if(INTCON3bits.INT3IF == 1){
INTCON3bits.INT3IF = 0;
PIE1bits.TMR1IE = 1; //Enable Timer1 Interrupt
//Start Timer 1 for LONG bounce delay
T1CONbits.RD16 = 0; //Operate in 2x8bit mode
T1CONbits.T1RUN = 0; //Do not use T1CON clock
T1CONbits.T1CKPS = 11; //Prescale 1:8
T1CONbits.T1OSCEN = 0; //Shut down T1 Oscillator
T1CONbits.TMR1CS = 0; //Use FOSC/4
T1CONbits.TMR1ON = 1; //Start timer
DIR= ~DIR;
}
}
void delayfive (int loop) // Prototype for pulse timing, wasteful routine.
{
int i;
for (i=0; i<loop; i++)
{
; //do nothing, this is correct, please do not adjust! - This is just a routine to waste instruction cycles.
}
}
int main () {
//Set device clock - 4MHz operation//
OSCCONbits.IRCF2 = 1; //Make the
OSCCONbits.IRCF1 = 1; //internal clock
OSCCONbits.IRCF0 = 1; //8MHz
TRISAbits.RA0 = 0; //define A0 as OUTPUT
TRISAbits.RA1 = 0; //Define RA1 as OUTPUT
TRISBbits.RB0 = 1; //define RB0 as INPUT
CMCON = 0xFF; //switch OFF comparitors
PWMEN1 = 0xFF; //switch OFF PWM module
ADCON1 = 0xFF; //switch OFF Port-A ADC
//Interrupt Settings//
RCONbits.IPEN = 1; //enable interrupt priority
INTCONbits.GIE = 1; //enable all interrupts
INTCONbits.PEIE =1; //enable internal interrupts
INTCON3bits.INT3IE =1; //enable INT3 external interrupt
INTCON2bits.INTEDG3 =1; //INT3 RISING EDGE interrupt
DIR = 0;
if (SPEED == 1) {
delayfive(100);
PULSE= 1;
delayfive(2);
PULSE= 0;
}
else{
delayfive(10);
PULSE= 1;
delayfive(2);
PULSE= 0;
}
}
The timing isn't critical (and indeed isn't really set up yet) but I expected at least to be able to see BCOUNT merrily count up once INT3 is fired?
What am I doing wrong here?
Cheers,
Ed