SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC18F USB development




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Enabling Timed Interrupts
 Post Posted: Tue Dec 27, 2011 7:15 pm 
Offline

Joined: Tue Nov 15, 2011 12:58 am
Posts: 9
So, I've been playing around with the USB tutorial with some pretty decent results.

Next thing I wanted to try was getting a timed interrupt for timer0 to work with the demo-code.

I saw that there's a place for "application specific low priority interrupt code" and a high priority one.

I was following what this guy did: http://www.edaboard.com/thread197899.html but I can't get anything to work..

I guess there's a non-standard way of setting up a timer0 interrupt that I'm not understanding? I'm really not too sure where to go from here.

Directly from the demo that you have, how would one setup that interrupt?

Any input is greatly appreciated.


Top 
 Profile  
 
 Post subject: Re: Enabling Timed Interrupts
 Post Posted: Tue Dec 27, 2011 9:42 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 898
There are quite a few code examples of using both high and low priority ISRs on this site, however most are for the HiTech C compiler (the Simon18F/UltimateSimon game projects are good examples).

However, there are a number of sites via google that offer good tutorials on the subject; I suggest you start there. ISRs are not so complex once you get the hang of them :)


Top 
 Profile  
 
 Post subject: Re: Enabling Timed Interrupts
 Post Posted: Wed Dec 28, 2011 12:35 am 
Offline

Joined: Tue Nov 15, 2011 12:58 am
Posts: 9
Well MP lab says I have something that's compile-able.

I dont like asking for code assistance, however can you give me a sanity check here?

To setup the timer: (This goes into your initialisePic() function)
Code:
   INTCON2bits.TMR0IP = 0 ;   // Set timer0 interrupt to low priority
   INTCONbits.TMR0IF =0;// Clear the timer0 interrupt flag
   //TMR0L = 106;      // Reset the timer0 counter
   T0CON = 0b11000110; // Timer0 on, 8-bit and 1:16 prescaler
   INTCONbits.TMR0IE = 1;

   // Enable interrupts
   INTCONbits.GIEL = 1;
   //Dont Enable the high one, because its used for USB interrupt stuff, and we are polling.


Then for the lowPriorityISRCode() function:
Code:
void lowPriorityISRCode()
{
   PORTB =0x00;

//   // Application specific low-priority ISR code goes here
if(!HIDRxHandleBusy(USBOutHandle))
    {
   sprintf(debugString, "This is a Timer.");
   debugOut(debugString);
    USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
     }

   INTCONbits.TMR0IF = 0;
}


This should work right? I enabled the timer, enabled the interrupt, gave a priority. However the Timer has never been triggered...


Top 
 Profile  
 
 Post subject: Re: Enabling Timed Interrupts
 Post Posted: Wed Dec 28, 2011 1:46 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 898
Did you set the global interrupt enable flag? (GIE)?


Top 
 Profile  
 
 Post subject: Re: Enabling Timed Interrupts
 Post Posted: Wed Dec 28, 2011 8:07 pm 
Offline

Joined: Tue Nov 15, 2011 12:58 am
Posts: 9
No I didn't set that one high on purpose because if I did it would'nt be recognized as a USB device.

I did find a solution though, and that was in usb_config.h where you have #define polling or interrupt, if I change it over to interrupt based then the device was recognized and I saw a square wave on the output.

Thanks Again.
...I'll probably be back.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 5 posts ] 

Board index » Electronics Projects » PIC18F USB development


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
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 post attachments in this forum

Search for:
Jump to:  
cron
Translated by MaĆ«l Soucaze © 2009 phpBB.fr