View previous topic :: View next topic |
Author |
Message |
mahdi70
Joined: 05 Jan 2016 Posts: 44
|
timer2 external clock input |
Posted: Sun Feb 07, 2016 6:29 am |
|
|
Hi ..
which pin of dspic33fj128gp804 use to timer2 external clock input?
tnx |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Feb 07, 2016 6:51 am |
|
|
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: 1345
|
|
Posted: Sun Feb 07, 2016 8:31 am |
|
|
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
|
|
Posted: Fri Feb 12, 2016 5:52 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Feb 12, 2016 6:26 am |
|
|
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
|
|
Posted: Fri Feb 12, 2016 6:32 am |
|
|
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: 1345
|
|
Posted: Fri Feb 12, 2016 9:22 am |
|
|
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
|
|
Posted: Fri Feb 12, 2016 9:58 am |
|
|
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
|
|
Posted: Sat Feb 13, 2016 5:41 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Feb 13, 2016 6:32 am |
|
|
please post your complete code... |
|
|
mahdi70
Joined: 05 Jan 2016 Posts: 44
|
|
Posted: Sat Feb 13, 2016 7:23 am |
|
|
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
|
|
Posted: Sun Feb 14, 2016 4:46 am |
|
|
this is my code |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19497
|
|
Posted: Sun Feb 14, 2016 5:12 am |
|
|
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
|
|
Posted: Sun Feb 14, 2016 6:27 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Feb 14, 2016 7:04 am |
|
|
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 |
|
|
|