Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Programming Orangutan Robot Controllers with Bascom


#1

Hello,

cause i am familar with Basic and not able to programm in C / C++, i would like to use Bascom.

Now my question:

How do i use the Lcd-display, the auxiliary processor, the UARTs and the Motorcontrollers from
the Orangutan SVP with Bascom ?

Regards

Plums


Bascom and Orangutan SVP-324
#2

Is there way to call external libraries from BASCOM-AVR, even if they were compiled from C with another tool like avr-gcc? That would probably be the best thing for you because then you could call our Pololu AVR Libraries from BASCOM-AVR and you wouldn’t have to rewrite them in basic.

If there isn’t a way to call external libraries, then I’m afraid you’ll have to read the source of our libraries and rewrite the parts that you need in Basic. Reading the source code will require you to learn some C and C++, though.

Note that it’s also possible that the default libraries that power BASCOM-AVR will conflict with our libraries. For example, our library uses Timer 2 to run the motors and keep time so if BASCOM-AVR happens to also use Timer 2 then you could have problems (I don’t know if BASCOM-AVR uses any timers).

–David


#3

Hi David,

thank you for your hinds.
I don’t know wether there is a way to call external libraries from BASCOM-AVR, but i believe no.

After a friend had a look to the C-code, he told me what to do.
I only had to learn how to handle the Timer2 with PWM with BASCOM.
After a search in the www , an Update to BASCOM-AVR Ver.2.0.2.1 and study the chematics i found
a easy way. :mrgreen:

The sample works fine and shows how to use BASCOM on the Orangutan Controller.

The only thing ,i don’t know until yet, is: which port drives the Servo-Multiplexer?

Here the Bascom-Code which i have tested.

Regards Uwe

-----------------------------------------------------------------------------------------------
' BASCOM-AVR  Ver.2.0.2.1

' Uwe Fricke
' [uw.fricke@web.de](mailto:uw.fricke@web.de)

 ' -----------------------------------

      'LCD-Display & Hardware PWM mit Timer2
      ' mit Pololu Orangutan SVP


$regfile = "m1284Pdef.dat"
$crystal = 20000000


Dim N As Integer
Dim Anzeige2 As String * 16


'------------------------------------------------------------------------------------------------

'Rs = PortB.0
'RW = PortB.1        R/W option wird hier nicht benötigt
' E = PortB.2

'Db0, Db1, Db2 und Db3 sind auf Masse    ; auf Masse

'Db4 = PortC.2
'Db5 = PortC.3
'Db6 = PortC.4
'Db7 = PortC.5
                     '----------------------------------------------------------
                     ' LCD-Anzeige vorbereiten Daten- und Steueranschlüße definieren

Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.2 , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4

                     '----------------------------------------------------------

     '---------Zusätzlich neue Zeichen definieren---define new own characters ----------

'   Deflcdchar 1 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16     ' |
'   Deflcdchar 2 , 24 , 24 , 24 , 24 , 24 , 24 , 24 , 24     ' ||
'   Deflcdchar 3 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28     ' |||
'   Deflcdchar 4 , 30 , 30 , 30 , 30 , 30 , 30 , 30 , 30     ' ||||
'   Deflcdchar 5 , 31 , 31 , 31 , 31 , 31 , 31 , 31 , 31     ' |||||

Deflcdchar 1 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 31        '
Deflcdchar 2 , 32 , 32 , 32 , 32 , 32 , 32 , 31 , 31        '
Deflcdchar 3 , 32 , 32 , 32 , 32 , 32 , 31 , 31 , 31        '
Deflcdchar 4 , 32 , 32 , 32 , 32 , 31 , 31 , 31 , 31        '
Deflcdchar 5 , 32 , 32 , 32 , 31 , 31 , 31 , 31 , 31        '
Deflcdchar 6 , 32 , 32 , 31 , 31 , 31 , 31 , 31 , 31        '
Deflcdchar 7 , 32 , 31 , 31 , 31 , 31 , 31 , 31 , 31        '


    '----------------- Now use an internal routine ------------

_temp1 = 1                                                  'value into ACC

!rCall _write_lcd                                           'put it on LCD

Cursor Off , Noblink
'------------------------------------------------------------------------------------------------

Config Portc.6 = Output
Config Portc.7 = Output

Config Portd.6 = Output
Config Portd.7 = Output

'Config Timer2 = Pwm , Pwm = On , Compare A = Clear , Prescale = 8
Config Timer2 = Pwm , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 8

Ocr2a = 255                                                 ' Pwm-Output OC2A = 0  Minimum  /  255 => Maximum
Ocr2b = 255                                                 ' Pwm-Output OC2B = 0  Minimum  /  255 => Maximum

Portc.6 = 0                                                 ' rotating direction   Dir2
Portc.7 = 1                                                 ' rotating direction   Dir1

Enable Timer2

'LCD-Display ------------------------------------------------------------------------------------

Locate 1 , 1
Lcd " BASCOM-Test"

Locate 2 , 1
Lcd Chr(1) ; Chr(1) ; Chr(2) ; Chr(3) ; Chr(4) ; Chr(5) ; Chr(6) ; Chr(7) ; Chr(7) ; Chr(6) ; Chr(5) ; Chr(4) ; Chr(3) ; Chr(2) ; Chr(1) ; Chr(1)

Wait 2

Locate 2 , 1
Lcd "LCD / PWM-Timer2"

Wait 2

Locate 2 , 1
Lcd " AVR ATmega 1248P"

Wait 2

Locate 2 , 1
Lcd "                "

Wait 1

Locate 2 , 1
Lcd " OCR2A : "

' PWM -------------------------------------------------------------------------------------------

Do

Portc.7 = 0                                                 ' Drehrichtung festlegen / set direction

'------------------------------------------------------------------------------------------------
For N = 255 To 0 Step -1                                    ' Drehzahl von 0 > Max erhöhen
                                                             ' inc. rotatation speed
  Ocr2a = N
  Waitms 50
  Locate 2 , 10
  Anzeige2 = Str(ocr2a)
  Anzeige2 = Format(anzeige2 , "000")
  Locate 2 , 10
  Lcd Anzeige2

Next N
'------------------------------------------------------------------------------------------------

Portc.7 = 1                                                 ' Drehrichtung ändern / change direction
Wait 2

'------------------------------------------------------------------------------------------------
For N = 0 To 255                                            ' Drehzahl von Max > 0 senken
                                                             ' dec.. rotatation speed
  Ocr2a = N
  Waitms 50
  Anzeige2 = Str(ocr2a)
  Anzeige2 = Format(anzeige2 , "000")
  Locate 2 , 10
  Lcd Anzeige2

Next N
'------------------------------------------------------------------------------------------------
Wait 2


Ocr2b = 0                                                   ' Pwm-Output OC2B = MAX / LED on

For N = 1 To 20                                             ' Blinking with D5 and D6
  Portc.6 = 0
  Waitms 250
  Portc.6 = 1                                               ' Drehrichtung ändern / change direction OC2B
  Waitms 250
Next N

Ocr2b = 255                                                 ' Pwm-Output OC2B = Min / LED off

Loop
'------------------------------------------------------------------------------------------------
End

#4

That’s great that you got the motors and LCD working!

The signal input of the servo demultiplexer is hardwired to PD5, but the output selection pins (SA, SB, and SC) are not connected to anything. If you need to control more than one servo, you will have to connect some of those pins to some free IO lines of your choosing, using a wire.

For more info, see the “Servo Demultiplexer” section on this page:
pololu.com/docs/0J39/4

and read this page:
pololu.com/docs/0J20/6.k

–David


#5

Thank you, David,

now i got it. If you have to control some servos more, you save I/O-lines.

I don’t know how big the differenz is between soft- and hardware PWM.
Is the accuracy of hardware-PWM much more better?

If i would like to use the multiplexer with BASCOM, it would be a little complicated.
First i had to look after the programming the correct impuls, and second,
i had to manage the multiplexer.
Much work, to save I/O-lines, but good to know that there is a way.

In BASCOM there are instructions to use sevos easely!

Config Servos = n , Servo1 = Portd.7 , Servo2 = Portb.1; …ServoN = Port… , Reload = 100 , Interval = 100
Servo(1) = xxx
Servo(2) = yyy
Servo(n)= zzz
Enable Interrupts

So, if i have enough I/O-lines and don’t need the accuracy of hardware-PWM , it would be easyer to use
the internal instruction of Bascom.

Thank you for your help and hints.
I wish you a merry christmas and a happy new year
Best Regards

Uwe