CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interruption on RB1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alanayala



Joined: 14 Apr 2015
Posts: 1
Location: Mexico

View user's profile Send private message

Interruption on RB1
PostPosted: Wed Apr 15, 2015 12:19 am     Reply with quote

Hi Everyone.

I am a student and my team and i are doing an automatic transmission for a bicycle. But we have a problem, we need 3 interruption for the program, we are using the toggle bit RB4 and our idea was to use the interruption on RB1 and RB2, as external ones. we have the problem that even if RB1 is 1, the interruption doesnt get in. But, if I force the interruption to be one it gets into it.
Any idea?
Using MPLAB 8.89 with c18 compiler.

////// Autonomated Velocity Transmssion for a Bicycle of 9 gears/////

#include <p18f4550.h>

//Hall Sensor Variables
unsigned int sensors=0; // Counter of the sensor in the star
unsigned int sensorw=0; // Counter of the sensor in the wheel
unsigned int rpms=0; // Rpms of the star
unsigned int rpmw=0; // Rpms of the wheel
unsigned int velw;
unsigned char modo='a'; //mode

//PWM Variables
unsigned char duty_cycle;
unsigned char pinRC2;

//Bluetooth Variables
unsigned char receptor; //RXREG
unsigned int enable=0;

//Function Prototype
void Velocidad (void); //Velocity
void Estrella (void); //Star
void oc_isr (void); //PWM
void delay_3s(void); //delay
void Rx (void); //Bluetooth Reception
void Tx (unsigned char i); //Bluetooth Transmission

//High Priority Interruptions
#pragma code high_vector=0x08
void high_interrupt (void)
{ _asm nop _endasm
}

//Low Priority Interruptions
#pragma code low_vector=0x18

void low_interrupt (void)
{

if(INTCONbits.TMR0IF==1)
{
_asm goto Velocidad _endasm //Velocity
}

if(INTCONbits.RBIF==1)
{
_asm goto Estrella _endasm //Star
}

if (PIR1bits.CCP1IF==1)
{
_asm GOTO oc_isr _endasm //PWM
}


if(PIR1bits.RCIF==1)
{
_asm goto Rx _endasm //Bluetooth Reception
}

}


#pragma code
#pragma interruptlow Estrella //Counts when the hall sensor of the star is activated
void Estrella (void)
{
INTCONbits.RBIF=0; //Turn off flag
if(PORTAbits.RA0 == 1)
{
sensors++; //Add
}
if(PORTAbits.RA1 == 1)
{
sensorw++; //Add
}
}


#pragma interruptlow Velocidad
void Velocidad (void)
{ INTCONbits.TMR0IF=0;
rpms=sensors*15; //Rpms of the star
sensors=0;
rpmw=sensorw*10; //Rpms of the wheel
sensorw=0;

enable=1;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////Servomotor///////////////////////////////////////////////////////
////////Frequency=125Hz Duty Cycle= 7 a 32% Amplitude=2.5 Vpp Offset=1.25V/////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


#pragma interruptlow oc_isr
void oc_isr (void) //PWM Function
{
unsigned int temp16;

temp16=CCPR1L; //Read of Register Compare Low
temp16+=CCPR1H*256; //Read of Register Compare high

if ( pinRC2== 0)
{
pinRC2 =1;
temp16+= ((unsigned int)duty_cycle)*100;
}
else
{
pinRC2 =0;
temp16+= ((100-(unsigned int)duty_cycle)*100);
}

PORTCbits.RC2=pinRC2;
CCPR1H=temp16>>8;; //Register de Output compare high
CCPR1L=temp16; //Register de Output compare low

PIR1bits.CCP1IF=0; // Turn off flag

}


#pragma interruptlow Rx
void Rx (void) //mode
{
receptor= RCREG;
if(receptor=='a'||receptor=='b'||receptor=='c') //for the three modes
{
modo=receptor;
}

}

void delay_3s(void) //Delay
{
unsigned long i=0;
for (i=0; i<4000; i++)
{
_asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm;_asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm;
_asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm; _asm nop _endasm;
}

}

void Tx(unsigned char i)
{
TXSTAbits.TXEN=0; //Transmission OFF
TXREG=i; //Load data
TXSTAbits.TXEN=1; //Transmission ON
while(TXSTAbits.TRMT==0) //Wait
{
Nop();
}

}


void main (void)
{
unsigned int temp16;
TRISA=0xFF;
TRISB=0xFF; //All as inputs
PORTB=0;
PORTA=0;
TRISCbits.RC2=0; //ouptut PWM
PORTCbits.RC2=0;
pinRC2=0;
OSCCON=0b01100000; //Oscillator 4 MHz
T1CON=0b0100000; // Oscillator 4 MHz, timer 1

// Output compare
T3CONbits.T3CCP1=0;
CCP1CON=0b00000010; // Toogle mode

//PRIORITIES
//Global
RCONbits.IPEN=1; //Enable priority levels
INTCON=0b11111000; // enable high, low interrupts.
INTCON2=0b11110000; // dont enable RB0 pull ups and enable interruptsd
ADCON1=0x0F; //digital outputs
INTCON3=0b00011000; //enable interrupts on INT1 & INT2

//TMR0
T0CON = 0b10000010;
T0CONbits.TMR0ON=1; //Turn on TMR0


//Input Capture PWM
PIE1bits.CCP1IE=1; // Enable interrupt
IPR1bits.CCP1IP=0; // low priority
do
{

//if(enable==1) //Transmission of rpmw
//{
// Tx(rpmw);
// enable=0;
//}

while (rpms>15) // speed changes are only made when the //star is moving up from 15 rpms
{
//assigns a value to velw depending on rpmw
if (rpmw <15) velw=20;
if (rpmw>15 && rpmw <25) velw=40;
if (rpmw>25 && rpmw <35) velw=60;
if (rpmw>35 && rpmw <45) velw=80;
if (rpmw>45 && rpmw <55) velw=100;
if (rpmw>55 && rpmw <65) velw=120;
if (rpmw>65 && rpmw <75) velw=140;
if (rpmw>75 && rpmw <85) velw=160;
if (rpmw >86) velw=180;

switch (velw) // is where you will be changing the servo //duty cycle depending on velw
{
case 20:
duty_cycle=6; // Duty cycle for gear 1
delay_3s();
break;
case 40:
duty_cycle=8; // Duty cycle for gear 2
delay_3s();
break;
case 60:
duty_cycle=9; // Duty cycle for gear 3
delay_3s();
break;
case 80:
duty_cycle=11; // Duty cycle for gear 4
delay_3s();
break;
case 100:
duty_cycle=12; // Duty cycle for gear 5
delay_3s();
break;
case 120:
duty_cycle=14; // Duty cycle for gear 6
delay_3s();
break;
case 140:
duty_cycle=15; // Duty cycle for gear 7
delay_3s();
break;
case 160:
duty_cycle=17; // Duty cycle for gear 8
delay_3s();
break;
case 180:
duty_cycle=18; // Duty cycle for gear 9
delay_3s();
break;
}
break;
}
temp16=TMR1L; //Read Timer1 Low and capture Timer1 High
temp16+=TMR1H*256+ ((100-(unsigned int)duty_cycle)*100);
CCPR1H=temp16>>8;; //Register Output compare high
CCPR1L=temp16;
}

while(1);

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 12:30 am     Reply with quote

Wrong forum.

This is a CCS C forum, not C18.

Get yourself the student edition of the CCS compiler, and we can show you how to do this with this compiler. Otherwise go away.....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group