Jump to content
Sign in to follow this  
pdegior

PIC Failsafe Project

Recommended Posts

I am trying to program my own PIC to act as a failsafe in the event of a loss of signal. I wrote a quick test program but am having some difficulty. I am using a PIC16F628 with external 4MHz crystal. I can control a servo no problem using the pulsout command, but as soon as I introduce a pulsin command, the servo seems to pulse very slowly to position, and in between pulses I can turn the servo by hand to another position. I am not even doing anything with the pulsin data. Any suggestions would be appreciated....Here is the sample code.

define Osc 4

CMCON = 7

rec_sig var byte

b3 = 152

goto receiver_read

receiver_read:

pulsin 5,1,rec_sig

pulsout 3, 150

pause 18

goto receiver_read

end

Without the pulsin command the servo holds steady at the center position. With the pulsin line, the servo can be easily moved before it tries to come back.

Share this post


Link to post
Share on other sites

I'm definitely not an expert with pics or PBP. The only thing that comes to mind is that you’re not getting a pulse on the pulsin pin. Do you actually have the RC RX connected? If not then it is waiting until it times out before sending the pulsout. If the RX is connected double check that it is connected to the correct pin. Make sure you have a ground connection between the RX and your pic circuit.

Share this post


Link to post
Share on other sites

Do you mean that I should ground the signal wire going to my pulsin pin or my pulsout pin that goes to the servo?

I also found that there is a parameter you can set called PULSIN_MAX that limits the number of counts to look for a pulse. The default is 65535. At 4MHz that equates to roughly 16ms plus the time for me to generate my pulse out. I set the number much lower at it seems to be acting much better. Before I made these the changes I did check it with the receiver conntected and I still had the problem. Perhaps it is the ground issue. I will try with the receiver and see houw it goes.

Thanks

Share this post


Link to post
Share on other sites
Do you mean that I should ground the signal wire going to my pulsin pin or my pulsout pin that goes to the servo?

Whatever you do, Do NOT ground the pulsout pin.

I also found that there is a parameter you can set called PULSIN_MAX that limits the number of counts to look for a pulse. The default is 65535.

I'm not a PBP user. But, according to the online info, if the pulsin var is defined as 8-bits (as is yours), then the timeout occurs at count 255. That is only 2.5mS, which shouldn't be a problem for you at this point.

BTW, when using the pulsin statement, how much does the framerate slow down? If it is about 1.5Hz (650mS) then the pulsin thinks rec_sig is a 16-bit variable. Perhaps setting PULSIN_MAX to 255 would help out then.

Again, I am not a PBP user. So, keep that in mind.

Share this post


Link to post
Share on other sites

The framerate is exactly 1.5Hz. I counted the pulses and in 1 minute it pulsed 90 times.

You're right I did have it the var set to byte. I have since changed it back to word although it is probably not necessary since my longest pulse should only be around 2ms.

I changed my pulsin_max to 300 initially and now to 255 as you mentioned and there is significant improvement. The true test will be when I get a chance to hook up the receiver and see if I accurately use the pulses.

Edited by pdegior

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×