asap help please

Discussion in 'Embedded Systems and Microcontrollers' started by cassity69, May 21, 2014.

  1. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    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
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,382
    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.
     
  3. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    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
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,382
    Use the hashtag (#) in the post header to enclose your code here, I am not proficient in C, just assy.
    Max.
     
  5. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    Code ( (Unknown Language)):
    1. #include <p18f4520.h> // header files of PIC18F4520
    2. #include <delays.h> // include delays
    3. #include <portb.h> // Header files required for port B interrupts
    4. #include <usart.h>
    5. #include <stdlib.h>
    6. #include <stdio.h>
    7. #include <float.h>
    8.  
    9. #pragma config WDT = OFF
    10. #pragma config LVP = OFF
    11. #pragma config DEBUG = ON
    12. #pragma config OSC = HS
    13.  
    14.  
    15.  
    16. /*Declare functions*/
    17. void EnableInterrupts (void);
    18. void HIGH_ISR (void);
    19. void LOW_ISR (void);
    20.  
    21.  
    22.  
    23.  
    24. //Globals
    25. unsigned int TMR1overflowCnt = 0;
    26. unsigned int TMR1FinalOverflowCnt = 0;
    27. unsigned int TMR1FinalCnt = 0;
    28. char CountFinished = 0;
    29.  
    30.  
    31. // main function
    32. void main (void)
    33. {
    34. long ClockCount = 0;
    35. long SignalPeriod = 0;
    36. long TwoToPowerSixteen = 65536;
    37. long OSCperiod = 0.00000005;
    38.  
    39. TRISA = 0x00; //Set port A as output
    40. LATA=0; //Initialize Port A.
    41. ADCON1 = 0b00001111; //All ADC disabled
    42. TRISD = 0x00; //Set port D as
    43. TRISB = 0xff;
    44.  
    45.  
    46.     OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 64);
    47.  
    48.  
    49.  
    50. INTCON2bits.RBPU = 1;   //Disable port B pullups
    51. ADCON1 = 0X0f;          //Disable ADC
    52. EnableInterrupts();             //Enable appropriate interrupts
    53.  
    54.  
    55.  
    56. while(1)
    57.     {
    58.         if (CountFinished == 1)
    59.         {
    60.             ClockCount = (TMR1FinalOverflowCnt*TwoToPowerSixteen) + TMR1FinalCnt;
    61.             SignalPeriod = ClockCount*OSCperiod;
    62.             CountFinished = 0;
    63.         }
    64.         Nop();
    65.     }
    66.  
    67.  
    68. }
    69.  
    70.    
    71.  
    72.  
    73.  
    74.  
    75.  
    76. void HIGH_ISR (void)    // High priority interrupt service routine
    77. {
    78. //int ControlNob0,ControlNob1,ControlNob2;
    79.  
    80.     if( PIR1bits.TMR1IF == 1)
    81.     {
    82.         TMR1overflowCnt++;
    83.         PIR1bits.TMR1IF = 0;   
    84.     }
    85.  
    86.     if(INTCONbits.INT0IF == 1)
    87.     {
    88.         TMR1L = 0;
    89.         TMR1H = 0;
    90.         TMR1overflowCnt = 0;
    91.         INTCONbits.INT0IF = 0;
    92.     }
    93.    
    94.     if(INTCON3bits.INT1IF == 1)
    95.     {  
    96.         TMR1FinalOverflowCnt = TMR1overflowCnt;
    97.         TMR1FinalCnt = TMR1H<<8 + TMR1L;
    98.         CountFinished = 1;
    99.         INTCON3bits.INT1IF = 0;
    100.     }
    101.    
    102.    
    103.     INTCONbits.GIE = 1;     //Enable global interrupts
    104.    
    105. }
    106.  
    107.  
    108.  
    109.  
    110.  
    111.  
    112. void LOW_ISR (void)     // High priority interrupt service routine
    113. {
    114.     Nop();     
    115.     INTCONbits.GIE = 1;     //Enable global interrupts
    116. }
    117.  
    118.  
    119.  
    120.  
    121.  
    122. #pragma code low_vetor=0x18         //Instruct complier to serve low priority interrupts as memory location 0x18
    123. void interrupt_at_low_vector(void)
    124. {
    125.     _asm
    126.         GOTO LOW_ISR                    //Jump to low ISR
    127.     _endasm
    128. }
    129. #pragma code // Return to default code section
    130.  
    131. #pragma code high_vetor=0x08            //Instruct complier to serve high priority interrupts as memory location 0x08
    132. void interrupt_at_high_vector(void)
    133. {
    134.     _asm
    135.         GOTO HIGH_ISR                   //Jump to high ISR
    136.     _endasm
    137. }
    138. #pragma code // Return to default code section
    139.  
    140.  
    141.  
    142.  
    143.  
    144.  
    145. //***********************************************************************
    146. //*********************Enable interrupts**********************************
    147. //***********************************************************************
    148. void EnableInterrupts (void)
    149. {
    150.  
    151.     //External interupt setup
    152.     //Flags
    153.     INTCONbits.INT0IF   = 0; //Set INT0 flag to 0
    154.  
    155.     //Set prioity
    156.     //Note INT0 is always high priority
    157.     INTCON3bits.INT1P = 1;
    158.     INTCON3bits.INT2P = 1;
    159.    
    160.     //Set INT0,1,2 to interupt on rising edge.  Can be made to be
    161.     INTCON2bits.INTEDG0 = 1;    //1 interupts on riseing edge
    162.     INTCON2bits.INTEDG1 = 0;
    163.  
    164.     //Enable interupts
    165.     INTCONbits.INT0IE   = 1;    //Enable INT0
    166.  
    167.     //Enable priority interupts
    168.     INTCONbits.GIEL = 1;    //Enable low priority interrupts
    169.     INTCONbits.GIEH = 1;    //Enable high priority interrupts
    170.     RCONbits.IPEN   = 1;    //Enable priority’s for interrupts make all high
    171.    
    172.     INTCONbits.GIE = 1;     //Enable global interrupts
    173.  
    174.  
    175.     T1CONbits.RD16 = 1;
    176.     T1CONbits.T1RUN = 1;
    177.     T1CONbits.T1CKPS1 = 0;
    178.     T1CONbits.T1CKPS0 = 0;
    179.  
    180.     T1CONbits.TMR1CS = 0;
    181.     T1CONbits.T1SYNC = 0;
    182.     T1CONbits.T1OSCEN =1;
    183.     T1CONbits.TMR1ON = 1;
    184.  
    185. //Set interupts
    186.  
    187.     PIR1bits.TMR1IF = 0;
    188.     IPR1bits.TMR1IP = 1;
    189.     PIE1bits.TMR1IE=1;
    190. }
    191.  
     
  6. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    does anyone know how to make a flow diagram please

    thanks max head room
     
Loading...