View previous topic :: View next topic |
Author |
Message |
ELINAP
Joined: 05 Sep 2013 Posts: 14
|
16F721 and Timer1 problem |
Posted: Mon Jan 26, 2015 7:52 am |
|
|
Hi everybody,
I use an 16F721 for an application. I use the PWM output ( work good ) , watchdog timer ans i want to use the timer1 to generate a time base. The problem is the timer1's interrupt don't work. I'm not sure the timer1 run too.
main code:
Code: | setup_adc_ports(sAN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //131 ms overflow
setup_timer_2(T2_DIV_BY_16,249,1); //1,0 ms overflow, 1,0 ms interrupt
setup_ccp1(CCP_PWM);
set_pwm1_duty((int16)898);
T1GE = 0; mode gate disable
T1ON = 1; timer1 run |
But there is nothing happen on timer1.
If someone can help me?
Thanks by advance |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Mon Jan 26, 2015 8:24 am |
|
|
What do you expect to 'happen'?. The timer will just sit their counting. No flashing light, or trumpet!.
If you want it to 'do' something, then add a routine like:
Code: |
#INT_TIMER1
void T1_tick(void)
{
output_toggle(PIN_A1);
}
//and enable INT_TIMER1, and INT_GLOBAL in the main
|
This will then toggle the pin every time the timer resets to zero.
Get rid of your bit fiddles with the gate etc., not wanted/needed. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Mon Jan 26, 2015 9:40 am |
|
|
Just FYI, I just put together a test application based on this:
Code: |
#include <16F721.h>
#FUSES INTRC_IO,NOWDT,NOMCLR
#device ADC=10
#use delay(internal=16000000)
#INT_TIMER1
void T1_tick(void)
{
output_toggle(PIN_A1);
}
void main()
{
setup_adc_ports(sAN3);
setup_adc(ADC_CLOCK_DIV_16); //Internal is not recommended above 1MHz
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //131 ms overflow
setup_timer_2(T2_DIV_BY_16,249,1); //1,0 ms overflow, 1,0 ms interrupt
setup_ccp1(CCP_PWM);
set_pwm1_duty((int16)898);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(TRUE)
{
//TODO: User Code
}
}
|
and it merrily toggles the pin every 131mSec.
Note also the change to the ADC clock (read the data sheet...). Note 4 under the 'ADC CLOCK PERIOD' table. |
|
![](templates/subSilver/images/spacer.gif) |
ELINAP
Joined: 05 Sep 2013 Posts: 14
|
|
Posted: Tue Jan 27, 2015 7:49 am |
|
|
Problem solved. |
|
![](templates/subSilver/images/spacer.gif) |
|