dsPIC30F3014's TIMERS

Status
Not open for further replies.

alexsoad

New Member
Hi, i do have a problem managing the timers on dsPIC30F3014.
This microcontroller has 3 Timers: T1, T2 and T3.
For my project i use T2 and T3 to generate 2 PWM signals, that control 2 DC motors independently.
I do some Analog to Digital conversion, and i configured to be managed by "Internal Counter". I do not know what this means. Who is internal counter? Is it Timer 1?? or it is the microcontroller's clock.

I need to use one more timer, for creating an exact delay function, and i do need another Timer. So, i need to know if i can use Timer 1, or if there is another method to create a function that comports as a perfect controlled delay.

Thank you ,
Alex
 
Last edited:
The ADC unit has an internal counter based on the instruction clock that it uses for sample and conversion. It is not linked to the actual timer modules.
 
There are a number of ways to create a delay function, but using a timer it's relatively easy and quite accurate.

In the delay function create a very tight loop that is testing a your delay count. Then you can use the Timer1 interrupt to do the actual counting of the delay. You will have to do the calculations yourself based on the Timer1 frequency though. Pseudo code below.

C:
unsigned short gDelayCount = 0;

void delay(unsigned short delayTime)
{
    gDelayCount = delayTime;

    // Start our Timer1 counting
    StartTimer1();

    // Our actual delay loop
    while (gDelayCount != 0);

    // Stop Timer1 from counting
    StopTimer1();
}

void Timer1Interrupt(void)
{
    gDelayCount--;
}
 
To get a real base of time, you will have to input a multiplier on the delayCount based on the frequency of Timer1. Or just set the Timer1 frequency to be a multiple of a real time base.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…