View previous topic :: View next topic |
Author |
Message |
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Feb 10, 2021 11:17 am Post subject: |
|
|
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 _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Feb 10, 2021 11:36 am Post subject: |
|
|
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
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 |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Thu Feb 11, 2021 12:40 am Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Feb 11, 2021 10:17 am Post subject: |
|
|
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 |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Thu Feb 11, 2021 11:18 am Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Feb 11, 2021 1:34 pm Post subject: |
|
|
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 |
|
|
JC
Joined: 15 Dec 2007 Posts: 584 Location: Cleveland, OH
|
Posted: Fri Feb 12, 2021 12:10 am Post subject: |
|
|
What a great project!
Thank you for sharing it!
JC |
|
Back to top |
|
|
|