Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Plotclock

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Wed Feb 10, 2021 7:56 am    Post subject: Plotclock Reply with quote

A clock released by "Johannes Heberlein" in 2014 that writes the time on a whiteboard with a servo motor.
The program that controls the servo motor by calculating trigonometric functions is wonderful, and you can enjoy comical movements.
The original is a sketch of "Arduino", but I ported it to the BASIC language of BASCOM-AVR.
Since the servo connection can be changed to any port, it works on boards other than "Arduino".
It then plots against the [_hour] and [_min] variables, so you can connect an RTC and extend it with the BASCOM Date and Time instruction.

Video
https://youtu.be/3tXPJm8LnaI

Circuit diagram
https://drive.google.com/file/d/1BdboEpRqcnNcNywHRm3l0ulyqTghL6Xj/view

Production site
http://www.ne.jp/asahi/shared/o-family/ElecRoom/DigClock/Plotclock/Plotclock.html
English translation
http://translate.google.com/translate?hl=ja&sl=ja&tl=en&u=http%3A%2F%2Fwww.ne.jp%2Fasahi%2Fshared%2Fo-family%2FElecRoom%2FDigClock%2FPlotclock%2FPlotclock.html

Original site
https://www.thingiverse.com/thing:248009
https://wiki.fablab-nuernberg.de/w/Ding:Plotclock
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Feb 10, 2021 11:17 am    Post subject: Reply with quote

you have done a remarkable job, bravo!

and the programme is very well documented and explained.
I would be a teacher, I would give you 20/20.
it is an excellent exercise to understand trigonometry

Jp Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Wed Feb 10, 2021 11:36 am    Post subject: Reply with quote

O-Family

Great job indeed. A very original idea from Johannes. Thank you for porting this and making the video.
Very good that you supply all the links. A great winter project Very Happy


one remark : when using CBI Servo_left_port,servo_left_bit you can also use RESET instruction since it should make the same code.
the compiler always tries to use the best instruction which is cbi/sbi for ports with a low port address. when not possible it will use IN or LDS with r23.

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Thu Feb 11, 2021 12:40 am    Post subject: Reply with quote

Hello.
Thank you for your feedback and advice.

Originally, it is ideal to use the hardware PWM output of Timer, but I wanted to be able to select the control pin of the servo motor to any port, so I made a PWM signal with software by interrupt.
This is to give flexibility in port placement when connecting RTCs and LCDs in the future.
Therefore, the accuracy of the PWM signals of the two arms is important, and interrupt processing must be completed in a short time.

When using the BASIC RESET instruction, it takes time to push many registers on the stack.
I wrote it in assembler with the interrupt's [Nosave] option enabled so that it doesn't save registers.

In addition, the [CBI] instruction is used to avoid saving the flag register. (The [CBI] instruction does not affect the flag register either)
Also, if the [LDS] instruction uses R23, it is necessary to save the R23 register, so [$notransform On] prohibits it.
These are some ideas for minimizing the interrupt processing time!
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 11, 2021 10:17 am    Post subject: Reply with quote

O-Family wrote:
Hello.
Thank you for your feedback and advice.

Originally, it is ideal to use the hardware PWM output of Timer, but I wanted to be able to select the control pin of the servo motor to any port, so I made a PWM signal with software by interrupt.
This is to give flexibility in port placement when connecting RTCs and LCDs in the future.
Therefore, the accuracy of the PWM signals of the two arms is important, and interrupt processing must be completed in a short time.

When using the BASIC RESET instruction, it takes time to push many registers on the stack.
I wrote it in assembler with the interrupt's [Nosave] option enabled so that it doesn't save registers.

In addition, the [CBI] instruction is used to avoid saving the flag register. (The [CBI] instruction does not affect the flag register either)
Also, if the [LDS] instruction uses R23, it is necessary to save the R23 register, so [$notransform On] prohibits it.
These are some ideas for minimizing the interrupt processing time!


that is not as it works.
there are 2 different things.
first the NOSAVE to avoid saving regs. yes you can do that and either not use registers or save the ones you use.

and second : the $notransform will not transform asm code. this means that if you use code that will not work you get an error. that is all it does.
But RESET will be compiled into CBI.
When used on ports with higher IO it could become an IN/AND/OUT or LDS/AND/STS using R23.

As a test you can compile your code and then change this :

Code:
'$notransform On                                             'Do not let instructions that use R23 or R0 automatically modify.
'$asm

   '
   '  ********************************************************
   '  * Timer1 comparison match A interrupt handling routine *
   '  ********************************************************
   '
Tintoc1a:
  Reset Servo_left_port.servo_left_bit                      'Set the control signal of the left servo to [L] level.
  Return


   '
   '  ********************************************************
   '  * Timer1 comparison match B interrupt handling routine *
   '  ********************************************************
   '
Tintoc1b:
  Reset Servo_right_port.servo_right_bit                    'Set the control signal of the right servo to [L] level.
   Return

'$end Asm
'$notransform Off
 


and you will see that you get the exact same code.

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Thu Feb 11, 2021 11:18 am    Post subject: Reply with quote

Yes.
I have an AVR disassembler, so I am familiar with what assembler code the compiled code outputs.
With that in mind, I avoided the RESET instruction because the code written in the BASIC instruction is unknown how the code output in the future will change.

The reason I use [$notransform On] is that if I don't write it, the compiler will apparently not give an error and register R23 will be corrupted in the interrupt, so I've had a hard time debugging.
This R23 corruption is not found in the source code.
Particular attention should be paid to corruption of the R23, R0, and R1 registers when using the [Nosave] option.

In a standard AVR, the register of the I/O port is a lower address, so if you select an AVR that cannot use the CBI instruction and the compiler gives an error, push R23 and rewrite it to the STS instruction.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 11, 2021 1:34 pm    Post subject: Reply with quote

in the help you find that R23 is used when $notransform is off.
Anyway i understand what you mean. if you move the port to a different one, and/or different chip, and you do not use $notransform it might use R23.

_________________
Mark
Back to top
View user's profile Visit poster's website
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Feb 12, 2021 12:10 am    Post subject: Reply with quote

What a great project!

Thank you for sharing it!

JC
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum