View previous topic :: View next topic |
Author |
Message |
USER010 Guest
|
Please I need help with Capture Mode PIC16F |
Posted: Mon Oct 05, 2009 9:46 pm |
|
|
Using CCS on PIC16F876A and I need to have Two signals captured on CCP1 to get their current frequency while each signal is on at a time, in other word two signals have different freqs and interchange their active duration with one another? So I can sample each 30 times/Sec for each one.
Please help. Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 05, 2009 11:03 pm |
|
|
1. What is the source of these signals ? What device is creating them ?
2. Are they multiplexed on 1 wire ? Or, do you have two separate
signals, on two separate wires ?
3. What is the frequency of each signal ?
4. What is the amplitude range of each signal ? Is it 0v to 5v ? |
|
|
help please Guest
|
two sources |
Posted: Wed Oct 07, 2009 12:36 pm |
|
|
Quote: |
1. What is the source of these signals ? What device is creating them ? |
PIC16F876A using CCS Compiler.
IR transmitter diode goes to RC0, red led diode goes to RC1
TSL230R (light2Freq) IC output freq. goes to RC2 (CCP1).
Both LEDs are blinking such that if one off the other is on basically by
toggling each pin state in main.
I used serial to debug. I used the following pseudo for testing:
Code: |
ccp-isr()
{
}
main{
while(1)
if(flag=0){
print RED
flag=1
}else{
print IR:
flag=0
}
}
|
But I get the value of IR copied to Red, at first two repeated values
representing IR then the next two print will representing red, it should be
different, and I want to see one print per each and accurately represent
intensity.
Quote: |
2. Are they multiplexed on 1 wire ? Or, do you have two separate
signals, on two separate wires ?
|
Two separate signals control leds flashing but one output from light conv.
Quote: |
3. What is the frequency of each signal ?
|
Varies based on intensity and that what I want to see...
Quote: |
4. What is the amplitude range of each signal ? Is it 0v to 5v ?
|
IC output is less than 5V or ~ 4V. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 07, 2009 3:53 pm |
|
|
Is a custom project that you are making, or is this another Manchester
decoder for an IR receiver project ? If it's the 2nd one, I think there
is sample code on the forum. |
|
|
Help Guest
|
CCP with multiple input |
Posted: Wed Oct 07, 2009 4:50 pm |
|
|
an oximeter, nothing fancy. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Help Guest
|
CCP1 with multi inputs. |
Posted: Fri Oct 09, 2009 3:41 pm |
|
|
Thank you for the reference and I followed all but it did not solve the problem, do you mind I send you in private msg my code and result to review. Basically my project is an oximeter that is why I need led & IR flashing and the CCP1 input to sample each one say 30 times, the CCP1 module does work but each led would be affected by the other sample and I do not know how to separate the readings. Regards. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 09, 2009 3:47 pm |
|
|
Quote: | I followed all but it did not solve the problem |
Explain.
Quote: |
do you mind I send you in private msg my code and result to review |
Why not post it in this thread ? |
|
|
Help Guest
|
CCP1 with multi-inputs |
Posted: Fri Oct 09, 2009 6:21 pm |
|
|
Sure:
Here is the code I have set, on PIC16F876A the C0 & C1 to control flashing of IR & LED. Input is taken from CCP1 (C2), when both leds on top of the light2freq converter which gives frequency as direct proportion to light intensity. Say that IR is closer than red, I get small value for IR then LED would have similar value and the flashing change such that each would last on for the duration of printing both values. I mean IR & Red and that darn confusing. I think I'm stuck. I do not know how to make capture get each at a time neatly.
Code: |
#int_ccp1
void ccp1_isr(void)
{
int16 current_ccp;
static int16 old_ccp = 0;
current_ccp = CCP_1;
isr_ccp_delta = current_ccp - old_ccp;
// Save the current ccp value for the next pass.
old_ccp = current_ccp;
}
void main(){
int16 current_ccp_delta;
int8 flag;
//TSl230R Setup
output_high(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
//Set initial state for LED & IR
output_high(PIN_C0);
output_low(PIN_C1);
set_uart_speed(19200);
//Capture mode Setup
set_timer1(0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_RE);
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
delay_ms(1000);
enable_interrupts(GLOBAL);
flag=0;
while(1) {
if(Sflag==0){
disable_interrupts(GLOBAL);
current_ccp_delta = isr_ccp_delta;
output_toggle(PIN_C1);
enable_interrupts(GLOBAL);
LEDfreq = (float) current_ccp_delta;
delay_ms(500);
printf("\n\r LED = %u ", LEDfreq);
Sflag=1;
} else {
disable_interrupts(GLOBAL);
current_ccp_delta = isr_ccp_delta;
output_toggle(PIN_C0);
enable_interrupts(GLOBAL);
IRfreq = (float) current_ccp_delta;
delay_ms(500);
printf("\n\r IR = %u", IRfreq);
Sflag=0;
}
delay_ms(1000);
} //end while(1)
} |
|
|
|
Help Guest
|
CCP1 multi input. |
Posted: Sat Oct 10, 2009 3:56 pm |
|
|
PCM programmer, Any idea or feedback? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 10, 2009 6:01 pm |
|
|
Can you post a timing diagram of your input signal to the CCP1 pin ?
Capture it on an oscilloscope, and post it on a free image hosting website.
Then post the link here, so we can look at the signals. |
|
|
Help Guest
|
CCP1 with multi-input. |
Posted: Sun Oct 11, 2009 6:37 pm |
|
|
I do not think I can do this without camera. But here is something very similar:
LED: __--- (source signal)
IR : ---__ (source signal)
CCP1: _--__--__--_----__----__---- (the first three (as ex.) led generated frequency by light sensor, the last three for IR, so expected values for example 10hz & 5hz accordingly, and with say for ex 40 readings for led or ir you get something like a wave.
Hope this make it clear. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 11, 2009 6:48 pm |
|
|
What is the duration in ms of each signal ? How long does the 5 Hz
signal last, and how long does the 10 Hz signal last ? |
|
|
Help Guest
|
CCP on multiple input. |
Posted: Sun Oct 11, 2009 8:30 pm |
|
|
Presuming 4mhz crystal, i would say 32ms each led would stay on at a time maximum, because I need to collect a series of samples of about 30 to 40 samples. So 32 ms sampling timer or maybe timer1 overflow would take 32ms as an estimate. |
|
|
Help Guest
|
CCP on multi input |
Posted: Sun Oct 11, 2009 8:45 pm |
|
|
I forgot to mention, that there should be an equal time for both leds to stay on/off say 1 second each. I would thike this to be adjustable for my application. |
|
|
|