Click here to Skip to main content
15,391,980 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Lock a file Pin
Richard MacCutchan5-Nov-12 22:10
mveRichard MacCutchan5-Nov-12 22:10 
GeneralRe: Lock a file Pin
Iain Wiseman6-Nov-12 19:29
MemberIain Wiseman6-Nov-12 19:29 
GeneralRe: Lock a file Pin
Richard MacCutchan5-Nov-12 3:00
mveRichard MacCutchan5-Nov-12 3:00 
AnswerRe: Lock a file Pin
Sarath C5-Nov-12 22:01
MemberSarath C5-Nov-12 22:01 
GeneralC CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
STEVE10K3-Nov-12 7:34
MemberSTEVE10K3-Nov-12 7:34 
GeneralRe: C CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
Tr@v3-Nov-12 11:15
MemberTr@v3-Nov-12 11:15 
GeneralRe: C CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
STEVE10K5-Nov-12 7:57
MemberSTEVE10K5-Nov-12 7:57 
AnswerRe: C CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
Tr@v7-Nov-12 7:47
MemberTr@v7-Nov-12 7:47 
Try something like the following for your interrupt handlers. Depending on the micro you select, how to install these will be different. I would stay away from PIC parts, I personally don't like them. The Atmega family of MPU should be better to work with in my opinion, although my personal favorite these days is the Freescale Kinetis family of MPU's. You can get demo boards in the form of expandable towers from Freescale.

[EDIT] You may also want to handle rollover for the counter variable if you expect to have counts high enough for this to happen.

C++
#define S1  (1 << 0)
#define S2  (1 << 1)

unsigned char sensorFlags = 0;
int counter = 0;

/* interrupt handler for S1 */
void s1_isr(void)
{
 if(sensorFlags & S2)
 {
    /* Exiting, decrement counter */
    --counter;
    /* clear S2 flag */
    sensorFlags &= ~S2;
    /* Get timestamp, store it, transmit to remote host
      this will depend a lot on your hardware */
 }
 else if(sensorFlags & S1)
 {
    /* ERROR same sensor tripped twice, handle as necessary */
 }
 else
 {
    /* Entering, set S1 flag */
    sensorFlags |= S1;
 }

  /* clear interrupt flag if necessary */
}

/*interrupt handler for S2 */
void s2_isr(void)
{
 if(sensorFlags & S1)
 {
    /* Entering, increment counter */
    ++counter;
    /* clear S1 flag */
    sensorFlags &= ~S1;
    /* Get timestamp, store it, transmit to remote host
      this will depend a lot on your hardware */
 }
 else if(sensorFlags & S2)
 {
    /* ERROR same sensor tripped twice, handle as necessary */
 }
 else
 {
    /* Exiting, set S2 flag */
    sensorFlags |= S2;
 }

 /* clear interrupt flag if necessary */
}


modified 7-Nov-12 14:05pm.

GeneralRe: C CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
STEVE10K8-Nov-12 3:41
MemberSTEVE10K8-Nov-12 3:41 
GeneralRe: C CODE FOR RUNNING TWO SENSORS FOR BI-DIRECTIONAL COUNTING Pin
STEVE10K3-Dec-12 2:49
MemberSTEVE10K3-Dec-12 2:49 
QuestionC++ question. Please help me out Pin
Member 88567522-Nov-12 9:06
MemberMember 88567522-Nov-12 9:06 
AnswerRe: C++ question. Please help me out Pin
jeron12-Nov-12 9:18
Memberjeron12-Nov-12 9:18 
AnswerRe: C++ question. Please help me out Pin
Richard MacCutchan2-Nov-12 10:23
mveRichard MacCutchan2-Nov-12 10:23 
AnswerRe: C++ question. Please help me out Pin
Amarnath S3-Nov-12 20:49
professionalAmarnath S3-Nov-12 20:49 
Questionhow to return value after user input Pin
Member 21198442-Nov-12 5:11
MemberMember 21198442-Nov-12 5:11 
AnswerRe: how to return value after user input Pin
Richard MacCutchan2-Nov-12 6:25
mveRichard MacCutchan2-Nov-12 6:25 
GeneralRe: how to return value after user input Pin
Member 21198442-Nov-12 8:16
MemberMember 21198442-Nov-12 8:16 
GeneralRe: how to return value after user input Pin
Richard MacCutchan2-Nov-12 10:19
mveRichard MacCutchan2-Nov-12 10:19 
AnswerRe: how to return value after user input Pin
Santhosh G_2-Nov-12 6:34
MemberSanthosh G_2-Nov-12 6:34 
GeneralRe: how to return value after user input Pin
Member 21198442-Nov-12 7:51
MemberMember 21198442-Nov-12 7:51 
GeneralRe: how to return value after user input Pin
Santhosh G_2-Nov-12 15:32
MemberSanthosh G_2-Nov-12 15:32 
GeneralRe: how to return value after user input Pin
Member 21198442-Nov-12 17:19
MemberMember 21198442-Nov-12 17:19 
GeneralRe: how to return value after user input Pin
Santhosh G_2-Nov-12 17:26
MemberSanthosh G_2-Nov-12 17:26 
GeneralRe: how to return value after user input Pin
Member 21198442-Nov-12 17:33
MemberMember 21198442-Nov-12 17:33 
GeneralRe: how to return value after user input Pin
Santhosh G_2-Nov-12 18:01
MemberSanthosh G_2-Nov-12 18:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.