Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the Timer2 of a PIC32 to Set a Delay
    primarykey
    data
    text
    <p>I'm pretty much brand new to the PIC32 and its programming in C, so I'm a bit stumped on how to go about the following problem. I've been asked to toggle an LED of the PIC32 on and off, which I can do fine; however, I now wish to add a 0.25s delay between toggling. I've been told to assume that I'm making use of a 72MHz system clock and a 36MHz peripheral bus clock. I know now that Timer2 is a Type B Timer, and that I should configure it for 16 bit ungated operation. I figured I can first set the initial values of TMR2, PR2 and other bits in T2CON as needed before setting TON to start the time, ending it by clearing TON and resetting the initial values.</p> <p>Well, if that above sounds right, how might I do this with C? What I can gather from the reference manual is that it might look something like the following:</p> <pre><code>T2CON = 0x0; // Stop Timer and clear control register, // set prescaler at 1:1, internal clock source TMR2 = 0x0; // Clear timer register PR2 = 0xFFFF; // Load period register T2CONSET = 0x8000; // Start Timer </code></pre> <p>Now, how might I set the prescale and what not so that I can achieve my 0.25s delay? I'm just not good at covering what I need to C, and I'm still not that great at performing this kind of thing in assembly to begin with... Any guidance is appreciated. Here's my code thus far:</p> <pre><code>#include &lt;p32xxxx.h&gt; int main() { while(1) { PORTDbits.RD0 = 1; // Turns LED On? // Delay...? PORTDbits.RD0 = 0; // Turns LED Off? // Delay...? } return 0; } </code></pre> <p>Header File: <code>p32mx360f512l.h</code>, if that is of any use.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload