CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Nested interrupts on 16F

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tonyp



Joined: 25 Jul 2008
Posts: 2
Location: UK

View user's profile Send private message

Nested interrupts on 16F
PostPosted: Fri Jul 25, 2008 4:10 am     Reply with quote

PIC18 devices have compiler methods to allow an interrupt routine to be interrupted by another, higher priority, interrupt but PIC16 devices do not. Can I do the same with PIC16F844 device?

I have a regular 10 ms interrupt (Timer0) doing things that are of less importance than another higher priority interrupt (Timer2). The time for Timer2 to interrupt is constantly varied (it is being used to generate sweeping audio tones that traverse a wide range of frequencies. A square wave at audio frequency is produced by toggling a pin). Sometimes, when the audio output needs to be changed (Timer2 interrupt), there is delay because the Timer0 interrupt is being serviced. This can spoil the audio quality.

I'd like the Timer2 interrupt to break into the Timer0 interrupt, toggle the audio pin, then permit Timer0 interrupt to continue.

Any ideas on whether and how this can be done safely?
Ttelmah
Guest







PostPosted: Fri Jul 25, 2008 4:55 am     Reply with quote

You need to switch to a 18 device.
Problem is that the 16 family only has one true 'interrupt' vector, with all interrupts calling exactly the same point. The 18 chips added hardware support for a second interrupt vector. It is not really something that can be fully solved in software.
That you are having problems, does suggest that the timer interrupt is fairly slow. One thing you can try, that will improve things a little, is to have your timer2 routine as a separate function, have the timer2 interrupt setup to use 'noclear', and call this routine. Have the routine clear the interrupt itself. Then at convenient points inside the timer0 routine, test the timer2 interrupt bit, and if it is true, also call this routine. Since the interrupt will then be cleared, it won't get called again by the hardware.

Best Wishes
tonyp



Joined: 25 Jul 2008
Posts: 2
Location: UK

View user's profile Send private message

Much improved
PostPosted: Fri Jul 25, 2008 8:53 am     Reply with quote

Many thanks, Ttelmah.

Unfortunately I can't move to PIC18 device, however your suggestion regarding the additional function has improved matters considerably. It's still a tiny bit crackly at some frequencies though, so I think my next action will to use a higher oscillator speed to reduce the jitter in the generated audio signal further still.

I'll remember your technique for other applications!

Originally I used the PWM for this purpose but ran into problems. To change the output frequency generating a 50% duty square wave involves updating both the period and the duty. Sometimes, when updating the PWM I got several missed 'on' pulses in a row, due I think to the other unrelated interrupts messing up the PWM update. I guess using the built-in C functions for PWM control takes some time to execute.

Regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group