Error in programming Project 6 (ultrasonic range finder)

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

Re: Error in programming Project 6 (ultrasonic range finder)

Postby robosang » Thu Jul 12, 2012 10:16 pm

I think you should just simply put value in the configuration bit.

__CONFIG (0x2CE4);

though this is not the complete configuration bits because PIC16F887 have 2 configuration words, but the 2nd words does not affect your program for now. Again, I think some other thread have the answer, this is due to different version of Hitech compiler, changes the label for configurations setting in the header file.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Fri Jul 13, 2012 10:04 am

After i change it its working...however the display shows "Dist :491 inch Analog"
no matter how i move the sensor the value is also around 491 inch...whats happen??
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby robosang » Fri Jul 13, 2012 2:56 pm

You are going round and round, show us the hardware, check your ultrasonic sensor, whether there is voltage change at the AN pin, etc. Who can help if we cannot see the problem? There may be hundreds possibilities for it not to work.

You might miss a connection, your sensor might not be working at all, your code does not fit with your hardware, ........
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Fri Jul 13, 2012 4:26 pm

The sensor doesnt have any problem...and the connnection I check alot of time follow the project six 6 guild...all going smoothly...only when I start the programming everything ruined
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Fri Jul 13, 2012 6:03 pm

I canot attach the photo..it said the file is invalid...it is jpeg file..
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Fri Jul 13, 2012 9:05 pm

Thnks and sry for trouble u guys~~
Attachments
image 2.jpg
My result (always that number)
image 1.jpg
My connection
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby robosang » Fri Jul 13, 2012 10:25 pm

well, cannot see the whole setup, no photo on the connection to ultrasonic sensor. Looking at the code, there is nothing wrong, at least no major mistake. A brief look through the code, there should be 3 modes available, have you tested the other modes? What is the result?

Using breadboard to interface always cause uncertainty, especially when you have a lot of wiring, I seldom use breadboard.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Fri Jul 13, 2012 10:36 pm

I follow the connection base on this one...the connect the sensor with long wire thats y it cannot be seen...the other 2 mode shows 000 in the reading..i guess is not affected rite?
Attachments
Untitled.jpg
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby zhenning » Sat Jul 14, 2012 7:35 am

yeosteven WROTE:I manage to find the problem with the error there as I change the ___ to __
howeever i got another problem now....my code is

CODE: SELECT_ALL_CODE
//==========================================================================
//   Author            : CYTRON TECHNOLOGIES SDN BHD
//   Project            : SK40C sample code for PIC16F887
//   Project description   : Analog Sensor: Range using Ultrasonic Range Finder
//                    3 mode : (1: Analog)
//                           (2: PWM   )
//                           (3: UART  )
//==========================================================================

//   include
//==========================================================================
#include <htc.h>
#include "lcd.h"
#include "adc.h"
#include "system.h"
#include "uart.h"

//   Configuration
//==========================================================================
__CONFIG(MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);

//   global variable
//===========================================================================
unsigned int To=0,T=0,TH=0;
unsigned char data[6] = {0};

//  Interrrupt Subroutine
//============================================================================
static void interrupt isr(void)
{
   if (T0IF)                        // TMR0 is overflow
   {
      T0IF = 0;                      // clear flag bit
      To +=0x100;                     // count number of TMR0 overflow ( make it to 16bit TMR)
   }
      
   if(RBIF)                        // there is change bit on RB4-RB7
   {
      RBIF = 0;                     //                                           ____
      if (PWM_IN)                     // PWM_IN(RB2) is 1 mean is rising form 0  __|         
      {
         TMR0 = 0;                  // clear all counter involved, start new count for period of RB4 high
         To = 0;
      }
                                 //                                 ___
      else TH = TMR0 + To;            // PWM_IN(RB2) is 0 mean is falling form 1       |_____  // save TH, RB4 high period
   }
}

//   main function
//==========================================================================
void main(void)
{
unsigned char mode = 1;
   PORTA = 0;                     // Clear Port
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;

   
   TRISA = 0b11111111;               // set PORTA as INPUT
   TRISB = 0b00000111;               // set PORTB<7:3> as OUTPUT , PORTB<2:0> as INPUT
   TRISC = 0b10000000;
   TRISD = 0b00000000;               // set PORTD as output
   

   ANSELH = 0;                   // SET PORTB as DIGITAL I/O for PIC16F887
   WPUB = 1;                     // PORTB Weak Pull Up enable

   // Interupt on change
   IOCB0 = 0;            
   IOCB1 = 0;
   IOCB2 = 1;                     // when PORTB.2 detect change will interrupt
   IOCB3 = 0;
   IOCB4 = 0;
   IOCB5 = 0;
   IOCB6 = 0;
   IOCB7 = 0;

   RBIE = 1;                     // PORTB Change Interrupt Enable bit   


   // TMR 0 configuation
   T0CS = 0;                  
   PSA = 0;                  
   PS2 = 1;                     // prescale 1:256
   PS1 = 1;                  
   PS0 = 1;                  
   T0IE = 1;                     // TMR0 Interrupt
   TMR0 = 0;
   
   GIE = 1;                     // Global Intterupt enable
   PEIE = 1;                     // Peripheral Interrupt enable

   lcd_initialize();               // Initialise LCD

   adc_initialize();               // Initialise ADC

   uart_initialize();               // Initialise UART

   TX == 1;                     // ON Transmit pin (refer Maxbotix EZ1 Ultrasonic datasheet)

   lcd_home();
   lcd_putstr("Dist:");
   lcd_goto(0x0B);
   lcd_putstr("inch");

while (1)
   {
   switch(mode)
      {
   case 1:         lcd_2ndline();
               lcd_putstr("Analog");
               while (SW1 == 1)
                  {
                  unsigned int adc_value = 0;
                  unsigned int range_an = 0; 
                  unsigned char j;
                  adc_on();
                  for(j = 0 ; j < 10 ; j++)                  // take analog result for 20 times
                     {
                     adc_value = adc_value + ui_adc_read();      
                     }
   
                  adc_value = adc_value/10;                  // adc_value devide by 10 to get average result
                  range_an = adc_value/2;                     // max vslue adc_value = 2.55/5 *1024 - 1 =  522
                  lcd_goto(0x05);                           // max is 254 inch... 522/254 = ~2
                   lcd_bcd(3,range_an);                     // (1 to 6 inch) is readed as 6 inch (refer to ultrasonic datasheet)
                  }   
               while (SW1 == 0);
               break;

   case 2:         lcd_2ndline();
               lcd_putstr("PWM   ");
               unsigned int range_pwm;
               while(SW1 == 1)
                  {
                  range_pwm = TH;                           // read TH from interrupt subroutine
                  lcd_goto(0x05);                           // each value = 256*4/20mhz = 51.2us, 1 inch = 147us 
                  range_pwm = (range_pwm*100)/288;            // 147us/51.2us = 2.87
                  lcd_bcd(3,range_pwm);   
                  }
               while (SW1 == 0);
               break;

   case 3:          lcd_2ndline();
               lcd_putstr("UART   ");
               unsigned int value,k,l = 0;
               while(SW1 == 1)
                  {
                  
                  for (l=0 ; l<6 ; l++)
                     {
                     uc_uart_receive();                     //take value from UART subroutine
                     if(RCREG == 'R') data[k=0] = RCREG;         // check if start byte 'R' is met 
                     if(data[0] == 'R') data[k++] = RCREG;      // save the data in data array
                     if (k>4) k = 4;                        // if the data array reached max, set the index to 4
                     }
                     lcd_goto(0x05);
                     send_lcd_data(1,data[1]);
                     send_lcd_data(1,data[2]);
                     send_lcd_data(1,data[3]);
                  }
      }

      while (SW1 == 0);
      if (++mode > 3)             // if SW1 is press, increase the mode number until it is max and loop back
         {
         mode = 1;
         }   
      
   }   
}


and i got this error...

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\adc.p1".
Clean Warning: File "C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.p1" doesn't exist.
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\lcd.p1".
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\uart.p1".
Clean: Done.
Build C:\Users\Yeo\Desktop\ETP\Project_6\Project_6 for device 16F887
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\adc.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\lcd.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\uart.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" -oProject_6.cof -mProject_6.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 adc.p1 Project_6.p1 lcd.p1 uart.p1 --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error [800] C:\Users\Yeo\AppData\Local\Temp\s4s4.; 45. undefined symbol "FOSC_INTRCIO"

how should I define this?? anyone help??


Hi,
Each MCU has a different config word defined by HiTech. Some uses FOSC_INTRCIO some uses other definition. Attached is part of the extracted definition from the header file.

CODE: SELECT_ALL_CODE
// Config Register: CONFIG1
#define CONFIG1              0x2007
// Oscillator Selection bits
// RC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, RC on RA7/OSC1/CLKIN
#define FOSC_EXTRC_CLKOUT    0xFFFF
// RCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, RC on RA7/OSC1/CLKIN
#define FOSC_EXTRC_NOCLKOUT  0xFFFE
// INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
#define FOSC_INTRC_CLKOUT    0xFFFD
// INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
#define FOSC_INTRC_NOCLKOUT  0xFFFC
// EC: I/O function on RA6/OSC2/CLKOUT pin, CLKIN on RA7/OSC1/CLKIN
#define FOSC_EC              0xFFFB
// HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_HS              0xFFFA
// XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_XT              0xFFF9
// LP oscillator: Low-power crystal on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_LP              0xFFF8
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby robosang » Sat Jul 14, 2012 7:46 am

zhenning is right, different CPU have different config words, and to make you suffer more, HI-TECH change that label from the older version header file to new version, causing the compiler not to recognize the label. Same happen for the case ADGO to GODONE.

Now, back to the circuit/interface and your ultrasonic. You say it is working, but the reading for mode 2 and mode 3 give you 0, this is totally wrong. If the ultrasonic is working, at least there should be reading because ultrasonic will automatically output 3 data, Analog, PWM and UART (inverted).

I suspect:
1. The wiring not correct. Yes, everyone say they do it correct, according to the diagram, but when you notice something is wrong, it is wrong, people tend to make assumption. Happen every time.
2. Ultrasonic sensor is not working at all, you can try referring to this site to test whether it is working: http://www.maxbotix.com/articles/016.htm
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

PreviousNext

Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 4 guests

cron