Author |
Message |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 6:54 am Subject: Measuring time between two events (Solved) |
Ok, thanks to everyone. Not only did i solve my original problem but learnt some new things on the way. Next time i'll try to catch any mistakes using printf() also. |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 6:23 am Subject: Measuring time between two events (Solved) |
I edited my last post and said that this unsigned int16 rise,fall,time;
unsigned int32 local_time;
solves all issues just like you said. But i don't really understand why. Could you elaborate pleas ... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 6:05 am Subject: Measuring time between two events (Solved) |
OK, i changed them to unsigned int16's and i don't get any more random numbers:40028 us
40028 us
40024 us
40028 us
40028 us
but when the time measured is longer than 60ms i get wrong readings.
... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 5:36 am Subject: Measuring time between two events (Solved) |
Long was changed to an int32 which is a signed by default, i forgot to change it in my original post.
I actually still get the random number but not as frequently:
40024 us
40028 us
40028 us
... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 4:09 am Subject: Measuring time between two events (Solved) |
Ok i changed the code as you said:
while(TRUE) {
output_high(PIN_B4);
delay_ms(10);
output_low(PIN_B4);
delay_ms(20);
output_high(PIN_B0) ... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Thu May 03, 2018 3:32 am Subject: Measuring time between two events (Solved) |
I connected the output to the default pin for CCP2 and now i get:
29605 us
27715 us
4294932551 us
28902 us
4294933805 us
30047 us
28002 us
4294932841 us
expecting 130000us from the original ... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Wed May 02, 2018 6:41 am Subject: Measuring time between two events (Solved) |
while(TRUE) {
output_high(PIN_B4); // fed to CCP1 (pin_9)
delay_ms(10);
output_low(PIN_B4);
delay_ms(20);
output_high(PIN_A3); ... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Wed May 02, 2018 3:12 am Subject: Measuring time between two events (Solved) |
It's a DIP18. |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Tue May 01, 2018 11:10 am Subject: Measuring time between two events (Solved) |
Yeap. So if i add SETUP_TIMER_1(T1_INTERNAL | T1_DIV_8 ); then it should be ok, no? (8/4)/8=250KHz, 4us and 32500 counts for 130ms. I still get the same output. |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Tue May 01, 2018 7:46 am Subject: Measuring time between two events (Solved) |
So, timer 1 is counting at 0.5us (8MHz/4) and it takes 260000 counts to reach 130ms so a int32 is needed. Right?
Now i get:
4292821246 us
4292821246 us
4292821246 us
Did i connect the output ... |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Tue May 01, 2018 7:20 am Subject: Measuring time between two events (Solved) |
I am testing the output pins with an oscilloscope and it looks ok. |
Topic: Measuring time between two events (Solved) |
irmanao
Replies: 25
Views: 44713
|
Forum: General CCS C Discussion Posted: Tue May 01, 2018 7:13 am Subject: Measuring time between two events (Solved) |
I wanted to test an example code for measuring time between two events for a future project, so i used this CCP code from the ccs manual.#int_ccp1
void isr()
{
rise=CCP_1; // CCP_1 is ... |
Topic: Problem measuring pulse width with one CCP |
irmanao
Replies: 15
Views: 31710
|
Forum: General CCS C Discussion Posted: Sun Sep 24, 2017 10:46 am Subject: Problem measuring pulse width with one CCP |
16bit
#include <16F1827.h>
#fuses PLL, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(internal=8000000)
#use rs232(baud=9600,xmit=PIN_B5,rcv=PIN_B2,bits=8,ERRORS)
in ... |
Topic: Problem measuring pulse width with one CCP |
irmanao
Replies: 15
Views: 31710
|
Forum: General CCS C Discussion Posted: Sun Sep 24, 2017 9:46 am Subject: Problem measuring pulse width with one CCP |
Ok, i changed the code a bit:#INT_EXT
void ext_int (void){
set_timer1(dms);
clear_interrupt(int_timer1);
enable_interrupts(INT_TIMER1);
}
#INT_TIME ... |
Topic: Problem measuring pulse width with one CCP |
irmanao
Replies: 15
Views: 31710
|
Forum: General CCS C Discussion Posted: Thu Sep 21, 2017 8:24 am Subject: Problem measuring pulse width with one CCP |
I got a bit confused about the timer interrupt part of your comment..
This is what i came up with..#INT_EXT // zero crossing
void ext_int (void){
flag=1;
}
#INT_TIMER0
void ... |
|