PIC32 Multiple timers.

General questions about Firewing...

PIC32 Multiple timers.

Postby jamesbarry2 » Sat Jul 29, 2017 9:04 pm

Could any of you firewing experts help me with the following: using a firewing 32 module, I can use timer one o/k, on it's own, but how does one program the use of several timers to use together, each with it's own interrupt handler? Or else, if I program timer registers manually, how do I assign an interrupt handler to each one? Help would be much appreciated, Thanks....
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm

Re: PIC32 Multiple timers.

Postby Jerry Messina » Sun Jul 30, 2017 10:23 am

If you want to create a new isr module for one of the other timers, take a look at the existing timers.bas file
in Library\MCU32\Interrupt.

Here's an example for timer2 (I've stripped out all the code so it's just a shell).
For a list of all the xxxxx_VECTOR definitions see the files in Library\MCU32\System

Code: Select all
Module Timer2

imports Isr                                  ' interrupt macros and constants

'****************************************************************************
'* Name    : OnTimer (Private)                                              *
'* Purpose : Timer Event handler                                            *
'****************************************************************************
private interrupt OnTimer(TIMER_2_VECTOR, ipl1Software)
   '<<do intr processing>>
   
   ' clear intr flag
   Isr.SetFlag(TIMER_2_VECTOR, 0)
End Interrupt

'****************************************************************************
'* Name    : Start                                                          *
'* Purpose : Start interrupt handling                                       *
'****************************************************************************
Public Sub Start()
   Enable(OnTimer)
End Sub

'****************************************************************************
'* Name    : Halt                                                           *
'* Purpose : Stop interrupt handling                                        *
'****************************************************************************
Public Sub Halt()
   Disable(OnTimer)
End Sub

'****************************************************************************
'* Name    : Main                                                           *
'* Purpose : Initialise the module                                          *
'****************************************************************************
private Inline Sub Main()
   isr.SetPriority(TIMER_2_VECTOR, ipl1)
   isr.SetSubPriority(TIMER_2_VECTOR,0)

   '<<setup your hdw>>

   ' clear intr flag
   Isr.SetFlag(TIMER_2_VECTOR, 0)
End Sub

End Module
Jerry Messina
 
Posts: 256
Joined: Thu Feb 14, 2013 10:16 am

Re: PIC32 Multiple timers.

Postby David John Barker » Sun Jul 30, 2017 10:30 am

setting up interrupts in PIC32 is a little different from a standard PIC. I would recommend you look at some of the open source Firewing libraries first. First one would be "timers.bas" located under the Firewing "library\MCU32" folder. Look at the main sub:

Code: Select all
private Inline Sub Main()
   Count = 0   
   isr.SetPriority(TIMER_1_VECTOR, ipl1)
   isr.SetSubPriority(TIMER_1_VECTOR,0)
   T1CON = 0                ' clear Timer 1 - no presccale
   PR1 = _reloadTimerValue  ' set timer period
   IFS0.3 = 0               ' clear timer interrupt flag
   T1CON.15 = 1             ' switch timer on 
End Sub

much of it will look familiar if you have PIC experience (T1CON, IFS0) but the biggest difference is the calls to

Code: Select all
   isr.SetPriority(TIMER_1_VECTOR, ipl1)
   isr.SetSubPriority(TIMER_1_VECTOR,0)

here you are setting the interrupt priority and vector. You can see a list of available interrupts under the (hidden) file "library\MCU32\System\isr32MX150F128.bas"

Also look at

Code: Select all
private interrupt OnTimer(TIMER_1_VECTOR, ipl1Software)

to see how the vector is assigned. You really need to take a look at the relevant Microchip datasheets on using interrupts under PIC32, but studying the Firewing code will help you loads...
User avatar
David John Barker
 
Posts: 459
Joined: Thu Nov 08, 2012 12:21 pm

Re: PIC32 Multiple timers.

Postby jamesbarry2 » Sun Jul 30, 2017 11:15 am

Thanks for that Guys, I will study it in depth. I had noticed that the compiler switched the CPU to multi vector mode when interrupts were invoked in my code, from that point on I was in uncomfortably deep water....
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm

Re: PIC32 Multiple timers.

Postby jamesbarry2 » Sun Jul 30, 2017 3:18 pm

Thanks again Guys, -Works a treat, -Timers driving Output compare, driving DMA, driving SPI.
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x