CC5x, Delay Example, PIC16F690, Help! | All About Circuits

  • Network Sites:
    • Latest
    • News
    • Technical Articles
    • Latest
    • News
    • Technical Articles
    • Market Insights
    • Education
    • Latest
    • Projects
    • Education
  • Industry Tech Days is a free 5-day virtual conference. Learn More
All About Circuits
  • Log In
  • Join
    • Log in
    • Join AAC
    • Or sign in with
      • Facebook
      • Google
      • Linkedin
      • GitHub
0:00 / 0:00
  • Podcast
  • Latest
  • Subscribe
    • Google
    • Spotify
    • Apple
    • Heartradio
    • Stitcher
    • Pandora
    • Tune In
Menu
  • Articles
    • Latest
    • News
    • Projects
    • Technical Articles
    • Industry Articles
    • Industry White Papers
  • Forums
    • Latest
    • Hardware Design
    • Embedded & Programming
    • Education
    • Math & Science
    • Community
  • Education
    • Textbooks
    • Video Lectures & Tutorials
    • Worksheets
    • Industry Webinars
    • Virtual Workshops
  • Tools
    • Calculators
    • Part Search
    • Test Equipment Database
    • Bom Tool
    • IC Design Center
  • Videos
    • Latest
    • New Products
    • Video Tutorials
    • On-Demand Webinars
    • Tech Chats
    • Virtual Workshops
  • Datasheets
  • Giveaways
  • Industry Tech Days
  • Partner Content Hub
  • Podcast
    • Connect with us
    • Network Sites:
All About Circuits Microcontrollers

CC5x, delay example, PIC16F690, Help!

Join our Engineering Community! Sign-in with:

  • Home
  • Forums
  • Embedded & Programming
  • Microcontrollers
CC5x, delay example, PIC16F690, Help!
  • Thread starter gargoor
  • Start date May 23, 2015
G Thread Starter

gargoor

Joined Jan 5, 2009 6 Ladies & Gents, I have been going through timer0 and its studeis. Everytime I get close to understand the delay function given in CC5x compiler, I end up confused. I want to delay 1s the leds I got connected to chip. But I can't figure how to calculate exactly a delay of one second. I understand the following formula Next * Presc * 1/Fosc/4 = delay and the functionality of Timer0 as I read from some tutorials and the datasheet But I'm confused .. Please see the code and the questions below the following code Code: void delay_ms( uns16 millisec) // // Delays a multiple of 1 milliseconds at 4 MHz // using the TMR0 timer { OPTION = 2; // prescaler divide TMR0 rate by 8 TMR0 = 2; // deduct 2*8 fixed instruction cycles delay char next = 0; do { next += 125; // Does it start from 125 to 256 or 0 to 125 ? clrwdt(); // needed only if watchdog is enabled while (TMR0 != next) // 125 * 8 * (1/4MHz/4)= 1 ms ; } while ( -- millisec != 0); } /*-------------------------------------------------- subroutine: main parameters: none returns: nothing task: Main program function Light red leds then delay then light yello ---------------------------------------------------*/ void main(void) { OPTION = 0; Init(); while(1) { //Init(); D0(); Delay_ms(1000); D1(); Delay_ms(1000); //it is too fast you got to change the time delay or add more functions to see disco light D2(); Delay_ms(1000); } } Here are my questions : 1. void delay_ms( uns16 millisec) // what is uns16 ? why not just int or signed ? I guess it isn't signed because PIC16f690 doesn't use 2's complement? 2. do { next += 125; // Does it start from 125 to 256 or 0 to 125 ? clrwdt(); // needed only if watchdog is enabled while (TMR0 != next) // 125 * 8 * (1/4MHz/4)= 1 ms How much is TMR0? . Is 1ms the time it takes to count next till 256 (till overflow)? ; } while ( -- millisec != 0); Is --millisec equals 1000 and it reduces to 999, 998 ..... so on till 0 ? how much time it takes to do so ? } 3. while(1) { //Init(); D0(); Delay_ms(1000); // What is 1000 for ? It subtitues millisec variable . so then it reduces 1000 to 999 to 998 and so on ? or how? D1(); Delay_ms(1000); 4. How much is standard F0sc in PIC16f690, is it 4MHz ? Last edited: May 23, 2015 Scroll to continue with content ErnieM

ErnieM

Joined Apr 24, 2011 8,393 I see two things in your questions: you need a better understanding of C, and you also need to know your target PIC device better. You would be well served to find some tutorials written for this compiler to follow. I know of none, and if you do not find any I suggest changing to a free the Microchip compiler where you can get such tutorials (along with a hardware board that allows you to run all the tutorials).
gargoor said: 1. void delay_ms( uns16 millisec) // what is uns16 ? why not just int or signed ? I guess it isn't signed because PIC16f690 doesn't use 2's complement? Click to expand...
Why would you need to guess? You chose the CC5X compiler, one I have never heard of before, yet I was able to absolutely find the definition for this symbol in a couple of minutes by simply Reading The Fine Manual (RTFM) for your compiler. You should have found it faster as that manual would have been in your download package. It means "millisec" is an unsigned 16 bit integer. And the PIC16f690 absolutely does indeed use 2's complement. In this case there is no such thing as a negative time delay so a negative number makes no sense so it is not allowed. "millisec" will hold the number of milliseconds the routine will wait until it returns.
gargoor said: 2. do { next += 125; // Does it start from 125 to 256 or 0 to 125 ? clrwdt(); // needed only if watchdog is enabled while (TMR0 != next) // 125 * 8 * (1/4MHz/4)= 1 ms How much is TMR0? . Is 1ms the time it takes to count next till 256 (till overflow)? ; } while ( -- millisec != 0); Is --millisec equals 1000 and it reduces to 999, 998 ..... so on till 0 ? how much time it takes to do so ? } Click to expand...
"next" is defined as an (unsigned) char with an initial value of zero. (CCS makes the char type unsigned by default (RTFM) )"+=" means add the value on the right to the variable on the left. "TMR0" is the Timer1 register in the PIC that holds the current timer time; again RTFM for the PIC you are using. The (very short) while loop waits on that line for 125 counts on Timer1 to occure. If Timer1 is set up corrently it takes 1 full milliseccond for the count to advance by 125 counts. Then the "millisec" variable is decremented and tested to see if the total delay has passed. If not, the loop repeats.
gargoor said: 3. while(1) { //Init(); D0(); Delay_ms(1000); // What is 1000 for ? It subtitues millisec variable . so then it reduces 1000 to 999 to 998 and so on ? or how? D1(); Delay_ms(1000); Click to expand...
1000 is the delay beging requested. 1000 mS is one whole second. Inside the routine the "millisec" variable is initialized to 1000.
gargoor said: 4. How much is standard F0sc in PIC16f690, is it 4MHz ? Click to expand...
There are 8 different internal clock rates and an infinite number of external rates so it entirely depends on how the device is wired and/or configured. You must log in or register to reply here.
Thread starter Similar threads Forum Replies Date
F 2 Off-delay timers - 1 Flashing Light Homework Help 50 Nov 22, 2024
Cyfer_135 Project to produce a 10 hour time delay using 8051 microcontroller Homework Help 23 Nov 14, 2024
S HELP - need assistance with delay circuit please General Electronics Chat 29 Oct 24, 2024
B Seek CC5X directly at B Knudsen Data. Programming & Languages 6 Aug 2, 2012
M need help CC5x pic16f Overlapping code Programming & Languages 4 Feb 1, 2010
Similar threads
2 Off-delay timers - 1 Flashing Light
Project to produce a 10 hour time delay using 8051 microcontroller
HELP - need assistance with delay circuit please
Seek CC5X directly at B Knudsen Data.
need help CC5x pic16f Overlapping code

You May Also Like

  • Harmonic Suppression in Low-Q Class E Amplifiers

    by Dr. Steve Arar

  • UCLA Announces New One-Way Optical Material for Imaging Systems

    by Duane Benson

  • Remembering John B. Goodenough, Inventor of the Lithium-Ion Battery

    by Duane Benson

  • Your Guide to Industry Tech Days 2024

    by Dale Wilson

Top All About Circuits Logo Continue to site QUOTE OF THE DAY -

Từ khóa » Cc5x