0
\$\begingroup\$

The question is because in porting code from a PIC16F15324T using MCC to a project using a PIC 32MX470F512L.

There are portions of code where i have code like this:

    TMR1 = 0; // Starts counting
    while (TMR1 < TIME_BIG_PULSE_CONFIRM) // Minimum time to be considered big pulse
    {

        if (!data_in_get_value()) {
            if (!data_in_get_value()) { // Simple debounce - confirm twice
                break; // Get out of the while
            }
        }
    }

This may seem like a noob question, but are do the increments of TMR happen what same time if i configure both timers for 8us? Of course i know that the pic with the higher frequency is supposed to execute instrutions a lot faster (that would be true if MCC was optimized for the pic32)

PIC16 MCC:

enter image description here enter image description here

PIC32 MCC:

enter image description here enter image description here

\$\endgroup\$
  • \$\begingroup\$ what does PIC32 MCC say if you request 8MHz? \$\endgroup\$ – Bruce Abbott Jun 8 '19 at 3:22
  • \$\begingroup\$ @bruceabbott hi, you mean if I don't use pll? It works. MCC doesn't give a warning. \$\endgroup\$ – Nmaster88 Jun 8 '19 at 16:32
  • \$\begingroup\$ "MCC doesn't give a warning" - if it calculates a period of 8us then it should be fine (the period count will be different of course, due to the higher PBCLK frequency). \$\endgroup\$ – Bruce Abbott Jun 8 '19 at 21:35
  • \$\begingroup\$ @bruceabbott I think that is really my doubt! How can I count period count then? Because I was assuming that if the calculated period is equal for both that the period count would happen at the same time. \$\endgroup\$ – Nmaster88 Jun 9 '19 at 9:59
  • \$\begingroup\$ MCC calculates the required count to get the period you want. This count then has to go in the timer setup code (either automatically generated or manually if you are writing your own routines). If the clock frequencies are different then the timers have to be set up differently to get the same period. The 8 bit and 16 bit timers have a slightly different setups, but MCC takes care of it for you.. \$\endgroup\$ – Bruce Abbott Jun 9 '19 at 11:00
1
\$\begingroup\$

All PIC timers increment at each input clock cycle. Older PIC16 only have system clock as a timer input (plus an external pin) while newer ones usually have pre- and postscalers, multiple clock sources, etc. For you code to work in the same way you need the same input clock. Find out the exact timer clock on your PIC16 and make it the same on PIC32.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Hello @olegmazurov So the actual period in Pic16 and calculated period in pic32 is not the time for each increment of the timer? If i put 8us for both are they not supposed to increment at same time? \$\endgroup\$ – Nmaster88 Jun 8 '19 at 20:29
  • \$\begingroup\$ Period is an integer multiple of clock cycles. Your code doesn't use it. You need to make sure the input clock to the PIC32 timer is equal to the one used in PIC16, after all pre- and postscalers \$\endgroup\$ – Oleg Mazurov Jun 9 '19 at 22:10
  • \$\begingroup\$ OK, in this case I have different input clock for the timers, maybe I can put the pic32 timer equal with pre-scaler. Can you confirm if the calculated period in pic32, or actual period in pic16 is when they get back the counting to 0? So if I access TMR1 in my code after 8us TMR1 will be back to 0, right? \$\endgroup\$ – Nmaster88 Jun 9 '19 at 23:18
  • \$\begingroup\$ You can confirm the frequency by toggling the pin every 10000 counts, say and measuring the frequency on the pin with some other instrument - oscilloscope, freq.counter, etc. Coming to the right one is a matter of reading datasheets, and in case of PIC32, family reference manual AKA FRM. \$\endgroup\$ – Oleg Mazurov Jun 10 '19 at 15:51

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.