![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi all, I have PIC18F1330. It has two timer, namely timer0 and timer1. I have no problem with timer1. Here are my codes: Code: int GetPulse2(){
T1CON=0b00000000; /*Init timer1*/
TMR1L=0;
TMR1H=0;
TRISAbits.TRISA1=1; /*Make this pin as an input*/
while(PORTAbits.RA1==1); /*Make pin low*/
while(PORTAbits.RA1==0); /*While pin is high*/
T1CONbits.TMR1ON=1; /*Start timer1*/
while(PORTAbits.RA1==1); /*When pin is low*/
T1CONbits.TMR1ON=0; /*Stop timer1*/
return TMR1H*256+TMR1L; /*return 16bit timer value*/
}
PS: I am going to count the Pulse Width of PWM if this info useful.
__________________ When NewBee asks... Last edited by mrfunkyjay; 10th July 2008 at 06:03 PM. | |
| |
| | #2 |
| Try looking at the datasheet and series reference manual, look up the CCP module.
| |
| |
| | #3 |
|
there is no ccp module by the way, is there anything else?
__________________ When NewBee asks... | |
| |
| | #4 |
| That's a shame!. Are you trying to read radio control pulses, or does it vary over a wider range than that?. | |
| |
| | #5 |
|
yes radio control pulse from receiver module. it is between 1ms-1.5ms-2ms. Do you have an idea? Timer is used to make resolution better, and I used it with timer1 before. Now I need another one with timer0. Is it possible? If not, why?
__________________ When NewBee asks... | |
| |
| | #6 | |
| Quote:
I wouldn't get too excited about trying to get massive resolution, I don't think there's that much resolution in the original pulses. | ||
| |
| | #7 |
|
Hi please check this for me, whether I made a mistake or not. To count up to 2ms Pulse Width, I use 8bit timer/counter from timer0 (since PCB is made and timer1 is already used in this PIC18F1330). -8bit timer0 -Prescaler of 8 -FOSC/4 = 1Mhz -frequency input to timer0 would be 1Mhz/8 = 125kHz or T (period) = 8us -since, 8 bit, 0-255 then overflow, 256x8us = 2.048ms which is enough and useable in this case. CALCULATION: 2ms = (1/1Mhz) x 8 x ins.cycle ins.cycle = 0.002s / 0.000008s = 250 RESULT: 250 decimal would be 2ms Pulse Width. divide by two: 125 decimal would be 1ms Pulse Width. center position of servo: 125/2 + 125 = 187.5 ~ 188. then my code would be: Code: int GetPulse1(){
T0CON=0b01000010; /*Init timer0 8 bit, PSA assigned, 1:8 prescale value, reset timer0*/
TMR0L=0;
TMR0H=0;
TRISAbits.TRISA0=1; /*Make this pin as an input*/
while(PORTAbits.RA0==1); /*Make pin low*/
while(PORTAbits.RA0==0); /*While pin is high*/
T0CONbits.TMR0ON=1; /*Start timer0*/
while(PORTAbits.RA0==1); /*When pin is low*/
T0CONbits.TMR0ON=0; /*Stop timer0*/
}
Later I will use 20 gap in between 188. 168 or less as turning left (servo) 169-207 as middle position more than 208 as turning right. Thanks for ur comments!!
__________________ When NewBee asks... | |
| |
|
| Tags |
| timer0 |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Timer0 Prescale | lord loh. | Micro Controllers | 10 | 8th October 2008 06:14 PM |
| TIMER0 - Have I got this right? | UTMonkey | Micro Controllers | 8 | 14th December 2007 11:08 PM |
| PIC Timer0 | Hesam Kamalan | Micro Controllers | 7 | 29th October 2007 03:32 PM |
| Timer0 on PIC's | Hesam Kamalan | Micro Controllers | 4 | 18th July 2006 02:38 PM |
| Using the Timer0 module | wonbinbk | Micro Controllers | 2 | 14th September 2004 07:06 AM |