Jump to content

Recommended Posts

Are there any help files on the simulator? Simulating inputs?

 

Does it do Interrupts?

 

I can't get it to break at an interrupt set up on Timer1 (I hope!) on 16F88?

I see the Hi and Lo bytes of the counter changing in the register window as I single step, but it never stops in the interrupt?

 

Thanks, the learning curve continues!

 

Mike

Link to post
Share on other sites

Well I am in MPLAB simulator running boostC. I see my Timer1 count go up and roll over and set the Interrupt Flag (TMR1IF) go high.

Same result as in BoostC IDE running simulator, no interrupt?

Instructions in Sim says it does interrupts for this part (16F88) and using Timer1.

 

 

No Interrupt? PIE1, TMR1IE is high as well as TICON,TMR1ON.

INTCON GIE is set too?

 

Is there some switch to turn on Interrupts in MPLAM Sim?

 

Also using Boost C under MPLAB, the cursor doesn't to to start of code in the simulator on reset?

I can set a break point and run. Then I see were the code has stopped by an arrow pointing to it.

 

I am wondering if I need some ORG statement at the interrupt?

 

 

Here is the code located above the main. no ORGs?

 

void interrupt( void )

{

 

//Handle timer1 interrupt

if( pir1& (1<<TMR1IF) )

{

 

// dotimer1int();

 

// preload Timer1 // going to call this when I get interrupt running

tmr1h = 0xb1; //0xb1df is preload counter for 20mS at 8 MHz until rollover

tmr1l = 0xdf;

 

clear_bit( pir1, TMR1IF ); //clear timer 1 interrupt bit

}

 

//Handle timer2 interrupt

if( pir1 & (1<<TMR2IF) ) // shift 1over to TMR2IF bit position

{

clear_bit( pir1, TMR2IF ); //clear timer 2 interrupt bit

}

 

}

 

 

I will quit for a while and sit on it!

 

 

 

Thanks

Mike

 

Are there any help files on the simulator? Simulating inputs?

 

Does it do Interrupts?

 

I can't get it to break at an interrupt set up on Timer1 (I hope!) on 16F88?

I see the Hi and Lo bytes of the counter changing in the register window as I single step, but it never stops in the interrupt?

 

Thanks, the learning curve continues!

 

Mike

Link to post
Share on other sites
Well I am in MPLAB simulator running boostC. I see my Timer1 count go up and roll over and set the Interrupt Flag (TMR1IF) go high.

Same result as in BoostC IDE running simulator, no interrupt?

Instructions in Sim says it does interrupts for this part (16F88) and using Timer1.

 

 

No Interrupt? PIE1, TMR1IE is high as well as TICON,TMR1ON.

INTCON GIE is set too?

....

If you provide a complete but small program that demonstrates this problem I'll take a look.

 

Regards

Dave

Link to post
Share on other sites

Dave,

 

Here is the code for a 20 mS interrupt by Timer1.

 

I took some stuff out to shorten it. I hope I did not screw it up.

 

 

Thanks for looking at it!

 

Mike

 

 

 

 

////////////////////////////////////////////////////////////////////////////

#include <system.h>

// #include <icd2.h> // needed only if icd2 used for debugging

 

#include <PIC16F88.h>

 

#pragma DATA _CONFIG1, _PWRTE_ON & _WDT_OFF & _HS_OSC & _CP_OFF & _LVP_OFF

// #pragma OPTIMIZE "0"

 

//Set clock frequency

#pragma CLOCK_FREQ 8000000

 

//*************************

// Function Declarations

 

unsigned char atod(void);

 

void dotimer1int(void);

 

 

//*************************

 

 

 

 

//*************************

// Code

//*************************

 

 

void interrupt( void )

{

 

//Handle timer1 interrupt

if( pir1& (1<<TMR1IF) )

{

 

// dotimer1int(); //call function here OK?

 

// preload Timer1

tmr1h = 0xb1; //b1df is preload counter for 20mS at 8 MHz until rollover

tmr1l = 0xdf;

 

clear_bit( pir1, TMR1IF ); //clear timer 1 interrupt bit

 

}

 

//Handle timer2 interrupt

if( pir1 & (1<<TMR2IF) ) // shift 1over to TMR2IF bit position

{

clear_bit( pir1, TMR2IF ); //clear timer 2 interrupt bit

}

 

}

 

 

void main( void )

{

 

unsigned short Leddata = 0;

unsigned char Adata = 0;

unsigned char N = 0;

 

 

 

volatile bit Adc_go@ADCON0.GO;

 

 

//Configure port A

trisa = 0xff; // A are all Inputs

 

//Configure port B // B are all Outputs

trisb = 0x00;

 

//Initialize port B

portb = 0x00;

 

//******************************************************

//Set A/D Converters - 5 Registers involved, these 3 and the results Hi (adresh) and Lo ( adresl)

 

ansel = 00000001b; // select A0 as A/D Input

 

adcon1 = 01000000b; // left justified, A/D clock divided by 2, Vref is Vdd to Vss(Ground)

 

adcon0 = 01000000b; // select A/D conversion clocks to F/16 if ADCS2 = 1,

// Chan 0, A/D is Off to save power

 

//******************************************************

// Comparators not used

 

//Set Comparators

cmcon = 00000111b; // disable comparators

 

//Set Timer0 mode

clear_bit( option_reg, T0CS ); // configure timer0 as a timer

//Set prescaler assignment

clear_bit( option_reg, PSA ); // prescaler is assigned to timer0

//Set prescaler rate

clear_bit( option_reg, PS2 ); // prescaler rate 1:2

clear_bit( option_reg, PS1 );

clear_bit( option_reg, PS0 );

//Set timer0 source edge selection

set_bit( option_reg, T0SE ); // increment on high-to-low transition on RA4/T0CKI pin

 

//******************************************************

// Set up Timer1 for Interrupt every 20 mS for Servo Control

// 16 bit counter, increments F/4, or every 2uS for 8 MHz crystal

// Count in TMR1H and TMR1L

 

//Set Timer1 prescaler rate

clear_bit( t1con, T1CKPS1 ); //prescaler rate 1:1

clear_bit( t1con, T1CKPS0 );

 

//Set Timer1 clock source

clear_bit( t1con, TMR1CS );

 

//Set Timer1 ON

set_bit( t1con, TMR1ON ); //Turn On Timer1

 

// preload Timer1

tmr1h = 0xb1; //0xb1df is preload counter for 20mS at 8 MHz

tmr1l = 0xdf; //until rollover, 65535 - 20000 = 45535 = oxb1df

 

 

//******************************************************

//Timer2 not used

 

//Set timer 2 prescaler rate

clear_bit( t2con, T2CKPS1 ); //prescaler rate 1:1

clear_bit( t2con, T2CKPS0 );

//Set timer 2 postscaler rate

clear_bit( t2con, TOUTPS3 ); //postscaler rate 1:1

clear_bit( t2con, TOUTPS2 );

clear_bit( t2con, TOUTPS1 );

clear_bit( t2con, TOUTPS0 );

//Set timer 2 mode (enable or disable)

clear_bit( t2con, TMR2ON ); //enable timer 2

 

 

//******************************************************

 

// do blink test

 

nop();

portb = 0xff;

 

// Delay 1/4S

delay_ms(250);

 

portb = 0x00;

 

// Delay 1/4S

delay_ms(250);

portb = 0xff;

 

// Delay 1/4S

delay_ms(250);

 

portb = 0x00;

 

// Delay 1S

delay_ms(250);

 

// Enable Timer1 interrupts

set_bit (pie1,TMR1IE);

 

//Enable all interrupts

set_bit (intcon,GIE);

 

 

while(1)

 

{

 

nop();

 

//do nothing for debug

 

 

 

} //While

 

}

 

 

 

//*************************

// Functions

//*************************

 

//******************************************************

 

// atod() function reads 8 bit A/D data on A0

 

unsigned char atod()

{

set_bit (adcon0,ADON); //Turn On the A/D

 

delay_ms(1);

 

set_bit (adcon0,GO); //Start Conversion

 

while (adcon0.NOT_DONE)

{

nop(); //wait for conversion, good spot to stop for debug

};

 

clear_bit (adcon0,ADON); //Turn Off the A/D

 

return(adresh);

}

 

//******************************************************

 

// dotimer1int() function is called when Timer1 interrupts for servo control

 

void dotimer1int()

{

 

set_bit(portb,0);

delay_us(10);

clear_bit(portb,0);

 

return;

 

}

 

 

 

 

 

 

 

 

Well I am in MPLAB simulator running boostC. I see my Timer1 count go up and roll over and set the Interrupt Flag (TMR1IF) go high.

Same result as in BoostC IDE running simulator, no interrupt?

Instructions in Sim says it does interrupts for this part (16F88) and using Timer1.

 

 

No Interrupt? PIE1, TMR1IE is high as well as TICON,TMR1ON.

INTCON GIE is set too?

....

If you provide a complete but small program that demonstrates this problem I'll take a look.

 

Regards

Dave

Link to post
Share on other sites

Dave,

 

I moved over to running under MPLAB.

I copied the whole sub directory from SourceBoost to MPLAB and built a new project including SourceBoost tools.

 

It is interesting that the Sim does not show the Pointer to the start of main() after a reset.

If I "step into" 4 times, the Green Arrow finally shows up at main()?

 

I think it is starting at the interrupt when reset?

 

Although the Location Arrow is missing until 4X step into?

 

Your manual says every program has to have an interrupt function and a main.

I used the project wizard from another part to start this example?

 

Now I found in MPLAB "Configure" "Settings" menu, a box to check that makes the Reset to to Main()?

This fixed the reset problem?

 

I am looking in Sim where the interrupts could possibly be turned OFF? But it also does not work in your simulator.

 

Found an Icon in MPLAB that zipped the whole project up in a file, I attached it.

 

 

Thanks!

 

Mike

 

 

 

Dave,

 

Here is the code for a 20 mS interrupt by Timer1.

 

I took some stuff out to shorten it. I hope I did not screw it up.

 

 

Thanks for looking at it!

 

Mike

 

 

 

 

////////////////////////////////////////////////////////////////////////////

#include <system.h>

// #include <icd2.h> // needed only if icd2 used for debugging

 

#include <PIC16F88.h>

 

#pragma DATA _CONFIG1, _PWRTE_ON & _WDT_OFF & _HS_OSC & _CP_OFF & _LVP_OFF

// #pragma OPTIMIZE "0"

 

//Set clock frequency

#pragma CLOCK_FREQ 8000000

 

//*************************

// Function Declarations

 

unsigned char atod(void);

 

void dotimer1int(void);

 

 

//*************************

 

 

 

 

//*************************

// Code

//*************************

 

 

void interrupt( void )

{

 

//Handle timer1 interrupt

if( pir1& (1<<TMR1IF) )

{

 

// dotimer1int(); //call function here OK?

 

// preload Timer1

tmr1h = 0xb1; //b1df is preload counter for 20mS at 8 MHz until rollover

tmr1l = 0xdf;

 

clear_bit( pir1, TMR1IF ); //clear timer 1 interrupt bit

 

}

 

//Handle timer2 interrupt

if( pir1 & (1<<TMR2IF) ) // shift 1over to TMR2IF bit position

{

clear_bit( pir1, TMR2IF ); //clear timer 2 interrupt bit

}

 

}

 

 

void main( void )

{

 

unsigned short Leddata = 0;

unsigned char Adata = 0;

unsigned char N = 0;

 

 

 

volatile bit Adc_go@ADCON0.GO;

 

 

//Configure port A

trisa = 0xff; // A are all Inputs

 

//Configure port B // B are all Outputs

trisb = 0x00;

 

//Initialize port B

portb = 0x00;

 

//******************************************************

//Set A/D Converters - 5 Registers involved, these 3 and the results Hi (adresh) and Lo ( adresl)

 

ansel = 00000001b; // select A0 as A/D Input

 

adcon1 = 01000000b; // left justified, A/D clock divided by 2, Vref is Vdd to Vss(Ground)

 

adcon0 = 01000000b; // select A/D conversion clocks to F/16 if ADCS2 = 1,

// Chan 0, A/D is Off to save power

 

//******************************************************

// Comparators not used

 

//Set Comparators

cmcon = 00000111b; // disable comparators

 

//Set Timer0 mode

clear_bit( option_reg, T0CS ); // configure timer0 as a timer

//Set prescaler assignment

clear_bit( option_reg, PSA ); // prescaler is assigned to timer0

//Set prescaler rate

clear_bit( option_reg, PS2 ); // prescaler rate 1:2

clear_bit( option_reg, PS1 );

clear_bit( option_reg, PS0 );

//Set timer0 source edge selection

set_bit( option_reg, T0SE ); // increment on high-to-low transition on RA4/T0CKI pin

 

//******************************************************

// Set up Timer1 for Interrupt every 20 mS for Servo Control

// 16 bit counter, increments F/4, or every 2uS for 8 MHz crystal

// Count in TMR1H and TMR1L

 

//Set Timer1 prescaler rate

clear_bit( t1con, T1CKPS1 ); //prescaler rate 1:1

clear_bit( t1con, T1CKPS0 );

 

//Set Timer1 clock source

clear_bit( t1con, TMR1CS );

 

//Set Timer1 ON

set_bit( t1con, TMR1ON ); //Turn On Timer1

 

// preload Timer1

tmr1h = 0xb1; //0xb1df is preload counter for 20mS at 8 MHz

tmr1l = 0xdf; //until rollover, 65535 - 20000 = 45535 = oxb1df

 

 

//******************************************************

//Timer2 not used

 

//Set timer 2 prescaler rate

clear_bit( t2con, T2CKPS1 ); //prescaler rate 1:1

clear_bit( t2con, T2CKPS0 );

//Set timer 2 postscaler rate

clear_bit( t2con, TOUTPS3 ); //postscaler rate 1:1

clear_bit( t2con, TOUTPS2 );

clear_bit( t2con, TOUTPS1 );

clear_bit( t2con, TOUTPS0 );

//Set timer 2 mode (enable or disable)

clear_bit( t2con, TMR2ON ); //enable timer 2

 

 

//******************************************************

 

// do blink test

 

nop();

portb = 0xff;

 

// Delay 1/4S

delay_ms(250);

 

portb = 0x00;

 

// Delay 1/4S

delay_ms(250);

portb = 0xff;

 

// Delay 1/4S

delay_ms(250);

 

portb = 0x00;

 

// Delay 1S

delay_ms(250);

 

// Enable Timer1 interrupts

set_bit (pie1,TMR1IE);

 

//Enable all interrupts

set_bit (intcon,GIE);

 

 

while(1)

 

{

 

nop();

 

//do nothing for debug

 

 

 

} //While

 

}

 

 

 

//*************************

// Functions

//*************************

 

//******************************************************

 

// atod() function reads 8 bit A/D data on A0

 

unsigned char atod()

{

set_bit (adcon0,ADON); //Turn On the A/D

 

delay_ms(1);

 

set_bit (adcon0,GO); //Start Conversion

 

while (adcon0.NOT_DONE)

{

nop(); //wait for conversion, good spot to stop for debug

};

 

clear_bit (adcon0,ADON); //Turn Off the A/D

 

return(adresh);

}

 

//******************************************************

 

// dotimer1int() function is called when Timer1 interrupts for servo control

 

void dotimer1int()

{

 

set_bit(portb,0);

delay_us(10);

clear_bit(portb,0);

 

return;

 

}

 

 

 

 

 

 

 

 

Well I am in MPLAB simulator running boostC. I see my Timer1 count go up and roll over and set the Interrupt Flag (TMR1IF) go high.

Same result as in BoostC IDE running simulator, no interrupt?

Instructions in Sim says it does interrupts for this part (16F88) and using Timer1.

 

 

No Interrupt? PIE1, TMR1IE is high as well as TICON,TMR1ON.

INTCON GIE is set too?

....

If you provide a complete but small program that demonstrates this problem I'll take a look.

 

Regards

Dave

PicDem1e.zip

Link to post
Share on other sites

Oh my.

 

I looked at that many times, and thought it was for "interrupt on Port Changes"?

I did not over look it, just thought it was for ports?

 

Thanks! Now I get to continue! I am going to make a variable width pulse every 20mS for a model servo! Fun!

 

Mike

 

 

Hi Mike,

 

Try adding this to your code.

 

//Enable Peripheral interrupts
set_bit (intcon,PEIE);

 

Cheers

 

Reynard

Link to post
Share on other sites
Thanks! Now I get to continue! I am going to make a variable width pulse every 20mS for a model servo! Fun!

Mike

 

Looks like it may be worth you looking at the PWM module - this may save you some effort.

Edited by Tim Zim
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...