PIC Assembly Program Help

Thread Starter

ozirock

Joined Jan 13, 2011
47
Thanks for the MPLAB suggestion, it has helped a lot, I've now got the joysticks working well.

The code seem's to work exactly like I expect however the LED's are very dim. I don't think it's a wiring issue as when the program first starts the LED's are turned on and they come on at full brightness. It might be the way I'm setting the pins, I was using the following code which I've never tried before so maybe I haven't understood how it works correctly:

Rich (BB code):
movf    FB,W		;**** Set Full Beam ****
    		xorwf   On,W
    		btfsc   STATUS,Z
		bsf	PORTB,	0
		bcf	PORTB,	0
Could this be causing some sort of pulse modulation that's dimming the LEDs?
 

Markd77

Joined Sep 7, 2009
2,806
It will always get to the bcf line.
Actually I'm surprised it's on long enough to see.
You can skip a goto instruction to give the code two directions, although if you run into any unusual problems search for "read, modify, write" in the datasheet. Basically using instructions like bsf directly on the port isn't recommended but you can usually get away with it.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
I added the goto as follows and it worked perfectly, thanks!

Rich (BB code):
		movf    FB,W		;**** Set Full Beam ****
    		xorwf   On,W
    		btfss   STATUS,Z
		goto    $+3
		bsf	PORTB,	0
		goto    $+2
		bcf	PORTB,	0
I think just need to wire the motor to the board and I can test the PWM, fingers crossed that'll go ok.

I was wondering is it possible to send information between two pic's? for example can you set an output pin on one pic to D '20' somehow and have an input pin on another pic receive this value?
 

Markd77

Joined Sep 7, 2009
2,806
Have a look at the usart section of the datasheet for communication. It can be tricky to get working. You could also use a pulse duration method like the servos use. It could be easier to get a bigger / faster PIC.

How are you connecting the motor? Without the right protection circuitry it is easy to damage PICs with inductive loads.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47

Markd77

Joined Sep 7, 2009
2,806
Looks good. I'd forgotten to re-read the thread, and that you had already mentioned the motor controller.
This is going really smoothly for a first microcontroller project.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
Yes I was thinking that too, most I've ever done successfully is control a few LED's and that didn't take too much code. Seem's to be working out rather well!

The motor seem's to be struggling to get moving with the PWM, I think I'll get a few smaller motors during the weekend and see if they work better as I'd like to be able to control it at pretty slow speeds and I think this motor is just not made for that.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
Well I got a smaller motor and that seemed to work better with a test program that ramped up so that should be alright.

I then moved on to try controlling the servo and the simplest way I could think to do this was with an analogue switch chip. I'm using it kind of like half a H-bridge cause depending on whether pic set pin RB6 high or low the switch chip will either send the signal to the servo or to pin RA4.

If I connect an LED between RB6 and ground the LED lights and turns off when expected however when I connect my circuit once I switch the pin high it stays there. I wonder could the circuit be forcing the pin to remain high? Possibly there is some pic protection I'm missing.

I've uploaded the circuit here http://ozirock.webs.com/RC Cobra Wiring.pdf

Here's links to the bigger components if it helps:
SN754410 = Motor Controller
74HCT04N = Inverter Gate
74HCT4066N = Analogue Switch
 

Markd77

Joined Sep 7, 2009
2,806
Can't you just input the servo pulse into the PIC and then output it on another pin?
If you put code after your tests then the pulses will be at the same rate that the reciever is sending them.
A delay of 1ms followed by a loop should give you a variable delay of 1-2ms
This code doesen't work for count = 0 but apart from that it gives about 1ms if count =255 and hardly any time at all if count = 1
Rich (BB code):
t1
nop
decfsz count
goto t1
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
Of course, that is so much simpler I have a tendency to overcomplicate things! I've tried to change your code a bit to take advantage of the existing Servo_Delay and the code looks like this now:

Rich (BB code):
t1		bsf	PORTB,	6
		call	Servo_Delay
		decfsz 	count
		goto 	t1
		bcf	PORTB,	6
Where count is to be the length of the measured pulse. Just to check, nop means no operation right? and you put it in as an example?
 

Markd77

Joined Sep 7, 2009
2,806
Yes, nop means no operation. It is for timing purposes so that 250 times through the loop takes 1ms on a 4MHz crystal. With your call instead it will take much less than 250 times through the loop to get to 1 ms, but that may be ok with your code if you don't put in the fixed 1ms delay I suggested last post.
In fact your code should pretty much duplicate the original pulse.
You might notice that the servo doesen't move very smoothly because the number of steps between the endpoints isn't very high. If it's a problem then it might be possible to make a few alterations.
 

Markd77

Joined Sep 7, 2009
2,806
I think servos can draw a pretty decent current. You could try with the servo powered from a separate supply to see if that is the problem (connect the grounds of both supplies).
One thing your schematic is missing that could help is a 100nF capacitor across the power supply pins of the PIC and physically as close as possible to it.
If not the problem could be in the code.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
Okay I'll try get those capacitors, they are to stop sudden fluctuation's in current correct?

@Markd77

Adding the second power supply helped, I had control over the motor and the servo jerked around a bit but those problem's seem more to do with my program at least. I'll have to make a small program to test the servo on it's own.

@blueroomelectronics

The voltage regulator? It's a UA78L05AILPE3. It seem's to work okay, do you think it might be causing the resetting somehow? What would you suggest instead?
 

Markd77

Joined Sep 7, 2009
2,806
The capacitors help to keep the voltages stable when current demand changes.
If you post the code I (or someone else) will have a look to see if we can find anything obvious.
That voltage regulator is recommended for a power supply of 7V or more. If the supply is only 6V then any change on the supply will be passed on to the regulated circuit.
Something like the LE50CZ will work with a minimum 5.2V or if you want a bit more headroom for when the batteries drain a bit (and if the components are OK with it) you could get a 4.5V or 4V low dropout regulator.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
First of all sorry for the delay, assignment's are starting up again.

I think you wanted to see the entire code but I didn't want to fill the forum with it so I created a page on my site which shows the entire code and gives a link to download the .asm file if you like. This page is here. If anyone would prefer me to post the code in it's entirety here let me know.

I've had a look at some voltage regulators and this one in my inexpert view appears to be very good as it has a min voltage of 0.3v. Would this work?

And here is the diagram with the two extra capacitors.

Is there anything else you could suggest I should get? Just so I can get it all with one order.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
I had been using a UA78L05AILPE3 but the guy's pointed out it has a min supply voltage of 7v. I had chosen it that way to try and protect the pic from too high current, is that a mistake do you think?
 
Top