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

Its possible to measure many frequencies using just one ICP?

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



Joined: 09 Mar 2021
Posts: 2

View user's profile Send private message

Its possible to measure many frequencies using just one ICP?
PostPosted: Tue Mar 09, 2021 7:20 pm     Reply with quote

Hi everyone. It is possible to measure many frequencies using at least one ICP module from a microcontroller PIC? I want to read frequencies from 4 IR sensors (VS1838). I'm sending 38.4 kHz bursts of 600 microseconds width and pauses of 1 milliseconds width to obtain outputs signals of 625 Hz on each sensor.

These sensors are part of a break beam barrier to detect in/out of people.
Could you give me some advice or suggestions to implement it?
For now I'm using a PIC18F4580.
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 09, 2021 8:27 pm     Reply with quote

Without knowing more about the project, one way is to electronically switch (SP4T) the IR detectors into the CCP module of the PIC.
Simply select a sensor, read it, save the data, repeat 3 more times, update the display/send info to PC. Do it all again....
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Mar 10, 2021 12:39 am     Reply with quote

Also (of course), if he switched to one of the later PIC's with PPS, he could
use this to do the re-routing. So route the CCP to the first sensor pin, do the
measurements on this, then pin_select the next pin, do it's measurement,
etc. etc..
Am a little puzzled though about wanting to measure frequencies
from the VS1838. This generates constant frequencies. It is not a 'sensor',
it is an IR receiver. It receives the pulse train from an IR remote control.
The frequency of this means nothing. It is the pulse widths of the pulse
train that carries the data. If an IR remote control is used, all of these
receivers will pick up the same data train.
If you want to do a break beam system, then use a break beam sensor.
Something like the HLT-DS50CM. This gives a simple on/off output when
the beam is broken.
Osterix



Joined: 09 Mar 2021
Posts: 2

View user's profile Send private message

PostPosted: Wed Mar 10, 2021 1:33 pm     Reply with quote

Thanks for your answers. Well, I'm trying to replicate a passenger counting bar system. This system is made up of two pair of bars (IR emitter and IR receiver) to detect whether a person is getting on or off from a bus.

The IR emitter bar uses 2 IR led, 2 transistors and a Atmega16 microcontroller.
To implement this part, I use an oscilloscope to detect the output frequency (around 38 kHz burst, 600 microseconds width and pauses of 1 millisecond).
I use Arduino to implement this part Embarassed

By the other hand, the IR receiver bar uses 4 IR receiver (2 on top and 2 at bottom) and a Atmega16 microcontroller.

The output of the IR receivers are connected in the following pins:
Pin 13 (PD4 / OC1B) Timer/Counter1 Output Compare B Match Output (top,left)
Pin 14 (PD5 / OC1A) Timer/Counter1 Output Compare A Match Output (top, right)
Pin 15 (PD5 / ICP1) Timer/Counter1 Input Capture Pin (bottom, right)
Pin 16 (PD6 / OC2) Timer/Counter2 Output Compare Match Output (bottom, left)
I leave a reference image of the microcontoller:




At the beginning I tried using the ICP1 from the PIC18F4580 to read one of the IR receivers and then read others using external interrupts and a timer to catch the period. If someone pass through the break beam, the output of the IR receiver change (well, I supposed to do it in this way but I'm quite stuck)


Here is some code, developed in CCS V 4.106
Code:


//======== PIC SETUP===============================================
#include <18F4580.h>
#fuses HS, NOWDT,NOBROWNOUT, NOMCLR, NOPROTECT, NOFCMEN, NOIESO, NOPBADEN
#use delay (internal= 8M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

// PIN DEFINITION
#define sensorIR1  pin_c2
#define sensorIR2  pin_b0
#define sensorIR3  pin_b1
#define sensorIR4  pin_b2
#bit pinC2 = 0xF94.2  // TRISC Bit 2
#bit pinB0 = 0xF93.0  // TRISB Bit 0
#bit pinB1 = 0xF93.1  // TRISB Bit 1
#bit pinB2 = 0xF93.2  // TRISB Bit 2

 
int1 c1;    // Flag to indicate edge change in CCP ISR
int1 c2;    // Flags to indicate edge change in ext interrupt 0,1 and 2
int1 c3;
int1 c4;
 
// Variables to catch the time of change edges
unsigned int16 ticksA=0;
unsigned int16 ticksB=0;
unsigned int16 ticksC=0;
unsigned int16 ticksD=0;
unsigned int16 ticksE=0;
unsigned int16 ticksF=0;
unsigned int16 ticksG=0;
unsigned int16 ticksH=0;


// Read one IR receiver
#int_ccp1
void isr_ccp1()
{ if(c1==0)
 { ticksA=get_timer1();
   setup_ccp1(CCP_CAPTURE_FE);
   c1=1;
 }
 else
 { ticksB=get_timer1();
   setup_ccp1(CCP_CAPTURE_RE);
   c1=0;
   set_timer1(0); }
}

#int_timer1       // Overflows every 262 mS, if the ir receiver is blocked
void isr_timer1()
{ ticksA=0;
  ticksB=0; }


#int_ext
void isr_ext0()
{
  if(c2==0)
  {ticksC=0;=get_timer3();
   ext_int_edge( 0, L_TO_H);
   c2=1; }
  else
  {   ticksD=0;=get_timer3();
      ext_int_edge( 0, H_TO_L);
      c2=0;
  }
}
 
#int_ext1
void isr_ext1()
{
   if(c3==0)
  {ticksE=0;=get_timer3();
   ext_int_edge( 1, L_TO_H);
   c3=1; }
  else
  {
    ticksF=0;=get_timer3();
      ext_int_edge( 1, H_TO_L);
      c3=0;
  }
 }
 
#int_ext2
void isr_ext2()
{
   if(c4==0)
   {ticksG=0;=get_timer3();
   ext_int_edge( 2, L_TO_H);
   c4=1; }
  else
  {
    ticksH=get_timer3();
    ext_int_edge( 2, H_TO_L);
    c4=0;
  }
 
 }
 
void main()
{
   pinC2=1; pinB0=1; pinB1=1; pinB2=1;     // Pines C2,B0,B1 and B2 as inputs
   c1=0; c2=0;c3=0;c4=0;                          // Flags to indicate change of edge   
   setup_ccp1(CCP_CAPTURE_RE);                // CCP Module captures every Rising Edge
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);     // Timer1 counts every 4 microseconds
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);     // Timer3 counts every 4 microseconds
   enable_interrupts(INT_CCP1);                // Here I setup CCP interrupt
   enable_interrupts(INT_TIMER1);             // and external interrupt triggers
   enable_interrupts(INT_TIMER3);
   enable_interrupts(INT_EXT);
   ext_int_edge( 0, H_TO_L);
   enable_interrupts(INT_EXT1);   
   ext_int_edge( 1, H_TO_L);
   enable_interrupts(INT_EXT2);
   ext_int_edge( 2, H_TO_L);
   enable_interrupts(global);                 
   printf("Listo...\r\n");
   while(TRUE)
   {   
     printf("S1: %Lu\r\n" ,4*(ticksB-ticksA));   // Here I just print the                             
     printf("S2: %Lu\r\n" ,4*(ticksD-ticksC));  // duration of every pulse in
     printf("S3: %Lu\r\n" ,4*(ticksF-ticksE));   //  uS to see if it changes
     printf("S4: %Lu\r\n" ,4*(ticksH-ticksG));  //  whenI pass through the
     delay_ms(1000);                                    //barrier
                                 
   }
}


I'm not sure if I should monitor the other pins using just one timer. I hope you could give me any suggestions.
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 10, 2021 3:57 pm     Reply with quote

'Old school' people in a room method..

Have 2 vertical 'bars' of LEDs/sensors about a foot apart.
when a person walk into the room, the outer bar trips then the inner bar.
that show direction of travel... +1 to the people in room counter.

When the inner bar trips, then the outer bar , -1 to the people in room counter.

The electronics is simple, no frequencies...LEDS on solid, it's the sensor placement that is critical, though not too hard, really.
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