View previous topic :: View next topic |
Author |
Message |
P51D
Joined: 25 Jan 2010 Posts: 36
|
Interrupt-Problems |
Posted: Sat May 29, 2010 8:13 am |
|
|
Hello all
I have some problems with the using of one and more interrupts:
First:
Is it possible to have a timer-interrupt at compare-match like the ctc at the avr controllers??
Because at this time I can only create a timer interrupt with set the timer to a value like this:
Code: |
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_1);
set_timer1(65535-40);
enable_interrupts(INTR_GLOBAL|INT_TIMER1);
/*
*/
#int_TIMER1
void SysTime_isr(void){
sys_timer ++;
set_timer1(65535-40);
}
|
then I have a problem with using more than one interrupt routine with a dsPIC30F6012A:
Code: |
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_1);
set_timer1(65535-40);
ext_int_edge(H_to_L);
enable_interrupts(|INT_TIMER1);
enable_interrupts(INT_EXT0);
enable_interrupts(INTR_GLOBAL);
/*
*/
#int_TIMER1
void SysTime_isr(void){
sys_timer ++;
set_timer1(65535-40);
}
#int_EXT0
void FT245_isr(void){
// Read data
}
|
In this way, the second interrupt doesn't work and I don't know why.
Can any one help me?
Best regards
P51D |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat May 29, 2010 8:41 am |
|
|
On the PIC, the _timer_ is separate from the _CTC_.
The timer itself cannot have a 'compare match'. It has no such ability. However the CTC, can test specific timers, and interrupt when they reach a particular value.
On the second, the problem is time. 65535-40, corresponds to 40 instruction times. The first interrupt will be happening so often, that the second is unlikely to ever get called...
Best Wishes |
|
|
P51D
Joined: 25 Jan 2010 Posts: 36
|
|
Posted: Sat May 29, 2010 9:17 am |
|
|
Quote: |
On the second, the problem is time. 65535-40, corresponds to 40 instruction times. The first interrupt will be happening so often, that the second is unlikely to ever get called...
|
The problem is, that I need a time-reference with an exactitude at 1us.
The highest time that I could have is 30us. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat May 29, 2010 9:54 am |
|
|
Are you actually saying you want an interrupt event at 1MHz frequency, or you want a clock to run, counting at 1MHz?. If the former, then I'd have to say 'forget it'. It is technically possible to have an interrupt at this sort of frequency, but if you want to do anything else, there _will_ be problems, even on your PIC, which does have separate interrupt vectoring...
If you want a clock that counts in ticks of 1MHz, then on this PIC, I think you'd have to use two timers. Timer 3, setup as a PWM, with it's comparator set to clear it at 40 counts, and then feed this output to another timer, which will then be counting at the required frequency.
Look at the 'setup_compare' function for the CTC control.
Best Wishes |
|
|
P51D
Joined: 25 Jan 2010 Posts: 36
|
|
Posted: Sat May 29, 2010 12:17 pm |
|
|
Yes, I would have an interrupt event at 1MHz frequency.
The Problem is, that I have to update the peripheral with a frequency of ~27000kHz which is at ~37us.
I see 2 possible solutions:
1) I set the timer down to a interrupt-frequency of 100kHz or just to 27kHz
2) I compare the timer with a variable
which do you think is the better one?
best regards
P51D |
|
|
|