Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:08:45+00:00 2026-05-25T23:08:45+00:00

I’m pretty much brand new to the PIC32 and its programming in C, so

  • 0

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.

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:

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

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:

#include <p32xxxx.h>

int main()
{
    while(1)
    {
        PORTDbits.RD0 = 1;    // Turns LED On?
        // Delay...?
        PORTDbits.RD0 = 0;    // Turns LED Off?
        // Delay...?
    }
    return 0;
}

Header File: p32mx360f512l.h, if that is of any use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:08:46+00:00Added an answer on May 25, 2026 at 11:08 pm

    the name of the header file IS of use … based on that filename i guess this is the chip you have to work with … http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532441

    on that page you can find some code samples in c, so that should cover questions like “how to work with this chip in c”

    so for your general approach:

    a loop is a nice idea, but since you are given a type b timer in ungated mode, i think that should be a hint to use interrupt handlers to do the work … have a look at http://ww1.microchip.com/downloads/en/DeviceDoc/61105E.pdf (section 14.4) on how to set this up

    in the ISR compare the timer/counter value with a value you will have to calculate based on the clock freq and the prescaler setting, so you will know when the desired time has come to flip the bit

    after the bit is flipped, reset the timer for the next cycle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.