element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum PIC32 delay help
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 472 subscribers
  • Views 2229 views
  • Users 0 members are here
  • programming.
  • timer
  • delay_timers
  • pic32
Related

PIC32 delay help

sanyika95
sanyika95 over 6 years ago

Hello everyone!

 

I just started to learn PIC32 programming with a PIC32 Ethernet Starter kit. I wanted to blink its led, 1 second on - 1 second off.

 

Here is the code for the delay:

#define USHORT unsigned short

void delayMs(USHORT milisec) {
    T1CON = 0x8010;
    TMR1 = 0x00;
    USHORT i = 0;
    PR1 = 0x40;
    while(i != milisec) {
        while(TMR1) {
        }
        i++;
        TMR1 = 0x00;
    }
    T1CON = 0x00;
    return;
}

 

It just works (or it looks like to work, I haven't measured it with an oscilloscope, just with a "stopwatch") and I don't know why. Can someone explain me?

 

 

The datasheet of the kit:

http://ww1.microchip.com/downloads/en/DeviceDoc/61166A.pdf

 

The datasheet of its PIC:

http://ww1.microchip.com/downloads/en/devicedoc/60001156j.pdf

  • Sign in to reply
  • Cancel

Top Replies

  • fmilburn
    fmilburn over 6 years ago +2
    I am not familiar with the PIC32 but that is strange code. You need to know what the clock speed is and how the dividers to the timer are set. A quick look at the datasheet shows that T1CON is the timer…
  • sanyika95
    sanyika95 over 6 years ago in reply to fmilburn +2
    I don't really know the clock speed. In the datasheets there were a 32kHz and a 8MHz clock as internal. I did my calculation with both of them and none of them worked. As you said, the T1CON is the control…
  • rusgray
    rusgray over 6 years ago +2
    Have you done the simple beginner Harmony tutorial project ? It implements a blinking LED, and does a good job of covering the basics of working with Harmony. It also serves as a good starting point for…
Parents
  • rusgray
    rusgray over 6 years ago

    Have you done the simple beginner Harmony tutorial project? It implements a blinking LED, and does a good job of covering the basics of working with Harmony. It also serves as a good starting point for writing firmware for any hardware involving a supported Microchip MCU, as the heartbeat will tell you if your state machine stops functioning properly.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • sanyika95
    sanyika95 over 6 years ago in reply to rusgray

    I haven't checked, but now I will. Thank you!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • sanyika95
    sanyika95 over 6 years ago in reply to rusgray

    I haven't checked, but now I will. Thank you!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube