PBP projects for R/C models
Hi,
Following on from a suggestion on the main PBP forum, it is hoped to get people to post up code snippets for anything RC model related. I'll start the ball rolling by posting code that makes an LED pulse like a beacon and is controllable from a transmitter. - This was a result of my own bit of code and suggestions from guys on this forum on how to use pulsein command to detect the signal from the receiver.
Code:
'****************************************************************
'* Name : RC Input - 12F675 *
'* Author : *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'* Date : 27/10/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
' set up PIC config
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
__CONFIG
_INTRC_OSC_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
OPTION_REG = %10000000 ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
GPIO = %00000000 ' All outputs = 0 on boot
TRISIO = %00001000 ' GPIO.3 input, GPIO.0,2,3,4,5 output
ANSEL = 0 ' Set all digital
WPU = 0 ' Internal pull-ups = off
ADCON0 = 0 ' A/D off
;set varibles
signal VAR GPIO.3 'GPIO.3 is used to the receiver
pulse VAR BYTE 'pulse is used to store the result
led var GPIO.0 'GPIO.0 is the output we want to flash
i var byte 'i is used for the for next loop to generate width of pulses
getout var bit 'used to check switch routines
'-------------------------------------------------------------------------------
main:
PulsIn signal, 1, pulse ' reads signal from receiver
IF (pulse >= 100) AND (pulse <= 160) Then ' threshold for activation
Low GPIO.0 ' turns LED off
Else
goto flash 'if pulse is ouside range goto flash
EndIF
GoTo main ' do it all again
flash:
for i = 1 to 254 ' for next loop
Pwm GPIO.0,i,1 ' send pulse to GPIO.0 for lenght i increasing brightness
pause 1
if i=253 then ' test to see value of i
i=1 ' if test is true then set 1 to 1 and getout to 1
GetOut=1
if Getout=1 then goto down ' if getout is q then jump to down routine
endif
next i
down: ' same as flash but decreases brightness
for i = 254 to 1 step -1
Pwm GPIO.0,i,1
pause 1
if i=2 then ' test of value i, if i =1 then
i=1 ' set i to 1 and getout to 0
GetOut=0
if Getout=0 then goto main ' test value of getout - if 0 go to start of program
endif
next i
autonomous and RC hobby car
Please, if you are interested, take a look at the
"How do I give a radio control car autonomous control"
Thread. I have a PICkit 2 and PICbasic programming package.
Attached is a sketch of what i need to do. I think. Any suggestions would be greatly appreciated. The forum does not let me attach the same file twice.
http://www.picbasic.co.uk/forum/atta...1&d=1263008711
Ken Jones
Maybe I should change my design
Mr or Ms scalerobotics,
My original idea for an RC car that could toggle between RC control and autonomous control was to have DPDT relays switching between the RC receiver PWM outputs and the PIC PWM outputs. Please see:
http://www.ziplink.net/users/kjones/...color_copy.jpg
I discounted the idea of routing the RC commands through the PIC as that route might be slow and/or noisy. It sounds like that is exactly what you are designing. Please keep me in touch with your progress.
I think that design would force me to choose another PIC as it would require three inputs from the radio receiver and two outputs to the electronic speed control and the steering servo. -- all interrupt driven I would think.
I am sort of stuck with the PICkit 2 since I have purchased three of them. They are also not toooo big. If I could get more confidence prototyping I might consider building my own PIC carrier, but just getting the prototyping bits, parts and pieces entails an hour's drive to a store with which I am not familiar.
Ken
No BAUDCON in PIC16F8x series.
I searched all the .inc files in the microchip/MPASM suite directory for the string BAUDCON. I got many hits. None were from the PIC16F8xx set of microprocessors.
The hits mostly said "BAUDCON EQU h'019f'" in BANK 3.
There are no such entrees in the PIC16F8xx .inc files.
How do I find out what BAUDCON means in its context so that I can translate to my PICkit 2 context?
where are the ASM macros stored?
I got Darrel Taylor's blinky to work on my PICkit 2 16F887. I had to change the output pin to the LED to match the printed circuit on the 44 pin demo board.
Now I would like to get blinky to interrupt on the rising edge and the falling edge of a signal coming in CCP1 which is RC2.
Darrel Taylor's blinky contains this line
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
Where do I look for the definition of INT_ENABLE? I used SEARCH. I had no luck at all.
Ken
I agree with using interrupts to measure time
Scalerobotics.
I have not been successful getting the RC knowledgeable folks to come clean with the exact signal pulse width specs. The hobby RC folks at our local RC Excitement racetracks and store
http://www.rcexcitement.com/
say that neutral (braking) is 130ms. This makes sense if the max pulse size is 256ms (2 to the 8th for convenient digital counting). How often that pulse is expected I am not sure. I think I read that the shortest pulse is about 50ms and the longest about 200ms. But I have no idea where or how I got that impression.
It would be nice if I could implement a program on my PICkit such that my eyes could detect this variation by observing the glow of an LED.
I neither own an oscilloscope nor have easy access to one. I do have some contacts at the Fitchburg State College Computer Science Department. I could call them and take over my car for a definitive answer.
Enough talk. I'm supposed to be thinking and tinkering.
Ken
You are absolutely correct!
These RC Excitement guys just said 150 and 125 and 175. They never said the units. I just surmised milliseconds.
Last week you sent me two short programs. You also suggested that I go to Darrel Taylor's page and grab some code. I got his "blinky" to compile and work with the minor adjustments of changing the output to an LED register and the DT_INT-14.bas fix. I never got either of yours to compile and run.
On page 125 of your 18F2520 spec I found T0CON containing TMR0ON, T08BIT, T0CS, T0SE, PSA, T0PS2 AND T0PS1. I could not relate any of this to the contents of pages near 77 of my 16F887 spec. I also could not find in any code you posted where you set these bits.
Scalerobotics thought I might be able to measure the PWM radio receiver outputs if I converted it to a serial stream. Good idea, but I don't know what to do with a serial signal.
I would feel successful if I could see on a flashing LED that my radio receiver is working and that the PIC can read it. (I know it is working because the car wheels turn.) This is the intent of the first code (RC-Input - 12F675) Scalerobotics sent me. It originate with Malcolm from Hertfordshire, UK.
I'd like to get that working.
Time out. Gotta check the TV for results of the Massachusetts special US Senatorial election.
Ken
Looks like the PICkit Logic Tool is my answer
I have discovered the Analyzer Tool in the PICkit Tool Logic Tool package.
It looks like this tool will provide me a picture of the output of my radio receiver if I can get Scalerobotics' program to work. I have both MPLAB IDE and PICbasic PRO packages. They have some duplications. I have a book "PIC PROJECTS" which pontificates the advantages of MPLAB. I have an impressive PICkit Tool HELP menu.
My impression is that the PICkit package is what I should focus upon. Does that make sense?
Ken
I am completely lost.....
I succeeded in getting scalerobotics second code sample to compile.
This is the one that samples PWM incoming and puts it out the serial port. It created an .asm file that would not build. The list of errors is too large to publish here. (Besides that it does not word wrap well.)
I am completely missing something. I do not understand PICBASIC PRO.The multiple hundred page microchip DATA SHEETS blow my mind. I try to read a section (16F887 Page 74 on SOFTWARE PROGRAMMABLE PRESCALER) and I can not put it in context.
I am not sure where the basics are that I am meant to go back to. I have a couple of paperback books. Maybe I should read page by page.
Ken
I am getting confuseder and confuseder
The PICBASIC PRO compiler book that comes (for $250) with MIcroEngineering Labs product does not mention built in routines. I found a chapter in a MikroElektrnonika "Programming PIC MCUs in BASIC"on line book devoted to these. I assume they work with my system. True? I don't think so.....sigh
http://www.mikroe.com/en/books/picbasicbook/05.htm
The above book says,
-------start snip---------------
Prototype sub procedure EEprom_Write(dim Address as byte, dim Data as byte)
Description
Function writes byte to [Address]. [Address] is of byte type, which means it can address only 256 locations. For PIC18 MCU models with more EEPROM data locations, it is programmer's responsibility to set SFR EEADRH register appropriately.
All interrupts will be disabled during execution of EEPROM_Write routine (GIE bit of INTCON register will be cleared). Routine will set this bit on exit
Ensure minimum 20ms delay between successive use of routines EEPROM_Write and EEPROM_Read. Although EEPROM will write the correct value, EEPROM_Read might return undefined result.
Example
for i = 0 to 20
EEPROM_Write(i, i + 6)
next i
-------------------end snip----------------
I tried the following bit in my PBP compiler.
i VAR BYTE
for i = 0 to 20
EEPROM_Write (i, i + 6)
next i
It complained that the EEPROM line has a syntax error.
What am I just not grasping.....??? I assume the two BASIC packages differ. The question is where do I find the built in routines that come with MY PBP?
Ken
Success - the wheels go round
This PWM exercise is designed just for what I have done.
http://www.melabs.com/resources/samples/pbp/hardpwm.bas
After loading the .hex into the RC car (carrying my PICkit2), hooking up another battery and connecting CCP1 to the electronic speed control, The wheels spin!!
Ain't technology grande!
Ken