need help to combine the programming

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

need help to combine the programming

Postby nanslipknot86 » Sat Oct 17, 2009 9:18 pm

hye.i hope anybody in this forum can help me to solve my problem.i'm final year student which have final year project.for my final project, i have to make maze mapper robot.i use PIC18F4550 as the microcontroller,ir distance sensor (sharp GP2D120XJ00F) and the dc motor with encoder PD3046.all component i bought from cytron cmpany.my problem is i don't know how to combine the ir sensor programming with the dc motor.actually i have make the combination between ir sensor with LED programming and it works functionally.but when i try to combine between ir sensor with dc motor,the circuit not function.i will attach the the combination of my programming.for your information i use pbp format in microcode studio software.

define osc 8

'defenition
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
MWPWM1 VAR PORTC.2 'PWM MOTOR 1
MWPWM2 VAR PORTC.1 'PWM MOTOR 2
MRCW1 VAR PORTD.4
MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
MRCW2 VAR PORTD.6
MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
TRISD.4=0
TRISD.5=0
TRISD.6=0
TRISD.7=0
TRISA.2=1
TRISA.1=1
TRISA.0=1
ADCON1=%00000000
SENSOR1 VAR BYTE
SENSOR2 VAR BYTE
SENSOR3 VAR BYTE

HPWM 1,150,1000
HPWM 2,150,1000

'MAIN PROGRAM
MAIN:
gosub fwd 'JUMO TO FWD
GOSUB IR1 'JUMP TO IR1 SUBOUTINE
GOSUB IR2 'JUMP TO IR2 SUBROUTINE
GOSUB IR3 'JUMP TO IR3 SUBROUTINE

GOTO MAIN 'LOOP TO MAIN FOREVER

'SUBROUTINE PROGRAM

FWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=1
MRCW2=0
RETURN

BWD:
HPWM 1,150,500
MRCCW1=1
MRCW1=0
HPWM 2,150,500
MRCCW2=0
MRCW2=1
RETURN

RIGHT:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=0
MRCW2=1
RETURN

LEFT:
HPWM 1,150,500
MRCCW1=1
MRCW1=0
HPWM 2,150,500
MRCCW2=1
MRCW2=0
RETURN

IR1:
ADCIN 0,SENSOR1

IF SENSOR1>46 THEN
GOSUB RIGHT


ELSE
if SENSOR1<46 THEN
GOSUB FWD

ENDIF
ENDIF
pause 1000

RETURN

IR2:
ADCIN 1,SENSOR2

IF SENSOR2>46 THEN
GOSUB LEFT


ELSE
if SENSOR2<46 THEN
GOSUB FWD

ENDIF
ENDIF
pause 1000

RETURN

IR3:
ADCIN 2,SENSOR3

IF SENSOR3>46 THEN
GOSUB BWD


ELSE
if SENSOR3<46 THEN
GOSUB FWD

ENDIF
ENDIF
pause 1000

RETURN
nanslipknot86
Freshie
 
Posts: 7
Joined: Sat Oct 17, 2009 3:40 pm

Re: need help to combine the programming

Postby robosang » Sun Oct 18, 2009 12:06 am

This is the attitude and solution of our future engineer..... searching for direct solution in forum?

I thought there are Forum Rules and Regulations, I think Cytron should take it off, no one even read that topic.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: need help to combine the programming

Postby nanslipknot86 » Sun Oct 18, 2009 1:34 am

i'm not to search the solution.i just need the suggestion or hint so that i can repair the programmed that i have made with my own.i tried many ways but not function.i will be glad if any one can give me some advise so that i can solve the programmed.i hope u not misjudge me.
thanks for the comment anyway.
nanslipknot86
Freshie
 
Posts: 7
Joined: Sat Oct 17, 2009 3:40 pm

Re: need help to combine the programming

Postby sich » Sun Oct 18, 2009 2:30 pm

My first question: Are u certain that when u take away all those combinations between the devices, each device is working fine with ur program? Test each one of them step-by-step before u do the combination. For example, can you control ur dc motor to rotate cw and ccw with a simple program?
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: need help to combine the programming

Postby ober » Sun Oct 18, 2009 5:59 pm

I would agree with sich. Minimize your troubleshooting area, start from very simple code and expand it, step by step, verify a small code is working. After you add or modify your code, check again whether is working as you want, if not, you know that something is wrong at the code that you have just add. Do not simply combine section of codes from different program. Good luck!
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: need help to combine the programming

Postby nanslipknot86 » Sun Oct 18, 2009 6:12 pm

yes,i have test the each device with the simple program.the test dc motors were fine.i can control cw n ccw.the sensors also succeeded when i made simple program to interface with the LED.the circuit also function.when i combined programs of the sensors with the dc motors, there were no error.i checked the flow of the code,the code flow exactly what i wanted.then i tried to put the PIC with those programs that i made into my circuit.then the result like this when i switch on the circuit:

1-dc motors not running although the sensors function well.when i made the simple program to control the dc motors again without the sensor,the dc motors were functionally well.

i tried many ways but i still don't got the result that i wanted.i want to know how much bytes that pic can store the code? I'm afraid that the pic can't store the code too much bytes because the code that i made was too long.
nanslipknot86
Freshie
 
Posts: 7
Joined: Sat Oct 17, 2009 3:40 pm

Re: need help to combine the programming

Postby nanslipknot86 » Sun Oct 18, 2009 7:08 pm

one more question,if i use the PIC4550 but in the microcode i select the type of the pic which not same with my pic,for example in the microcode i select the PIC16f877 but i use PIC18F4550,and i compile the program which is the hex not in the pic18f4550 type ,is that the factor my program doesn't work with my circuit?
nanslipknot86
Freshie
 
Posts: 7
Joined: Sat Oct 17, 2009 3:40 pm

Re: need help to combine the programming

Postby robosang » Sun Oct 18, 2009 7:35 pm

nanslipknot86 WROTE:one more question,if i use the PIC4550 but in the microcode i select the type of the pic which not same with my pic,for example in the microcode i select the PIC16f877 but i use PIC18F4550,and i compile the program which is the hex not in the pic18f4550 type ,is that the factor my program doesn't work with my circuit?


Definitely cannot work if you choose the wrong device during compilation. If you choose wrong model in same family (such as PIC18F) it might work, but if you choose model between different family (such as PIC16F and PIC18F), I am confident to say, the code will not work in your circuit.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: need help to combine the programming

Postby nanslipknot86 » Sun Oct 18, 2009 7:49 pm

so i select the incorrect device in microcode right.i think my code are quite right because i check the flow and the code flow exactly what i want.thanks anyway for helping me
nanslipknot86
Freshie
 
Posts: 7
Joined: Sat Oct 17, 2009 3:40 pm

Re: need help to combine the programming

Postby ober » Mon Oct 19, 2009 11:20 am

nanslipknot86 WROTE:so i select the incorrect device in microcode right.i think my code are quite right because i check the flow and the code flow exactly what i want.thanks anyway for helping me


I din really check the code because I am not familiar with the compiler, it should be BASIC, right? Anyway, robosang is correct. If you choose the wrong PIC model during compile it end up wrong hex code although your program logic or flow is correct and there is no syntax error. You might still be able to load the code to PIC, but it will not run.

Anyway, good luck. Doing embedded project is not easy especially when it come to troubleshooting and fixing bugs, a tiny mistake may take weeks to solve it. Keep on the hard work.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 26 guests