0
\$\begingroup\$

I'm new to pic's and the harmony framework, and i'm trying to toggle a pin from high to low and vice versa in the interrupt callback of the Timer.

I configured my oscillator to operate at 32 MHz

enter image description here

enter image description here

or at least is what appears here, so i suppose it's right: enter image description here

Then i configured a Timer Driver, with prescale 256, so each tick is 8us:

enter image description here

Now my question, i want an interrupt to happen at each 8us, and i want to toggle a pin (RG0) at each interrupt. How can that be done?

enter image description here

I see what seems the interrupt code at the file system_interrupt.c: enter image description here

But if inside that function i put the following line:

LATGINV = 0x00000001; nothing happens, i go check on the oscilloscope the signal and there is no toggle.

If i put the same line on main.c it works, the problems is that it doesn't seem to be accessible in system_interrupt.c

\$\endgroup\$
  • 1
    \$\begingroup\$ You have to write code in callback function. It is not generated by Harmony as it is your application code. \$\endgroup\$ – Swanand Jun 12 '19 at 10:11
  • \$\begingroup\$ Hi @Swanand you mean the IntHandlerDrvTmrInstance0 function right? \$\endgroup\$ – Nmaster88 Jun 12 '19 at 10:15
  • \$\begingroup\$ Yes! IntHandlerDrvTmrInstance0 \$\endgroup\$ – Swanand Jun 12 '19 at 10:29
  • \$\begingroup\$ @Swanand but is it a good solution to put code inside that function? It is code generated, every time i generate code i need to check what i need to keep inside, but maybe it's the only way. \$\endgroup\$ – Nmaster88 Jun 12 '19 at 10:32
  • \$\begingroup\$ Why you want to generate code multiple times? You configure the Harmony, Generate basic code and then start writing your application. \$\endgroup\$ – Swanand Jun 12 '19 at 11:26
1
\$\begingroup\$

There are two ways of configuring timers in harmony v2.

i.e. Static or Dynamic

For static timers you need to add your handling code into the system-interrupt.c file timer handler. See here

For dynamic timers you can specify a custom handler in your application code. See here. See 'Creating the ISR' and 'Registering the ISR' sections.

I would use the harmony timer system service, see here, which is a bit simpler implementation and similar to dynamic implementation but might result in less accurate timing due to extra software handling.

LATGINV is not typical usage.

There is pin toggle example code in this example.

To toggle your LATG 0 pin with harmony you may do the following

Initialization

PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_0);

Toggling

PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_0);

The microchip developer help is quite in depth and I'd recommend reading

\$\endgroup\$
  • \$\begingroup\$ Hi @pm101 thanks for the tip. Still in system_interrupt.c it doesn't seem to work. the invert of the pin. \$\endgroup\$ – Nmaster88 Jun 12 '19 at 14:29
  • \$\begingroup\$ LATGINV will not set a pin. Did you see PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_0); and PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_0); in the timer system service example? \$\endgroup\$ – pm101 Jun 12 '19 at 15:32
  • \$\begingroup\$ i already tried using that functions but i will check again, about the LATGINV = 0x00000001 it works when i run in main, it seems valid. Maybe the problem is more than that, the interrupt probably is never called i need to understand why. Thanks. \$\endgroup\$ – Nmaster88 Jun 12 '19 at 15:41
  • \$\begingroup\$ You had to learn to use the debugger, then check if the ISR is called! \$\endgroup\$ – Mike Jun 13 '19 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.