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

32 bit Counter problem [Solved]

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



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

32 bit Counter problem [Solved]
PostPosted: Sat Aug 16, 2008 8:42 am     Reply with quote

Hello folks,
i have a strange prob,
i like to count a 10Mhz frequency
i use 30F4013 on counter 2 in 32 bit mode

if i print the result, i see only the lower16 bits,
10.000.000 = 0x989680
the result i see = 0x9680 or 35528

any sugestions?

Tnx, carl

Code:

#include <30f4013.h>
#device adc=12
#FUSES NOWDT // Watch Dog Timer
#FUSES EC
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#fuses HS3_PLL16 // div by 3 and  multiply the ext. clock of 40mhz by 8x
#FUSES PR_PLL // pll mode
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#define XTAL_FREQUENCY 128000000
#use delay(clock=XTAL_FREQUENCY)
#use rs232(stream = RS232, baud=115200,parity=N,xmit=PIN_F5,rcv=PIN_F4,bits=8)
int32 freq;
#include <math.h>

/////////////////////////////////////////////////////////////////////////////////////
/****************** 1 pps van GPS *******************/
#int_ext0
void EXT_ISR()
{
         freq=0;
         freq = get_timer23();
         set_timer23(0);   
}
/////////////////////////////////////////////////////////////////////////////////////




Void main()
{

   set_tris_b(0b11000001);
   EXT_INT_EDGE(L_TO_H);
   setup_timer2(TMR_32_bit);
   enable_interrupts(int_timer3);
   set_timer23(0);
   setup_timer2(TMR_EXTERNAL|TMR_DIV_BY_1);
   enable_interrupts(INT_EXT0);
   enable_interrupts(intr_GLOBAL);
   printf("hello\n\r");
   While(1)
   {
       delay_ms(400);
      printf("FRQ %lu \n\r",freq);
   }
}
[/code]

Last edited by on7nh on Sat Aug 16, 2008 10:54 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Aug 16, 2008 10:42 am     Reply with quote

You call setup_timer2 two times where the second call is overwriting the settings of the first call. Combine the two lines into one:
Code:
setup_timer2(TMR_EXTERNAL|TMR_DIV_BY_1|TMR_32_bit);
on7nh



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Sat Aug 16, 2008 10:53 am     Reply with quote

Manymanymanymanymanymanymany..... THANKS !
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