|
|
View previous topic :: View next topic |
Author |
Message |
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
dsPIC30F4012 Timers Problem |
Posted: Fri Apr 20, 2012 9:32 am |
|
|
hello guys i am using dsPIC30F4012, i have set timer1 to generate 10ms pulse wide for Led1 & 500ms for Led2,
the problem is that the controller is running tooooo slow, instead of generating 10ms pulse it is generating 1sec pulse
& when i vary the timer1 value the Blinking LED (500ms) in while loop also changes its it
Code: |
#include <30F4012.h>
#FUSES NOWDT, NOPROTECT, NODEBUG, NOBROWNOUT, HS, NOPUT
#use delay(clock=20MHz , crystal)
#define LED_1 PIN_E0
#define LED_2 PIN_D1
#INT_TIMER1
void Timer1_ISR(void)
{
output_toggle(LED_1);
set_timer1(64755);
}
void main()
{
set_tris_d (0b00000000);
set_tris_e (0b00000000);
output_low(LED_1);
output_low(LED_2);
set_timer1(64755);
setup_timer1(TMR_DIV_BY_64 |TMR_INTERNAL);
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
output_toggle(LED_2);
delay_ms(500);
}
}
|
|
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Fri Apr 20, 2012 3:12 pm |
|
|
I know on the PIC24, you have to specify which type of oscillator (primary, low power, etc) in addition to HS, XT, EC, etc. Try adding the PR fuse for that chip (if it has one). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Apr 20, 2012 3:26 pm |
|
|
First, study the timers on the 30F chips.
They are different from those on the PIC16/PIC18 chips. On these older chips, the timer counts 'up' to 65535, and then resets to 0. On the 30F, Timer1, has a comparator register, and counts up to this value, then resets itself. This is like the behaviour of Timer2 on the older chips. Just set the comparator register to 781, and the timer will interrupt every 10mSec (ish - half a count wrong).
Syntax for this, is just:
setup_timer1(TMR_DIV_BY_64 |TMR_INTERNAL,781);
Then, 'of course' the delay in the main code will be affected. If you are calling an interrupt routine every 10mSec, this will be 50 times in 0.5 seconds, and for each call, the processor has to go off and do the other job in the interrupt, and code in the main loop will slow down.
Realistically, if you have a timer ticking, then use it to give the second delay as well, _or_ use a hardware PWM/comparator, to generate the change in the high speed change in the output pin.
Best Wishes |
|
|
|
|
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
|