asap help please

Thread Starter

cassity69

Joined Dec 18, 2013
37
right cut a long story short in a group of two i have been involved with the making of a project which is 50/50 split

ive completed my half and my friend has aswell but my assesor has asked me for some extra information from my partners half which i am not that clued up on hes at work and i said ill try my best to do it

basically hes created a programme for a half effect sensor using a pic18f4520 i have the programme on my usb now but cant really make a clear picture of it

any advice how i could read from this ?
any help from where i could start would be great

the hall effect sensor has been soldered next to a stepper motor and when the stepper motor rotates the hall effect sensor counts how many times the wheel rotates
this is to measure the rpm
that is all i know lol

i have the full code if anyone wants me to inbox it to them
 

MaxHeadRoom

Joined Jul 18, 2013
28,699
If you have the code listing, what language is it programmed in?
It could be in Assembly or C as the most common methods.
What extra info is the assessor need?
For that type of application i usually use the input interrupt pin.
Max.
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
ive just messged you

he just needs a flow diagram for the code

ive started it
ive done

start
initialise pic
setup timers
setup interupts

then im completely lost
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
Rich (BB code):
#include <p18f4520.h> // header files of PIC18F4520
#include <delays.h> // include delays
#include <portb.h> // Header files required for port B interrupts
#include <usart.h>
#include <stdlib.h>
#include <stdio.h>
#include <float.h>

#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = ON
#pragma config OSC = HS 



/*Declare functions*/
void EnableInterrupts (void);
void HIGH_ISR (void);
void LOW_ISR (void);




//Globals
unsigned int TMR1overflowCnt = 0;
unsigned int TMR1FinalOverflowCnt = 0;
unsigned int TMR1FinalCnt = 0;
char CountFinished = 0;


// main function
void main (void)
{
long ClockCount = 0;
long SignalPeriod = 0;
long TwoToPowerSixteen = 65536;
long OSCperiod = 0.00000005;

TRISA = 0x00; //Set port A as output
LATA=0; //Initialize Port A.
ADCON1 = 0b00001111; //All ADC disabled
TRISD = 0x00; //Set port D as
TRISB = 0xff;


    OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 64);



INTCON2bits.RBPU = 1;	//Disable port B pullups
ADCON1 = 0X0f;			//Disable ADC
EnableInterrupts();				//Enable appropriate interrupts



while(1)
	{
		if (CountFinished == 1)
		{
			ClockCount = (TMR1FinalOverflowCnt*TwoToPowerSixteen) + TMR1FinalCnt;
			SignalPeriod = ClockCount*OSCperiod;
			CountFinished = 0;
		}
		Nop();
	}


}

	





void HIGH_ISR (void)	// High priority interrupt service routine
{
//int ControlNob0,ControlNob1,ControlNob2;

	if(	PIR1bits.TMR1IF == 1)
	{
		TMR1overflowCnt++;
		PIR1bits.TMR1IF = 0;	
	}

	if(INTCONbits.INT0IF == 1)
	{
		TMR1L = 0;
		TMR1H = 0;
		TMR1overflowCnt = 0;
		INTCONbits.INT0IF = 0;
	}
	
	if(INTCON3bits.INT1IF == 1)
	{	
		TMR1FinalOverflowCnt = TMR1overflowCnt;
		TMR1FinalCnt = TMR1H<<8 + TMR1L;
		CountFinished = 1;
		INTCON3bits.INT1IF = 0;
	}
	
	
	INTCONbits.GIE = 1;		//Enable global interrupts
	
}






void LOW_ISR (void)		// High priority interrupt service routine
{
	Nop();		
	INTCONbits.GIE = 1;		//Enable global interrupts
}





#pragma code low_vetor=0x18			//Instruct complier to serve low priority interrupts as memory location 0x18
void interrupt_at_low_vector(void)
{
	_asm 
		GOTO LOW_ISR					//Jump to low ISR
	_endasm
}
#pragma code // Return to default code section

#pragma code high_vetor=0x08			//Instruct complier to serve high priority interrupts as memory location 0x08
void interrupt_at_high_vector(void)
{
	_asm 
		GOTO HIGH_ISR					//Jump to high ISR
	_endasm
}
#pragma code // Return to default code section






//***********************************************************************
//*********************Enable interrupts**********************************
//***********************************************************************
void EnableInterrupts (void)
{

	//External interupt setup
	//Flags
	INTCONbits.INT0IF 	= 0; //Set INT0 flag to 0

	//Set prioity
	//Note INT0 is always high priority
	INTCON3bits.INT1P = 1;
	INTCON3bits.INT2P = 1;
	
	//Set INT0,1,2 to interupt on rising edge.  Can be made to be 
	INTCON2bits.INTEDG0 = 1;	//1 interupts on riseing edge
	INTCON2bits.INTEDG1 = 0;

	//Enable interupts
	INTCONbits.INT0IE 	= 1;	//Enable INT0

	//Enable priority interupts
	INTCONbits.GIEL = 1;	//Enable low priority interrupts
	INTCONbits.GIEH = 1;	//Enable high priority interrupts
	RCONbits.IPEN 	= 1;	//Enable priority’s for interrupts make all high
	
	INTCONbits.GIE = 1;		//Enable global interrupts


	T1CONbits.RD16 = 1;
	T1CONbits.T1RUN = 1;
	T1CONbits.T1CKPS1 = 0;
	T1CONbits.T1CKPS0 = 0;

	T1CONbits.TMR1CS = 0;
	T1CONbits.T1SYNC = 0;
	T1CONbits.T1OSCEN =1;
	T1CONbits.TMR1ON = 1;

//Set interupts

	PIR1bits.TMR1IF = 0;
	IPR1bits.TMR1IP = 1;
	PIE1bits.TMR1IE=1;
}
 
Top