View previous topic :: View next topic |
Author |
Message |
richi-d
Joined: 28 Aug 2007 Posts: 106
|
PWM Measurement with Capture PIC24 |
Posted: Thu Apr 09, 2009 4:45 am |
|
|
Hi All,
I´m trying to measure Servo pulses, but I donßt get an interrupt with my code:
Code: |
// V01 10.03.2009
#include <24FJ128GA106.h>
#FUSES FRC_PLL,NOPROTECT,NOIESO,NOJTAG,ICSP1,DEBUG
#use delay (clock=32000000)
#pin_select OC2=PIN_D11
#pin_select OC3=PIN_D10
#pin_select OC4=PIN_D9
#pin_select OC8=PIN_D8
#pin_select IC1=PIN_G7
#USE STANDARD_IO(B)
#USE STANDARD_IO(C)
#USE STANDARD_IO(D)
#USE STANDARD_IO(E)
#USE STANDARD_IO(F)
#USE STANDARD_IO(G)
#define _NOP #asm NOP #endasm;
#define TESTPIN PIN_F5
#define PWM_IN PIN_G7
long PWM_IN_STARTWERT;
long PWM_IN_STOPWERT;
#int_IC1
void IC1_isr(void)
{
if (input(PWM_IN))
{
PWM_IN_STARTWERT = get_capture(1,0);
setup_capture(1, CAPTURE_FE |CAPTURE_TIMER2);
}
if (!input(PWM_IN))
{
PWM_IN_STOPWERT = get_capture(1,0);
setup_capture(1, CAPTURE_RE |CAPTURE_TIMER2);
}
}
void main()
{
ENABLE_INTERRUPTS(INTR_GLOBAL);
SETUP_TIMER2(TMR_INTERNAL | TMR_DIV_BY_8); // 65535µs Überlauf, 1µs 1 Increment
SETUP_CAPTURE(1, CAPTURE_RE | INTERRUPT_EVERY_CAPTURE | CAPTURE_TIMER2);
ENABLE_INTERRUPTS(INT_IC1);
for(;;)
{
delay_ms(250);
}// for(;;)
}//Main() |
Is there a better method to do that? |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Thu Apr 09, 2009 6:02 am |
|
|
I now tried this Version:
Code: | void main()
{
ENABLE_INTERRUPTS(INTR_GLOBAL);
*0x142 = 0x0C01; //IC1CON2
*0x140 = 0x0403; //IC1CON1
SETUP_TIMER2(TMR_INTERNAL | TMR_DIV_BY_8); // 65535µs Überlauf, 1µs 1 Increment
ENABLE_INTERRUPTS(INT_IC1);
for(;;)
{
delay_ms(250);
}// for(;;)
}//Main() |
The program jumps now into the interrupt, but doesn´t have any value in the IC1BUFFER. Because after *0x140 = 0x0403; //IC1CON1 i always have 0x1B in the IC1CON1... Why do I not find my value 0x403 in the 0x140 register? |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Thu Apr 09, 2009 7:58 am |
|
|
All Adresses are wrong in the Compiler CCS!!
For Example:
Code: |
SETUP_COMPARE(1, COMPARE_SINGLE_PULSE | COMPARE_TIMER3);
|
This writes to the Adress 0x184 (IC9BUF)
I´m sooooo angry!!! The whole day for nothing! How can I write a 16bit value directly to the adress?
With: *0x142 = 0x0C01; it seems that I only can write 8bit.... |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Apr 09, 2009 12:03 pm |
|
|
Quote: | All Adresses are wrong in the Compiler CCS!! | Some of.
Quote: | How can I write a 16bit value directly to the adress?
With: *0x142 = 0x0C01; it seems that I only can write 8bit.... |
By using standard C syntax!
Code: | *(int16*)0x142 = 0x0C01; |
A better readable CCS specific version, that's used through all examples is this:
Code: | #word IC1CON2 = 0x142
..
IC1CON2 = 0x0C01; |
You can also utilize the Device Editor Tool to generate an include file with all device specific SFR addresses. Or correct some wrong SFR addresses. |
|
|
|