Thread: Using Timer Module in PIC Microcontroller

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    Using Timer Module in PIC Microcontroller

    Can someone please tell me how to produce a period signal that lasts 0.100 ms that is 35% red and 65% green using a bi-colour LED and the timer module?

    EDIT:
    I guess my question is too broad. I think I may be on the right track if someone answer this other question:

    Can someone tell me what this mean instead ?

    while(ReadTimer0() < (unsigned int)165)
    Its using this: OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);

    So does that mean that the period signal is 165 * 32 * 4/32 = 660 = 66%? I really just need to know how to calculate the period signal to produce 35% red and 65% green... If anyone could please help?
    Last edited by trial123; 02-28-2013 at 11:55 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I'm not sure what you're specifically asking here. I'm assuming "produce a period signal that lasts 0.100 ms" means a pulse sequence with a period of 0.1 ms. You do realize that flashing a bi-color LED at a period of 100us is too fast for your eyes to observe - it would just look steady orange.

    What is the period of a repetitive pulse? The time that the signal is high plus the time that the signal is low.

    What's 35% of 100us? That's how long the pin controlling the red side of the LED should be on.
    What's 65% of 100us? That's how long the pin controlling the red side of the LED should be off.

    The pin controlling the green side of the LED should be the inverted red LED signal.

    Then you need to determine the length of an instruction cycle (which for your device, which you didn't specify, is probably the inverse of 1/4 the oscillator/clock frequency). This is how to arrive at the desired count value. You must also note that your prescale value is 1:32, not 1:1, which will affect your target count value.

    Sorry if this didn't answer your question, but you were kind of vague in your request.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Microcontroller id
    By freddarkomf in forum Tech Board
    Replies: 3
    Last Post: 08-20-2012, 06:50 AM
  2. Microcontroller Programming
    By PFactorial in forum C Programming
    Replies: 4
    Last Post: 08-17-2011, 04:33 PM
  3. microcontroller to C++
    By ticrou in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2011, 07:04 AM
  4. Microcontroller ??
    By Cpro0 in forum Tech Board
    Replies: 7
    Last Post: 09-17-2010, 04:07 PM
  5. C for microcontroller
    By phernyt in forum C Programming
    Replies: 2
    Last Post: 12-08-2001, 01:01 PM