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 support@ccsinfo.com

PWM Measurement with Capture PIC24

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



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PWM Measurement with Capture PIC24
PostPosted: Thu Apr 09, 2009 4:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 09, 2009 6:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 09, 2009 7:58 am     Reply with quote

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)

Twisted Evil 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

View user's profile Send private message

PostPosted: Thu Apr 09, 2009 12:03 pm     Reply with quote

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.
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