CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Timing until Pin HIGH

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
twizz0



Joined: 26 Jun 2006
Posts: 3

View user's profile Send private message

Timing until Pin HIGH
PostPosted: Mon Jun 26, 2006 7:51 am     Reply with quote

Hello. I am very new to PIC programing and am looking for a very simple answer to what is possibly a very simple question. I have searched this forum and am unable to find and answer to my question (well one i understand anyway). All I need is a way to time the gap between me setting a pin High and other pin going high thats it. Please can somone help me.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 26, 2006 8:04 am     Reply with quote

Several ways of doing it. Picking which way depends on whether or not anything else needs to happen in the mean time. It could be as simple as setting the pin high. Start a timer running. Poll for the other pin to become high. Read the timer value. If you need the processor to do stuff in between. Then use an interrupt. Either and external edge triggered one or one of the CCP pins (if the pic has the ccp module). For this, you would set you pin high. Start a timer. And then wait for the interrupt. There is some latency associated with the interrupt. For the external interrupt, you would have to adjust for this. If using the CCP module, it captures the timer value when the event occurs so you only need to read the CCP value.
twizz0



Joined: 26 Jun 2006
Posts: 3

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 8:08 am     Reply with quote

No the pic doesnt need to do anything else at the same time so how do i setup a timer an use it (sorry really new to this)
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 26, 2006 8:11 am     Reply with quote

Read the manual (help file). There are examples under the sections. There are also example files and there is a search option for the forum. Look at setup_timer# in the manual.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Jun 26, 2006 8:11 am     Reply with quote

EX_CCPMP.C
Uses the PIC CCP module to measure a pulse width
twizz0



Joined: 26 Jun 2006
Posts: 3

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 8:24 am     Reply with quote

Yeah unfortunetly i dont understand any of them thats why I am asking for help, sorry
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Jun 26, 2006 9:33 am     Reply with quote

I can't post the code. BUT.. there are 9 lines of code
line
1)print a message
2)setup ccp1 with a rising edge. This count how often tmr1 overflows
3)setup ccp2 with a falling edge. This count how often tmr1 overflows
4)setup tmr1 as a time base. The count values then can be scaled to a time.
5)enable CCP2 interupt remember we are using the falling edge
6)trun on GLOBAL interupts// must turn on both CCP2 and global
7)while loop
8)a delay
9)print result.

We use two counters,
we store the count values at Riseing edge and falling edge.
subract the two counts and the difference is a scaled time of the pulse width.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group