Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i got the code to program a timer using a internal clock of PIC32 microcontroller using timer 1. I'm using a 16-bit synchronous external clock counter to do a counting for incoming data signal from AD9883A video analog to digital convertor. I will like to know which part of it i need to change and how do i include the input of the signal that i need to count.. Here is the code...

#include <plib.h>
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, #pragma config FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_8

// Let compile time pre-processor calculate the PR1 (period)
#define SYS_FREQ 			(80000000L)
#define PB_DIV         		8
#define PRESCALE       		256
#define TOGGLES_PER_SEC		1
#define T1_TICK	    (SYS_FREQ/PB_DIV/PRESCALE/TOGGLES_PER_SEC)

int main(void)
{
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
	
    //configure Timer 1 using internal clock, 1:256 prescale
    OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_256, T1_TICK);
    
    // set up the timer interrupt with a priority of 2
    ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);
    
    // enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    // configure PORTD.RD0 = output
    mPORTDSetPinsDigitalOut(BIT_0);
    while(1);
}
void __ISR(_TIMER_1_VECTOR, ipl2) Timer1Handler(void)
{
    // clear the interrupt flag
    mT1ClearIntFlag();
    // .. things to do
    // .. in this case, toggle the LED
    mPORTDToggleBits(BIT_0);
}</plib.h>
Posted
Updated 4-May-10 19:32pm
v2

1 solution

The answer seems to be in your own code ....

//configure Timer 1 using internal clock, 1:256 prescale    
OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_256, T1_TICK);


To change from internal to external clock you need to change the parameters passed to OpenTimer1. I cannot tell you the exact value, you need to look it up in the help for the compiler that you are using, but at a guess changing T1_SOURCE_INT to T1_SOURCE_EXT seems favourite. :)

Hope that helps :thumbsup:
 
Share this answer
 
Comments
limwy 5-May-10 4:21am    
thanks..then how do i program or add what code if i wanna use the external clock to do my programming. I wanna count the number of HSYNC signal coming in, how do i do the link up to do the counting?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900