Hi, If you had an application that needed multiple interrupts (5+). Is there a microcontroller that has this? The pic18 devices have 2 but I was wondering if there is an alternative.
"Interrupt on Change" is just one type of interrupt. That means that when the signal changes (high to low, low to high, or either) you can create an interrupt. That function is available on 10 pins (Ports A and B). There are other sources of interrupt too.yeah 5+ interrupts and priority. I thought the pic16 series has only 1 interrupt. I tried to setup 2 timer0 interrupts with the 16f785 but it wouldn't let me. What did you mean by "the 16F1829 has 10 interrupts on change"?
// Configure UART1 RX Interrupt
INTEnable(INT_SOURCE_UART_RX(UART1), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0);
....
// UART 1 interrupt handler
// it is set at priority level 2
void __ISR(_UART_1_VECTOR, ipl2) IntUart1Handler(void)
{
static WORD rx9data;
// Is this an RX interrupt?
if (INTGetFlag(INT_SOURCE_UART_RX(UART1))) {
hoststat.usart1_rxint++;
rx9data = ReadUART1();
put_mbmc_serial_buf((char) rx9data); // put received data in buffer
// Clear the RX interrupt Flag
INTClearFlag(INT_SOURCE_UART_RX(UART1));
}
// We don't care about TX1 interrupt
if (INTGetFlag(INT_SOURCE_UART_TX(UART1))) {
hoststat.usart1_txint++;
INTClearFlag(INT_SOURCE_UART_TX(UART1));
}
}
This is a serious misunderstanding. Timer0 (or timer1, or timer-anything) can only do one thing, and anyway it can't measure a time as long as a second. You'd be better off setting up a repetitive timer interrupt at something like 1000 per second, and then counting occurrences to get the time intervals you want. So you'd have one counter going up to 500, and one going to 1000, in order to give you 500msec and 1sec. Or do you actually want flash rates at those frequencies, so you'd want 250msec on, then 250msec off for one LED, and 500msec on and 500msec off for the other?The priority thing was an option to look at but for now I need some clarity on running multiple interrupts. I have only recently started looking at interrupts and wondered why I couldn't run 2 timer0 interrupts. I wanted to start basic with an led flash every 500ms on 1 and 1s on another.
#pragma config FOSC = INTOSCIO
#include <stdio.h>
#include <pic16f785.h>
#include <xc.h>
#include <stdlib.h>
int count=0;
void delay_1000(void);
void delay_100(void);
void interrupt delay1(void);
void interrupt delay2(void);
int main()
{
OSCCON = 0b00110000; //500kHz osc
T1CON = 0b00000101;
INTCON = 0b11100000;
TMR0 = 0x00;
ei();
TRISC = 0;
ANSEL0 = 0;
ANSEL1 = 0;
while(1);
}
void interrupt delay1()
{
if (INTCONbits.TMR0IF) {
PORTCbits.RC0 = !PORTCbits.RC0;
delay_1000();
INTCONbits.TMR0IF = 0;
return;
}
}
void interrupt delay2()
{
if (INTCONbits.TMR0IF) {
PORTCbits.RC1 = !PORTCbits.RC1;
delay_100();
INTCONbits.TMR0IF = 0;
return;
}
}
void delay_1000()
{
for(count=0; count<1000; count++)
{
if(INTCONbits.T0IF)
{
count++;
INTCONbits.T0IF = 0;
}
}
}
void delay_100()
{
for(count=0; count<100; count++)
{
if(INTCONbits.T0IF)
{
count++;
INTCONbits.T0IF = 0;
}
}
}
First, you need to understand what you're doing.ok so I have tried this code but I get an error saying "more than one interrupt function defined"
int countA = 1;
int countB = 1;
void interrupt isr() {
if (countA == 1) {
// time to toggle gadget A
PORTCbits.RC0 = !PORTCbits.RC0; // BTW: not the best way to do this
}
if (countB == 1) {
// time to toggle gadget B
PORTCbits.RC1 = !PORTCbits.RC1;
}
// step up the calendar
if (countA++ == 7) { // 7 is used here because we want 7-day period (every week)
// If it's Saturday, roll back to Sunday
countA = 1;
}
if (countB++ == 30) { // 30 is used here because we want 30-day period (every month)
// If it's the end of the month, roll back to the first
countB = 1;
}
INTCONbits.TMR0IF = 0; // won't need the alarm until the next morning
}
An ugly abstraction of 8 bit PIC hardware IMO.CCS fakes it by letting you define a function for every interrupt, but of course the hardware doesn't work that way. The compiler is inserting code to do the testing and branching for you.
It depends on what you meant by "interrupt". Low-end PICs don't have support for vectored interrupts. As such, you really have one isr.so I have tried this code
//real isr function
void interrupt myISR(void) {
//tmr0 isr
if (T0IE && T0IF) {
T0IF = 0; //clear the flag
_isrptr_t0isr(); //run tmr0isr
}
//tmr1 isr
if (TMR1IE && TMR1IF) {
TMR1IF = 0; //clear the flag
_isrptr_t1isr(); //run tmr1isr
}
//add more isr support here
}
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
| 4 | alternative to gtop010 module | Microcontrollers | 1 | |
| V | Any one suggest me alternative power supply of below pic | General Electronics Chat | 38 | |
|
|
Alternative Phase Sensitive Detection suggestions needed | Homework Help | 5 | |
| B | max1555 alternative needed??? | Digital Design | 0 | |
| S | Alternative for the IRF710 needed ? | Homework Help | 4 |