go away spammer

Author Topic: SRF05 sensor  (Read 2380 times)

0 Members and 1 Guest are viewing this topic.

Offline daisordanTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
SRF05 sensor
« on: March 12, 2011, 01:40:08 PM »
I have writen up the code for my SRF05 sensor with 18F4455 with MPLAB. When i just run the code, its working fine. But now if i put any code in the main..like LED flashing... The whole sensor doesnt work. I didnt use isr for my sensor measurement, is that case my whole sensor not working??
Thanks

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: SRF05 sensor
« Reply #1 on: March 12, 2011, 01:45:42 PM »
Post code.

Offline daisordanTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: SRF05 sensor
« Reply #2 on: March 12, 2011, 02:26:49 PM »

unsigned int distance;

void set_timer0(void)
{   
    OpenTimer0(T0_16BIT &          
                T0_SOURCE_INT &   
                T0_PS_1_1 );       
}


void trig_pulse (void)
{
   LATDbits.LATD2 = 1;       
    Delay10TCY();           
      LATDbits.LATD2 = 0;       
    Delay10TCYx(20);             

void measure_pulse (void)
{
    while(PORTDbits.RD3);   
    T0CONbits.TMR0ON = 0;   
}


void main (void)
{
    LATDbits.LATD2 = 0;     
    TRISD=0b00001000;     

   while(1)
   {       
       trig_pulse();               
      set_timer0();
       while(!PORTDbits.RD3);       
       measure_pulse();           
        distance = (int)TMR0L + (int)TMR0H << 8;
       distance /= (int)58;         
    }       
}

Offline daisordanTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: SRF05 sensor
« Reply #3 on: March 12, 2011, 03:22:05 PM »
Or maybe somethings wrong with the MPLAB setting? When i plug in PICkits to program the chip ( only sensor code), the sensor is working(power from PICkit). Now i program it, plug out PICkit, connect the chip to another power supply, the sensor doesnt work .

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: SRF05 sensor
« Reply #4 on: March 12, 2011, 06:54:55 PM »
Post all of the code including the Config bits, includes and variable definitions.

Are you building DEBUG or RELEASE code? MPLAB tool bar drop-down.

Have you run/stepped through your code in MPLAB's Simulator?

 


Get Your Ad Here

data_list