Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Trouble with 24ep512gu814 counter in main

Status
Not open for further replies.

anboli

Full Member level 2
Full Member level 2
Joined
Mar 9, 2012
Messages
144
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Visit site
Activity points
2,513
hello all,

Am working with 24ep512gu814, now am having trouble in increasing a variable count inside the program. All other ports & registers are being manipulated but not any variables manually declared/initialized.
the code is posted below
Code:
	#include <24ep512gu814.h>
	#include "REGISTERS.h"
	#include "PORT_BIT.h"
	
	#use delay(clock=25M)[CODE]

#pragma config ICS = PGD2 // ICD Communication Channel Select bits (Communicate on PGEC3 and PGED3)
#pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled)

// FPOR
#pragma config ALTI2C1 = OFF // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
#pragma config ALTI2C2 = OFF // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
#pragma config WDTWIN = WIN25 // Watchdog Window Select bits (WDT Window is 25% of WDT period)

// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)

// FOSC
#pragma config POSCMD = HS // Primary Oscillator Mode Select bits (HS Crystal Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = ON // Peripheral pin select configuration (Allow only one reconfiguration)
#pragma config FCKSM = CSECME // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are enabled)

// FOSCSEL
#pragma config FNOSC = PRIPLL // Oscillator Source Selection (Primary Oscillator with PLL module (XT + PLL, HS + PLL, EC + PLL))
#pragma config IESO = ON // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)

// FGS
#pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
#pragma config GCP = OFF // General Segment Code-Protect bit (General Segment Code protect is Disabled)

int32 Period_value = 24999999; // Instruction clock
int16 count=0;

#INT_TIMER3
void Timer2_3Interrupt()
{
T3IF = 0;
Rj0 = ~Rj0;

}

void Init_timer3_32()
{
T2CON = 0;
T3CON = 0;
TMR3 = 0;
TMR2 = 0;
T2T32 = 1;
T2CS = 0;
T2GATE = 0;
T2CKPS_4= 0;
T2CKPS_5= 0;
PR3 = 12; //12; Period_value>>16
PR2 = 34464; //13580; Period_value == 240ms
T3IP_0 = 1;
T3IP_1 = 0;
T3IP_2 = 0;
T3IF = 0;
T3IE = 1;
GIE = 1;

T2ON = 1;
}

void cpu_initiallisation()
{
PMD1 = 0X07FF; // TIMER3 IS ENABLED T3MD = 0;
PMD2 = 0XFFFF;
PMD3 = 0X0FFF;
PMD4 = 0XFFFF;
PMD5 = 0XFFFF;
PMD6 = 0XFFFF;
PMD7 = 0XFFFF;

ANSELA = 0X0000;
ANSELB = 0X0000;
ANSELC = 0X0000;
ANSELD = 0X0000;
ANSELE = 0X0000;
ANSELF = 0X0000;
ANSELG = 0X0000;
ANSELH = 0X0000;
ANSELJ = 0X0000;
ANSELK = 0X0000;

TRISA = 0X0000;
TRISB = 0X0000;
TRISC = 0X0000;
TRISD = 0X0000;
TRISE = 0X0000;
TRISF = 0X0000;
TRISG = 0X0000;
TRISH = 0X0000;
TRISJ = 0X0000;
TRISK = 0X0000;

INTCON1 = 0x8000;
INTCON2 = 0X8000;
INTCON3 = 0X0000;
INTCON4 = 0X0000;

INTTREG = 0X0000;

}


void main()
{

cpu_initiallisation();
// Init_timer3_32();
count = 0;
while(1)
{ while(count!=10)
{
count=count+1; //this is wat is not counting
rj1=~rj1; //some port blink to indicate loop working
delay_ms(1000);
}
count=0;
}
}
[/code]
please help thanks in advance
 

Maybe delay is not proper, it might be too fast. Increase delay 10 times and see.

the delay has nothing to do with the program. moreover the delay is working fine am getting a blink every one sec.

Code:
void main()
	{
	
		cpu_initiallisation();
	//	Init_timer3_32();
		count = 0;
		while(1)
		{	while(count!=10)
			{
				count=count+1;		//this is what is not counting
				rj1=~rj1;			//some port blink to indicate loop working	
                                portd=count;              //the portd value is never increased come what may!!
				delay_ms(1000);
			}
			count=0;
                        portd=0;
		}
	}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top