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

timer2 external clock input
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

timer2 external clock input
PostPosted: Sun Feb 07, 2016 6:29 am     Reply with quote

Hi ..

which pin of dspic33fj128gp804 use to timer2 external clock input?

tnx
temtronic



Joined: 01 Jul 2010
Posts: 9135
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 07, 2016 6:51 am     Reply with quote

That information is listed in the datasheet. I don't use that PIC so I can't say if it has 'mappable' pins or not but the section covering timers will.
Be sure to read the 'pinout' section as well and observe any notes about disabling other peripherals on the pins.
Too many PICs...too little time.



Jay
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Sun Feb 07, 2016 8:31 am     Reply with quote

Look in section 11.6 of your chip's datasheet for info on remappable pins. In the CCS manual, look at both #pin_select and setup_timer2 to see how to setup timer 2 to use an external clock.
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 5:52 am     Reply with quote

tnx for reply


this is my code :

Code:
#include <33FJ128GP804.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled

#device ICSP=1
#use delay(crystal=10MHz)


#pin_select t2ck=PIN_B15
#pin_select OC1=PIN_B3



void main()
{



   setup_timer2(TMR_EXTERNAL | TMR_DIV_BY_1, 1500);


   setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);
   set_pwm_duty(1, 0);
   while(TRUE)
   {
   set_pwm_duty(1, 500);   
   
   
   

   }}


but the level of pin b3 is high and pwm not work
temtronic



Joined: 01 Jul 2010
Posts: 9135
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 6:26 am     Reply with quote

comments.
1) Have you coded/compiled and got running a 1Hz LED program ?Be sure to use B3 as the test pin.

2) You only list 3 fuses,confirm that the others will not affect your program. Also be sure to program in 'release' mode and NOT 'debug' if using MPLAB.

3) You normally have to disable all other periphrals that can attach to I/O pins

As I sadi before I don't use that pic but reading the datasheet is paramount to getting PICs to run.
Jay
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 6:32 am     Reply with quote

temtronic wrote:
comments.
1) Have you coded/compiled and got running a 1Hz LED program ?Be sure to use B3 as the test pin.

2) You only list 3 fuses,confirm that the others will not affect your program. Also be sure to program in 'release' mode and NOT 'debug' if using MPLAB.

3) You normally have to disable all other periphrals that can attach to I/O pins

As I sadi before I don't use that pic but reading the datasheet is paramount to getting PICs to run.
Jay


when i use internal clock for timer2 , the compare/pwm is work....for test i use interrupt timer2 and toggle pin...

i am beginner in c and its hard to me for reading datasheet and understand it.
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 9:22 am     Reply with quote

Even if it is hard, it is something you'll need to work on. Getting your hands dirty is the best way to learn this stuff

What type of external clock are you feeding to timer 2 (part number?)? Have you verified that it is running correctly with an oscilloscope?
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 9:58 am     Reply with quote

jeremiah wrote:
Even if it is hard, it is something you'll need to work on. Getting your hands dirty is the best way to learn this stuff

What type of external clock are you feeding to timer 2 (part number?)? Have you verified that it is running correctly with an oscilloscope?


I try to understand datasheet

tnx...50 * 70 osc 50 mhz ...yes i see the wave on oscope and its work properly...Need to set tris pin to input?
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Sat Feb 13, 2016 5:41 am     Reply with quote

i test in low freq, for example 1khz for external clock, the timer work properly and when Freq rises the error rises and the timer not work.
temtronic



Joined: 01 Jul 2010
Posts: 9135
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 13, 2016 6:32 am     Reply with quote

please post your complete code...
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Sat Feb 13, 2016 7:23 am     Reply with quote

Code:
#include <33FJ128GP804.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled

#device ICSP=1
#use delay(crystal=10MHz)

//above code generated by wizard

#pin_select t2ck=PIN_b15  //external clock input pin


#INT_TIMER2
void  timer2_isr(void)
{
   output_toggle(pin_b4);//every interrupt, pin b4 toggled.....100ms
}

void main()
{

setup_timer2(TMR_EXTERNAL | TMR_DIV_BY_1, 19600);// 50MHZ external clock connect to pin b15
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INTR_GLOBAL);
   while(TRUE)
   {

   }}
   
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Sun Feb 14, 2016 4:46 am     Reply with quote

this is my code
Ttelmah



Joined: 11 Mar 2010
Posts: 19262

View user's profile Send private message

PostPosted: Sun Feb 14, 2016 5:12 am     Reply with quote

A simple line relating to this timer applies:

The external clock input (TxCK) is always
synchronized to the internal device clock and the
clock synchronization is performed after the
prescaler.

Note 'always synchronised'.
Now using a 10MHz internal clock, and a 50Mhz input, you are basically not going to see the 50MHz rate, because of this synchronisation. Depending on the exact relationship of the clocks, you may see an occasional count, or nothing.

Timer1, has the ability to run without this synchronisation. Timer2 does not.
mahdi70



Joined: 05 Jan 2016
Posts: 44

View user's profile Send private message

PostPosted: Sun Feb 14, 2016 6:27 am     Reply with quote

Ttelmah wrote:
you may see an occasional count, or nothing.



yes ..i saw it on oscope

now, There is no way that I use the timer 2 with 50MHZ clock?
temtronic



Joined: 01 Jul 2010
Posts: 9135
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 14, 2016 7:04 am     Reply with quote

As Mr. T pointed out, it cannot be done.
That's WHY it is so important to read the datasheet, especially for a 'new to you' PIC. There are differences even within 'families' of PICs so what works with PICxxx may NOT work with PICxxy.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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