thronborg,
You might find the code examples in post #374 helpful. This dates back to August 2010 when I was first incorporating a pot into my system.
Ken
Hello
Actually i have this code for display the value on a LCD. Now i want the value of 0 to be 1mS puls and 255 to be 2mS puls.
Se attached drawing.
Hope this helpCode:' Name : ServoTester.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' Target PIC : PIC16F690 or similar type compatible with LAB-X20 board ' Hardware : LAB-X20 Experimenter Board ' Oscillator : 4MHz external crystal ' Keywords : ADCIN, LCDOUT ' Description : PICBASIC PRO program to read pot and display on LCD. ' FUNKAR ROR EJ ' Define LCD pins Define LCD_DREG PORTC 'LCD data port Define LCD_DBIT 0 'LCD data starting bit 0 or 4 Define LCD_RSREG PORTC 'LCD register select port Define LCD_RSBIT 4 'LCD register select bit Define LCD_EREG PORTC 'LCD enable port Define LCD_EBIT 5 'LCD enable bit ' Allocate variables x Var Byte ANSEL = %00000100 ' Set PORTA.2 analog, rest digital ANSELH = %00000000 Pause 100 ' Wait for LCD to start mainloop: Adcin 2, x ' Read ADC value on AN2 (PORTA.2) Lcdout $fe, 1, "Pot1 = ", #x ' Send value to LCD Pause 50 ' Do it about 10 times a second Goto mainloop ' Do it forever End[/I][/I]
Thronborg
Servo Tester.pdf
Last edited by ScaleRobotics; - 12th March 2011 at 16:53.
Ken, take a look at this Electronics with Micro-controllers
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
Thank's, now i start to understand a little bit more. Its running fine but i got the feeling that i had to much code.
Actually i dont know why i had the ANSEL, ANSELH and ADCON, it seems to work without them. Any ideas?
'************************************************* ***************
'* Name : NimSer.BAS *
'* Date : 3/3/2011 *
'* Notes : Move Servo 1 to 2mS depend on POT value *
'* Show valu in mS on LCD display *
'* For standard servo settings 1-2mS set LOW_servo con 100 *
'* and HIGH_servo CON 200 *
'************************************************* ***************
'Define OSC and ADC
DEFINE OSC 4 ' Set internal Oschillator to 4Mhz
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 2 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
' Define LCD pins
Define LCD_DREG PORTC 'LCD data port
Define LCD_DBIT 0 'LCD data starting bit 0 or 4
Define LCD_RSREG PORTC 'LCD register select port
Define LCD_RSBIT 4 'LCD register select bit
Define LCD_EREG PORTC 'LCD enable port
Define LCD_EBIT 5 'LCD enable bit
TRISA = %00001001 ' RA0 = A/D input
ADCON1.7 = 0 ' RA.1 = +Vref, Set PORTA analog and left justify result
PORTb.6 =0 ' Prepare RB0 for high-going pulseout
ANSEL = %00000100 ' Set PORTA.2 analog, rest digital
ANSELH = %00000000
' Variables
outpuls VAR WORD ' Variable for the calculated puls out in mS
POT_POS VAR BYTE ' Pot position CC=0, CCW=255
LOW_servo con 60 ' Min Servo pulse 60= 0.6mS 100=1mS
HIGH_servo CON 200 ' Max Span from LOW_servo to HIGH_servo
' Span 100 gives 100+100 = 200=2mS
Pause 500 ' Wait for LCD to start
MainLoop: ' The Loop start here!
ADCIN 0,POT_POS ' Read A/D channel 0 to variable SVO_POS
outpuls =LOW_servo + (POT_POS *HIGH_servo/255) 'Calculate the outpuls in mS
Lcdout $fe, 1, "POT_POS= ", #POT_POS ' Display POT Valu between 0-255 on line 1
LCDOut $fe,$C0, "Puls= ",DEC (outpuls/100),".", DEC2 outpuls,"mS"' Display pulswith in mS on line 2
PULSOUT portb.6 ,outpuls ' Move servo on pin
PAUSE 20 ' Constant 20mS pulses(low) between outpuls
GOTO MainLoop ' Forever
End
![]()
Last edited by thronborg; - 15th March 2011 at 02:02.
Hello, I am back with a robocar - PBP question. I wish I had the will power to really study this.
My robocars use HPWM to control the steering and to drive the Electronic Speed Control => DC motor for the wheels. I am trying to calibrate this command given different little cars.
Before the "main:" label I placed some code to make the wheels turn and steer. I discovered that HPWM rides through the PAUSE command sometimes and not other times. It depends on what code precedes the HPWM commands. Immediately below is a case that works. Below that is a case that does not. By not work, I mean the wheels just do not move.The only difference is the presence of the WHILE loop at the beginning.
The WHILE loop at the front checks the power status of the radio transmitter. If channel3 (PORTC.4) is pulsing the radio is receiving a signal from its transmitter. This works. It gives me an opportunity to put the car down on the floor.
What'z up here with HPWM and PAUSE???
-----THIS WORKS: Turn OFF the transmitter and the wheels move---------------
switchtoPIC = 2
WHILE switchtoPIC >= 2
COUNT channel3,65,switchtoPIC
HIGH portc.0
WEND
HPWM 1, Left, 50
HPWM 2, Forward, 50
pause 1000
HPWM 1, HalfLeft, 50
HPWM 2, HalfForward, 50
pause 1000
HPWM 1, Straight, 50
HPWM 2, brake, 50
pause 1000
main:
------THIS DOES NOT WORK. THE WHEELS DO NOT MOVE until main: ----------
HPWM 1, Left, 50
HPWM 2, Forward, 50
pause 1000
HPWM 1, HalfLeft, 50
HPWM 2, HalfForward, 50
pause 1000
HPWM 1, Straight, 50
HPWM 2, brake, 50
pause 1000
main:
Would it help if I were to show you the assembly language code for the above two compilations?
Ken
Bookmarks