Jump to content
Christian Faure

Novo, Pic 16f877, Interrupts

Recommended Posts

Hi,

 

Thanks for this excelent work with BoostC and Novo.

 

Now i'm trying to run examples of NOVO (NovoLedFlash),

but this example only work (for me) with interrupts disabled,

and moving the code of interrupt to main loop.

 

I'm using a pic 16f877 whith bootloader, WatchDog disabled, 20Mhz

+BoostC 6.8

 

Any idea? :)

 

My modified code:

#include <system.h>
#include <novocfg_pic16t3e5ts1.h>
#include <novo.h>

#pragma DATA _CONFIG, _PWRTE_ON & _BODEN_ON & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF
#pragma CLOCK_FREQ	18432000

#define hTask0 0
#define hTask1 1


void interrupt( void )
{
if( intcon.T0IF )
{
	// update system time every 1ms (actually is 204.8us x 5 = 1.024ms)
	static BYTE intDivider;
	if( ++intDivider == 5 )
	{
		intDivider = 0;
		SysTimerUpdate();
	}

	intcon.T0IF = 0; //clear TMR0 overflow flag
}
}

void InitTimer()
{
// configure Timer0	
option_reg.T0CS = 0; // use internal clock
option_reg.PSA = 0; // use prescaler form timer 0	


// so we get an interrupt around every 204.8us with 20MHz Clock
// set prescaller to divide by 4
option_reg.PS0 = 1;
option_reg.PS1 = 0;
option_reg.PS2 = 0;

// enable interrupts ---------> DISABLED
//intcon.T0IE = 1; //enable TMR0 overflow bit	
//intcon.GIE = 1;
}

void Task0()
{
while( 1 )
{
	porta.0 = 0;
	Sys_Sleep( 100 );
	porta.0 = 1;
	Sys_Sleep( 100 );
}
}

void Task1()
{
while( 1 )
{
	porta.1 = 0;
	// 500ms delay
	Sys_Sleep( 250 ); // can only sleep for a maximum of 255 with 8 bit timers
	Sys_Sleep( 250 );
	porta.1 = 1;
	// 500ms delay
	Sys_Sleep( 250 );
	Sys_Sleep( 250 );
}
}

void main()
{	
//ansel = 0;
trisa = 0x00;
//Configure A/D pins
adcon1 = 0x06;

//Initialize port A
porta = 0x00;

//InitTimer();

SysInit();
SysCreateTask( hTask0, 2, Task0 );
SysCreateTask( hTask1, 2, Task1 );

SysStartTask( hTask0 );
SysStartTask( hTask1 );

while( 1 )
{	//-------- CODE FROM INTERRUPT
	static BYTE intDivider;
	if( ++intDivider == 5 )
	{
		intDivider = 0;
		SysTimerUpdate();
	}
			//-----------
	Sys_Yield();
}
}

Share this post


Link to post
Share on other sites
Hi,

 

Thanks for this excelent work with BoostC and Novo.

 

Now i'm trying to run examples of NOVO (NovoLedFlash),

but this example only work (for me) with interrupts disabled,

and moving the code of interrupt to main loop.

 

I'm using a pic 16f877 whith bootloader, WatchDog disabled, 20Mhz

+BoostC 6.8

 

Any idea? :)

Sounds like you are getting no interrupts, but why I'm not sure. Best to look at in detail the code that sets up and enables the interrupts.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks Dave,

 

But no, when i disable Novo (comment),

interrupts are ok, (with or without a complete initialization code)

 

When i enable Novo (comment out)

then is unpredictable,

sometimes interrupts work few seconds, then hang

sometimes interrupts dont work

but never run more than once time a task.

 

When i disable interrupts and move the SysTimerUpdate() to the main loop, then always run ok,

so i think that isn't a circuit problem, nor a logic problem in the sample code... :)

 

Are someone using the pic16F877 with Novo and interrupts enabled?

 

I need to change to pic18 branch?

 

Another idea?

 

Thanks

Christian

Share this post


Link to post
Share on other sites

Christian Faure,

Just more info:

I've tried a dummy (empty) timer interrupt enabled,

without calling SysTimerUpdate() from interrupt (calling it from main loop),

and get same result: hang

 

Regards,

Christian

The following code (your code with a couple of changes) works under the SourceBoost IDE simulator with PIC16F877 selected as the target. I have not tried it with the actual hardware.

 

#include <system.h>
#include <novocfg_pic16t3e5ts1.h>
#include <novo.h>

#pragma DATA _CONFIG, _PWRTE_ON & _BODEN_ON & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF
#pragma CLOCK_FREQ	18432000

#define hTask0 0
#define hTask1 1


void interrupt( void )
{
if( intcon.T0IF )
{
	// update system time every 1ms (actually is 204.8us x 5 = 1.024ms)
	static BYTE intDivider;
	if( ++intDivider == 5 )
	{
		intDivider = 0;
		SysTimerUpdate();
	}

	intcon.T0IF = 0; //clear TMR0 overflow flag
}
}

void InitTimer()
{
// configure Timer0	
option_reg.T0CS = 0; // use internal clock
option_reg.PSA = 0; // use prescaler form timer 0	


// so we get an interrupt around every 204.8us with 20MHz Clock
// set prescaller to divide by 4
option_reg.PS0 = 1;
option_reg.PS1 = 0;
option_reg.PS2 = 0;

// enable interrupts ---------> DISABLED
intcon.T0IE = 1; //enable TMR0 overflow bit	
intcon.GIE = 1;
}

void Task0()
{
while( 1 )
{
	porta.0 = 0;
	Sys_Sleep( 100 );
	porta.0 = 1;
	Sys_Sleep( 100 );
}
}

void Task1()
{
while( 1 )
{
	porta.1 = 0;
	// 500ms delay
	Sys_Sleep( 250 ); // can only sleep for a maximum of 255 with 8 bit timers
	Sys_Sleep( 250 );
	porta.1 = 1;
	// 500ms delay
	Sys_Sleep( 250 );
	Sys_Sleep( 250 );
}
}

void main()
{	
//ansel = 0;
trisa = 0x00;
//Configure A/D pins
adcon1 = 0x06;

//Initialize port A
porta = 0x00;

InitTimer();

SysInit();
SysCreateTask( hTask0, 2, Task0 );
SysCreateTask( hTask1, 2, Task1 );

SysStartTask( hTask0 );
SysStartTask( hTask1 );

while( 1 )
{   
	Sys_Yield();
}
}

 

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks Dave,

 

I've compiled and tested this code with my hardware

The same result: it hang

 

On reset :

Sometime a led on (not flashing verified with the soundcard as oscilo),

Sometime 2 leds on, not flashing,

Sometime 2 led off,

Sometime 1 led flash once,

 

i've other chip, a 16f877a, but i'm not sure to have a bootloader on it,

and a this moment dont have a hardware for flashing the chip.

I' try with this other and send results.

 

Regards,

Christian

Share this post


Link to post
Share on other sites

Hi Dave,

 

I've flashed my pic WITHOUT bootloader (from www.microchipc.com)

and now IT WOK FINE!!! :)

 

Please excuse me for your time lost.

 

But, if you know another bootloader, please let me know it

 

Thanks

Christian

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...