![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hello Guys,
I want to know exactly how to use timer. Lets say I have a requirement like this: A light kit system for rc car that blink a LED when no activity or system is idle for more than 10 seconds. I want to learn how to use Timer0 in this case, but I never know how to make it because I am still a newbie in programming. Can anyone help me? I am using PICKIT2 Programmer, PIC18F4520 MCU, and 20Mhz External Oscillator. My program should be programmed by C Language with C18 Compiler. ![]()
__________________
When NewBee asks... |
|
|
|
|
|
|
(permalink) |
|
There are many ways to use the timers, the simplest way is to simply start and stop them. To use a timer to give better resolution of your earlier code you could simply do,
Code:
int GetPulse(){
T1CON=0b0000000; //init Timer 1 - see data sheet
TMR1L=0; //clear the timer count (low byte)
TMR1H=0; //and the high byte
Pulse_tris=1; //make pin input
while(Pulse_in==1); //ensure pin is low to start with
while(Pulse_in==0); //wait until pin goes high
T1CONbits.TMR1ON=1; //start Timer 1
while(Pulse_in==1); //wait for pin to go low again
T1CONbits.TMR1ON=0; //stop timer 1
return TMR1H*256+TMR1L; //return the 16 bit timer value
}
I'll leave it to you to work out the other ways. Mike. |
|
|
|
|
|
|
(permalink) |
|
Ah, this is exactly what my Team Leader told me ystd. the 7500 is neutral position for the steering wheel and left is 5000 and 10000 is right position.
Then the if statement goes with 5000, 7500, and 100000 instead of lower resolution of 14 15 and 16. Is there really another way? Newbie always get lost, just like a born monkey (without parents) in a jungle.
__________________
When NewBee asks... |
|
|
|
|
|
|
(permalink) |
![]() okay several questions to go: 1. If I would go in 16 bits, like Pommie said, I should set this T1CONbits.RD16 = 1; right? 2. Why Pommie didnt set the Prescaler value? 3. T1OSCEN: Timer1 Oscillator Enable bit >> What does it mean? 4. T1CON=0b0000000; //init Timer 1 - see data sheet >> what kind of initialization do I need to setup? 5. What do this tell us? TMR1H*256+TMR1L >> ?? What is this? Thanks!!!
__________________
When NewBee asks... Last edited by mrfunkyjay; 4th June 2008 at 04:53 PM. |
|
|
|
|
|
|
(permalink) | ||||||
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Mike. |
|||||||
|
|
|
|
|
(permalink) |
|
Hello, I would like to continue my program by doing multitasking.
As you know, after I finished with the steering, I programmed myself the throttle function. The program simply read the PWM signal from the throttle channel pwm signal, then process it to flash several LEDs. Two things I noticed here: 1. Both steering and throttle triggers are almost all the time pressed together, but the LEDs, although they are located at different port, A0, A1, A2, etc., the left/right blinking and throttle forward blinking signals cannot executed at the SAME TIME. 2. I have a flashing command takes around 5s to be executed until finished, I don't want to have this, I want to have a flashing command, like a loop, only when the throttle trigger is pressed. So, it comes into a conclusion that the led only switched on when there is a signal and it could be finished either at 2nd 3rd or 4th second, not necessary up to 5th second. My colleague told me about the multitasking with software approach, hope somebody can give me clue regarding this, what do I need, how do I set those up. Thanks!
__________________
When NewBee asks... |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| NPN question- simple? | arrow | General Electronics Chat | 7 | 22nd December 2005 03:24 AM |
| Very simple question 2 | zambalik | General Electronics Chat | 3 | 17th July 2004 11:29 AM |
| simple question~ | cool | General Electronics Chat | 4 | 29th February 2004 09:47 AM |
| very simple question | xjackal | General Electronics Chat | 10 | 25th November 2003 06:50 PM |
| A simple question... | eyevancsu | General Electronics Chat | 3 | 26th March 2003 01:34 PM |