Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F4431 Configuration

Status
Not open for further replies.

2exposantThom

New Member
Hello,

I'm trying to simply configure a PIC18F4431 to generate an interruption when the Timer0 overflows.
When this interruption occurs, I decide to switch on or off a led.
The oscillator is a 20Mhz, and I configure the Timer0 in 16 bits mode.
So normally, the interruption has to come every (65535*4/20000000) according to the datasheet

My problem is that in my program, the interruption does not come every
(65535*4/20000000) but every 4 or 5 seconds.
And when I "scope" the osc1 and osc2 pins, I don't have a sinusoidal signal but a signal sticked to 5V.

Somebody could help me ?
Thanks

Here is my code :
The flags are defined in another C file


//===========================================================================================================================================
//; assembler/linker/chip options
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// nolist
#include <P18F4431.h>
#pragma config OSC = HS



//===========================================================================================================================================
// Constantes definition
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#include "application.h"
#include <stdio.h>
#include <P18F4431.h>

#define RA0 OUT
#define RA1 OUT
#define RA2 OUT
#define RA3 OUT
#define RA4 OUT
#define RA5 OUT
#define RA6 IN
#define RA7 IN

#define RB0 OUT
#define RB1 OUT
#define RB2 OUT
#define RB3 OUT
#define RB4 OUT
#define RB5 OUT
#define RB6 IN
#define RB7 IN

#define RC0 OUT
#define RC1 OUT
#define RC2 OUT
#define RC3 OUT
#define RC4 OUT
#define RC5 OUT
#define RC6 IN
#define RC7 IN

#define RE0 OUT
#define RE1 IN
#define RE2 IN
#define RE3 IN

#pragma interrupt Low_Irq
void Low_Irq(void)
{
unsigned int i;mybyte b;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Irq_Timer0_Match:
if (INTCONbits.TMR0IF){
INTCONbits.TMR0IF=0;
FLAG_2500US=1;}}


void main()
{
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
INTCONbits.TMR0IE=1;
OpenTimer0(T0_16BIT & T0_SOURCE_INT & T0_PS_1_1);


ANSEL0=0;
ANSEL1=0;

TRISA=RA7<<7 | RA6<<6 | RA5<<5 | RA4<<4 | RA3<<3 | RA2<<2 | RA1<<1 | RA0;
TRISB=RB7<<7 | RB6<<6 | RB5<<5 | RB4<<4 | RB3<<3 | RB2<<2 | RB1<<1 | RB0;
TRISC=RC7<<7 | RC6<<6 | RC5<<5 | RC4<<4 | RC3<<3 | RC2<<2 | RC1<<1 | RC0;
TRISE=RE3<<3 | RE2<<2 | RE1<<1 | RE0;





for(;;){

if (FLAG_2500US) {
FLAG_2500US=0;
Led_Cpu=!Led_Cpu;
continue; }

continue;}


}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top