i dont get it, why should there be more clockspeeds, and so damm hard to find out of.
Still it run very fast in time, but delays are way to slow.
have set "FOSC_LP"
Still it run very fast in time, but delays are way to slow.
have set "FOSC_LP"
i dont get it, why should there be more clockspeeds, and so damm hard to find out of.
Still it run very fast in time, but delays are way to slow.
have set "FOSC_LP"
//timer1 settings
TMR1H=0x80;
TMR1L=0;
T1CON=0b10001111;
TMR1IE=1;// PIE1 register
PEIE=1; //INTCON register
PIR1=0; // Clear all bits PERIPHERAL INTERRUPT REQUEST REGISTER 1
TMR1GE=1;
GIE=1;
TMR1ON=1;
INTCON=0b11100000;
What does " still it do not count as it should" mean???
Where is your ISR?
How should it count? Is it working at all? Details please.
static void interrupt
isr(void) // Here is interrupt function - the name is unimportant.
{
if(TMR1IF)
{// Was this a timer overflow?
TMR1IF=0;//Clear interrupt flag, ready for next
TMR1H=0x80;
//If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
regn_tick=1;
sec++;
sec_tick=1;
if (sec==60)
{
minut_tick=1;
sec=0;
}
}
}
You still have not answered the question or at least I do not understand what you are saying.'Rich (BB code):static void interrupt isr(void) // Here is interrupt function - the name is unimportant. { if(TMR1IF) {// Was this a timer overflow? TMR1IF=0;//Clear interrupt flag, ready for next TMR1H=0x80; //If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second regn_tick=1; sec++; sec_tick=1; if (sec==60) { minut_tick=1; sec=0; } } }
It should count the seconds, works fine on 16f690
have now changed it so it count every second simpel counter on lcd, but keeps showing 0.
it seems like it do not start the circuit that generate around 32 khz.
Do you remember your basic debugging skills? Set a breakpoint inside the ISR on the first line. If it stops there and the timer's interrupt flag is set then it is being called.how should i check if the timer is starting ?
if the interrupt is called, then i will know, but it is not....
ok, just run it with breakpoints it will just loop in the endlees loop, cause it do not get any input from extern xtal.You can use a clock stimulus in the MPLAB simulator. Then set a breakpoint in the ISR. I tell you tomorrow. But you can also look at my sticky in this forum section
I don't know what this means. Does this mean it is working in simulation mode?ok, just run it with breakpoints it will just loop in the endlees loop, cause it do not get any input from extern xtal.
,
ok was to the info to set up in stimul.I don't know what this means. Does this mean it is working in simulation mode?
Shouldn't this external crystal correspont with the configuration bits?no input from external xtal.
#include <htc.h>
//#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
__CONFIG (FCMEN_ON & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTOSC);
__CONFIG (LVP_ON & LPBOR_OFF & BOREN_ON & STVREN_ON & WRT_OFF);
#define LED RC0
#define _XTAL_FREQ 4000000
//global defs
volatile unsigned char week_day;
volatile bit timer_tick;
volatile bit blink;
const char * const day_of_week_names[] = {"Monday feels so bad",
"Tuesday feel better",
"Wednesday don't go ",
"Thursday goes slow ",
"Friday on my mind ",
"Saturday Night Live",
"Sunday be sporty "
};
static void interrupt
isr(void) // Here is interrupt function - the name is
// unimportant.
{
if(TMR1IF)
{// Was this a timer overflow?
TMR1IF=0;//Clear interrupt flag, ready for next
TMR1H=0x80;
//If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
timer_tick=1;
}//we are done here
}
void setup(void)
{
IRCF0=1;
IRCF1=0;
IRCF2=1;
IRCF3=1;//4MHz clock speed
//REGISTER 5-1: OSCCON: OSCILLATOR CONTROL REGISTER
// bit 6-3 IRCF<3:0>: Internal Oscillator Frequency Select bits
//1111 = 16MHz
//1110 = 8MHz
//1101 = 4MHz
//1100 = 2MHz
//1011 = 1MHz
//1010 = 500 kHz(1)
//1001 = 250 kHz(1)
//1000 = 125 kHz(1)
//0111 = 500 kHz (default upon Reset)
//0110 = 250 kHz
//0101 = 125 kHz
//0100 = 62.5 kHz
//001x = 31.25 kHz
//000x = 31kHz LF
TRISA0=0;
TRISC=0b01111000;//RC0-RC2 out,RC3-RC6 in,RC7 out
TRISB=0; //All port B output
GIE = 0; // Global interrupt disable just in case
ANSELA=0;
ANSELB=0;
ANSELC=0;//turn off all analog functions
//timer1 settings
TMR1H=0x80;
TMR1L=0;
//T1CON=0b00000110;//used during debug
T1CON=0b10001100;
// See datasheet REGISTER 19-1: T1CON: TIMER 1 CONTROL REGISTER
// TMR1CS<1:0> T1CKPS<1:0> T1OSCEN !T1SYNC — TMR1ON
//bit 7-6 TMR1CS<1:0>: Timer1 Clock Source Select bits
//11 =Timer1 clock source is Capacitive Sensing Oscillator (CAPOSC)
//10 =Timer1 clock source is pin or oscillator:
//If T1OSCEN = 0:
//External clock from T1CKI pin (on the rising edge)
//If T1OSCEN = 1:
//Crystal oscillator on SOSCI/SOSCO pins
//01 =Timer1 clock source is system clock (FOSC)
//00 =Timer1 clock source is instruction clock (FOSC/4)
//bit 5-4 T1CKPS<1:0>: Timer1 Input Clock Prescale Select bits
//11 = 1:8 Prescale value
//10 = 1:4 Prescale value
//01 = 1:2 Prescale value
//00 = 1:1 Prescale value
//bit 3 T1OSCEN: LP Oscillator Enable Control bit
//1 = Dedicated Timer1 oscillator circuit enabled
//0 = Dedicated Timer1 oscillator circuit disabled
//bit 2 T1SYNC: Timer1 Synchronization Control bit
//1 = Do not synchronize asynchronous clock input
//0 = Synchronize asynchronous clock input with system clock (FOSC)
//bit 1 Unimplemented: Read as ‘0’
//bit 0 TMR1ON: Timer1 On bit
//1 = Enables Timer1
//0 = Stops Timer1 and clears Timer1 gate flip-flop
TMR1GE=0;
//T1GCON: TIMER1 GATE CONTROL REGISTER
//bit 7 TMR1GE: Timer1 Gate Enable bit
//If TMR1ON = 0:
//This bit is ignored
//If TMR1ON = 1:
//1 = Timer1 counting is controlled by the Timer1 gate function
//0 = Timer1 counts regardless of Timer1 gate function
//Timer1 Interrupt prepare
TMR1IE=1;// PIE1 register
PEIE=1; //INTCON register
PIR1=0; // Clear all bits PERIPHERAL INTERRUPT REQUEST REGISTER 1
//todo now in order to generate interrupt GEI=1 and TMR1ON=1
//setup LCD
lcd_init();
lcd_goto(0); // select first line
//set the globals
week_day=4;
timer_tick=0;
blink=0;
//other misc settings
timer_tick=0;//clear the tick
}
void lcd_format_and_send(void)
{ blink=!blink;
LED=blink;
if (blink) lcd_puts("Next LED will be off");
else lcd_puts("Next LED will be on ");
lcd_goto(0x40); // Select second line
//lcd_puts("day of week ");
//lcd_putch(week_day+48);
lcd_puts(day_of_week_names[week_day]);
lcd_goto(0x00);
}
void main (void)
{ setup();
GIE=1;
TMR1ON=1;
while (1)
{
if (timer_tick)
{
week_day++;
if (week_day==7) week_day=0;
lcd_format_and_send();//send time to LCD
timer_tick=0;
//timer_tick=1;//just for debug
}// end if (timer_tick) Memo to my self put all this in sub function
}//end while endless loop
}//End main
Again. You are not providing enough information. We cannot see you project. You need to tell us what you can see.have now life in chip, changed the FOSC_INTOSC to FOSC_XT
But i cant figure out, why it run 4 times as fast as it should ???