|
|
View previous topic :: View next topic |
Author |
Message |
mahdi70
Joined: 05 Jan 2016 Posts: 44
|
6 input capture configuration |
Posted: Tue Feb 14, 2017 4:22 am |
|
|
hi buddies...i have 6 pwm channel with 1 khz freq and 6 input capture(icx)...i want to capture 6 channel wave with timer3 but Interferometry between output...how can i capture waves One by one with one timer(timer3)?
this my simple code
Code: | #INT_IC1
void ic1_isr(void)
{
if (input(pin_d8)) {
set_timer3(0);
}
if (!input(pin_d8) {
ic1=get_timer3();
}
}
#INT_IC2
void ic2_isr(void)
{
if (input(pin_d9)) {
set_timer4(0);
}
if (!input(pin_d9)) {
ic2=get_timer4();
}
} |
and ......
Code: | void main()
{
setup_timer3(TMR_INTERNAL | TMR_DIV_BY_1,55000);
setup_capture(1, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
setup_capture(2, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
setup_capture(3, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
setup_capture(4, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
setup_capture(5, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
setup_capture(6, CAPTURE_EE | INTERRUPT_FOURTH_CAPTURe | CAPTURE_TIMER3);
enable_interrupts(INT_IC1);
enable_interrupts(INT_IC2);
enable_interrupts(INT_IC3);
enable_interrupts(INT_IC4);
enable_interrupts(INT_IC5);
enable_interrupts(INT_IC6);
enable_interrupts(INTR_GLOBAL);
|
tnx alot |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Tue Feb 14, 2017 8:07 am |
|
|
It'd help if you told us which PIC you're using !
I can't tell if that code is correct let alone do what you want.
Obvious place to start would be trying 1 PWM input, then 2,then more...
You will need a stable KNOWN set of PWM sources ranging from 0 to 100%.
Another PIC could be used for this,giving 0,10,25,50,75,100 % PWM signals.
Without a KNOWN source any code you cut cannot be easily or properly tested !
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19494
|
|
Posted: Tue Feb 14, 2017 8:28 am |
|
|
Generally on IC type modules, you don't read the timer. You read the capture register. The whole point of these modules is that they record the timer value when triggered, then interrupt. The compiler provides 'get_capture' functions for this.
Then your code is mixing capture modes. You are selecting the 'every edge' mode, but then trying to use the 'every fourth event' option. Look at the data sheet. Look at the capture mode settings. Note:
001 = Capture mode, every edge (rising and falling); ICI<1:0> does not control interrupt generation
for this mode
Every edge mode _prevents_ the /4 option from working.....
You seem to be trying to time just the 'low time' of the waveform.
Don't set the timer in the capture (this is what is causing them the interfere). The timer should be set to count to 65536 (not limited to 55000), so it just 'free runs'. Then record the time when the signal is low (get_capture) as the 'start', and the time when you see it high as the 'stop'. The low period is then just stop-start. Do this for all the channels using the same timer.
If you don't want the low time, but the period, then switch to using just the rising or falling edge. |
|
|
mahdi70
Joined: 05 Jan 2016 Posts: 44
|
|
Posted: Tue Feb 14, 2017 9:17 am |
|
|
temtronic wrote: | It'd help if you told us which PIC you're using !
I can't tell if that code is correct let alone do what you want.
Obvious place to start would be trying 1 PWM input, then 2,then more...
You will need a stable KNOWN set of PWM sources ranging from 0 to 100%.
Another PIC could be used for this,giving 0,10,25,50,75,100 % PWM signals.
Without a KNOWN source any code you cut cannot be easily or properly tested !
Jay |
dspic33fj256mc710
i test 1 pwm and one input capture and it work...my problem start when i want use 2 capture channel with one timer...but i test 4 capture channel with 4 timer and its work |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19494
|
|
Posted: Tue Feb 14, 2017 9:41 am |
|
|
That is because you are setting the timer in the interrupt. Don't. Just record the values. Let the timer keep 'free running'. |
|
|
mahdi70
Joined: 05 Jan 2016 Posts: 44
|
|
Posted: Tue Feb 14, 2017 12:17 pm |
|
|
Ttelmah wrote: | Generally on IC type modules, you don't read the timer. You read the capture register. The whole point of these modules is that they record the timer value when triggered, then interrupt. The compiler provides 'get_capture' functions for this.
Then your code is mixing capture modes. You are selecting the 'every edge' mode, but then trying to use the 'every fourth event' option. Look at the data sheet. Look at the capture mode settings. Note:
001 = Capture mode, every edge (rising and falling); ICI<1:0> does not control interrupt generation
for this mode
Every edge mode _prevents_ the /4 option from working.....
You seem to be trying to time just the 'low time' of the waveform.
Don't set the timer in the capture (this is what is causing them the interfere). The timer should be set to count to 65536 (not limited to 55000), so it just 'free runs'. Then record the time when the signal is low (get_capture) as the 'start', and the time when you see it high as the 'stop'. The low period is then just stop-start. Do this for all the channels using the same timer.
If you don't want the low time, but the period, then switch to using just the rising or falling edge. |
hi...thanks alot sir....i understand some of your point of view ...can you offering simple code till i underestand?
tnx alot |
|
|
|
|
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
|