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

24FJ256GB206 + 1ms timer?

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



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

24FJ256GB206 + 1ms timer?
PostPosted: Tue Jul 15, 2014 11:32 am     Reply with quote

Dear CCS forum Memeber,
I need to have timer interrupt each 1ms on 24FJ256GB206.
I use CCS 24F USB PCB and CCS v5.026.
I use CCSUSB.h so i have set:
Code:
#use delay(crystal=20M, clock=32M, USB_FULL)


My code:
Code:
#include "CCSUSB.h"

#int_TIMER1
void TIMER1_isr()
{
   output_toggle(RED_LED);
}

void main()
{
   LED_OFF(RED_LED);
   
   setup_timer1(TMR_INTERNAL|TMR_DIV_BY_1);
   set_timer1(16000);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
     
   while(TRUE)
   {
   }

}

When i connect to oscilloscope i get 8.20ms Sad
I used timer with PIC18F without any problem. The strange think is when i change timer preset value in code, on oscilloscope nothing change.
Could You advise me when i did mistake?
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Jul 15, 2014 12:01 pm     Reply with quote

Your interrupt fires every 4.1 ms, so your 8.2ms makes sense. You need to use the optional parameter in setup_timer1() to set the period of the register to 16000 instead. Doing set_timer1(16000) doesn't really do what you think it does.
Requan



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

PostPosted: Wed Jul 16, 2014 4:02 am     Reply with quote

jeremiah wrote:
Your interrupt fires every 4.1 ms, so your 8.2ms makes sense. You need to use the optional parameter in setup_timer1() to set the period of the register to 16000 instead. Doing set_timer1(16000) doesn't really do what you think it does.


Thanks for Your quick help. You was right. i through in wrong way.
Now i have 1ms Very Happy
Requan



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

PostPosted: Wed Jul 16, 2014 6:39 am     Reply with quote

Arrow jeremiah:
Could You help me in one more issue:
i set up PWM:

Code:

#pin_select OC1  = PIN_B9
void main()
{
 setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 1000); 
 setup_compare(1,COMPARE_PWM_EDGE|COMPARE_TIMER2|COMPARE_CONTINUE_IDLE);
 set_pwm_duty (1,25000); 

   while(TRUE)
   {
   }


PWM duty is ok, but when i changed period value i always get 245Hz.
I read forum and tried different settings of setup_compare but nothing help
Requan



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

PostPosted: Wed Jul 16, 2014 11:48 am     Reply with quote

Requan wrote:
Arrow jeremiah:
Could You help me in one more issue:
i set up PWM:

Code:

#pin_select OC1  = PIN_B9
void main()
{
 setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 1000); 
 setup_compare(1,COMPARE_PWM_EDGE|COMPARE_TIMER2|COMPARE_CONTINUE_IDLE);
 set_pwm_duty (1,25000); 

   while(TRUE)
   {
   }


PWM duty is ok, but when i changed period value i always get 245Hz.
I read forum and tried different settings of setup_compare but nothing help


i added
Code:
 
enable_interrupts(INT_TIMER1);

and now i can adjust frequency - strange because i read a lot of threads and nobody added it.
Now i cant't adjust duty - independently from set_pwm_duty i have 42% on 58%
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Wed Jul 16, 2014 11:59 am     Reply with quote

I don't have a way to check at the moment, but most of those chips have an additional PWM parameter to set...something with both SYNC and TMR2 in the name. Check the .h file for your chip. I've had a few chips where I had to specify that parameter in addition to the timer 2 parameter.

The fact that enabling timer1 interrupts had any effect makes me worried. In your latest code you don't have a timer1 isr handler and that can be dangerous with the interrupt enabled. Either way it shouldn't affect the PWM since you link it to timer 2.
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