16 channel serial servo controller for robotic applications

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,
This's a asembly code to built a SSC(Serial servo contorller), probably a stupid question,as i don't understand how it work.

http://www.seattlerobotics.org/e...

VB controller

schematic

I had tried,but just only adjust 0 to 126 ,and 127 to 255 can't apply accuracy pulses.

Now, hope to solved the problem,

I tested for the assembly code on an AT90S8515 at 3.6864 MHz. The code was compiled with AVR Studio 4.12 SP3.

Run the Visual Basic program (EXE file) and move the Scroll Bar I get this pulse width:

Beginning,Pulse width = 2285 μs (2.285 ms) ,It's OK.

Press the cnter button(value 127): Pulse width = 1595 μs (1.595 ms),It's OK.
but move button down to value 128 and down to value 254,the Pulse width = 0.905 ms and no change.

Press the cnter button(value 127): Pulse width = 1595 μs (1.595 ms),
Move button up to value 126 and up to value 0, It worked fine .

The problem is why I moved button down to value 128 and down to value 254,the Pulse width = 0.905 ms and no change.

Hope somebody tried successful and help me to use the applications.

Thanks a lot.

Best regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My first response was that you're losing the high order bit in the serial communication, but that would cause the values 129 to 255 to act like the values 1 to 127, which they don't.

My second response is, did you cut and paste the source code into AVR Studio or type it in? That is, have you modified it (intentionally or otherwise)?

I will make the naive assumption that the Seattle Robotics Society has posted a working project. I also assume (again, naively) that your hardware, given its simplicity and your inspection, is correct.

If you would like someone else to have a look at your code, send me the source code (your AVR Studio file) via PM and I'll have a look at it.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The problem is why I moved button down to value 128 and down to value 254,the Pulse width = 0.905 ms and no change.

What doesn't change, the servo position? Or are you saying any value on the GUI from 128 to 254 produces a .905ms pulse?

Did you change .include "4414def.inc" to .include "8515def.inc" ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to make a 'remote volume control' for my PA board... VB side looks like thie servo controller... 16 scroll bars... serial rs232 to the avr.... it controlls 16 digital pots jacked into the channel inserts on a mackie mixing board. Set the faders to 0 db on the hw board and mix from the audience using the sw board. I bet you could sell one of these to every church with a PA man that wants to sit in the audience and tweak the levels. Don't steal my idea now! If you want to help me build the prototype, I guess we can split the royalty somehow if we get it into production. The ad in Mix magazine would be 1000s of $$

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob, go the extra step and implement that software on a cell phone -- you know, dialing for decibels.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dksmall wrote:
Quote:
The problem is why I moved button down to value 128 and down to value 254,the Pulse width = 0.905 ms and no change.

What doesn't change, the servo position? Or are you saying any value on the GUI from 128 to 254 produces a .905ms pulse?

Did you change .include "4414def.inc" to .include "8515def.inc" ??

Hi,dksmall

Yes,I had change .include "4414def.inc" to .include "8515def.inc" ,and the 90S4414 had tried.

They are the same, moved button down to value 128 and down to value 254,the Pulse width changed to 0.905 ms and held at 0.905 ms .

I used oscilloscope to watch the pulse,not connect to the servo.

I had change the RS232 circuit,because the original RS232 ciruit tried failed. :wink:

Thank your reply :lol:

Best regards
ayu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,zbaird
Thank your reply,thank you.

Your first response as I am.
I download the http://www.seattlerobotics.org/e... Project's software files.

folder \16csscnt\MCU_SRC\16CSSCNT.ASM

and use the "16CSSCNT.ASM" change .include "4414def.inc" to .include "8515def.inc" and compiler with AVR Studio 4.12 SP3.

And the hardware was posted above.

Thank you,I'll send you the code.
aps file download http://homelf.kimo.com.tw/acmyuj...
asm file download http://homelf.kimo.com.tw/acmyuj...

Best regards.
ayu.

Last Edited: Mon. Dec 11, 2006 - 12:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ayu, I'm looking at your source code, the original, and the data sheets for the two processors. I have some questions:

Are you using the same crystal as specified in the original project? If the processor speed changes, it will affect this code severely.

Has your include file (8515def.inc) been accidentally modified? Check the timestamp to make sure it has not changed in the last few days.

Do all 16 servo outputs show the same behavior (0.905 ms pulses) when their slider value is 128 to 254?

Does setting one slider to >127 affect any of the other pulse widths (when all the others are <128)?

This is slightly strange code and could be much better, but it should work. I do not understand why you are seeing a longer pulse (2.285 ms) for a value of 0 than for 127 (1.545 ms). Each pulse starts at 0.9 ms and then the value lengthens it out to a maximum of 2.3 ms. Low values should mean shorter pulses. The Visual Basic program sends the value as displayed above the slider.

There do not seem to be any differences between the two processors that would matter to this application. My biggest suspicion at the moment is that the AVR is not receiving valid data, possibly because the baud rate constant is incorrect. Again, the program depends on instruction timing for proper functioning, so if the speed has changed nothing is going to work quite right.

Chuck

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

16 servo for this robot

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,zbaird
Thank your reply,
Yes,I used the same crystal as above hardware (Posted: Dec 08, 2006 - 01:44 PM ),
My include file (8515def.inc and 4414def.inc
http://homelf.kimo.com.tw/acmyuj...
http://homelf.kimo.com.tw/acmyuj... )
should be not changed.I posted the original file, C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes
Whether something wrong with the files?please help me,thanks.

What's the "timestamp" I don't know? Would you tell me the details ? :oops:

There are no affect with setting one slider to >127 affect any of the other pulse widths (when all the others are <128).

The first current into the applications ,every pwm pins are the 2.3 ms.(my oscilloscope is analog,not digital,so should had deviation)

As you say that value of 0 is 0.9 ms,and the value increase to 127 the Pulse width is to increase to 1.595 ms,but adjust 128 to 255 the pulse is suddenly changed and held to 0.9 ms.It's so strange? so I bother that.:cry:
The baud rate,hardware and software as you see,I hadn't changed.it's so strange? :cry:

Deeply appreciated your analysis. Thanks a lot.
ayu

Last Edited: Tue. Dec 12, 2006 - 05:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a3v2r wrote:
16 servo for this robot

Hi,a3v2r

It's the beginning of my interesting robot, http://www.hitecrcd.co.jp/ROBOT/... but this applications should only controll robot arm or others.

http://www.hitecrcd.co.jp/ROBOT/... It's show movie. :lol:

If connected to the robot,it seem only can controll basic movements.The KHR series robot is the other robot, http://www.kondo-robot.com/html/...

That's why I learn the cores to play and diy the same one someday,but it seem so far away to me.
:wink:
ayu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ayu,
Please try this program instead of the .exe you downloaded and see if it works.

The timestamp is the date and time a file is created. If one of your include files had a timestamp that was not a year or more old, there would be a good chance that file had been modified. Yours are fine.

Thanks,
Chuck

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,zbaird
That's wonderful,it's succeed by the program. :lol: :lol: :lol: Thank you so much and you're my hero.I'm so happy :P :P :P and thank you for everything.

Would you teach me to understand the code(VB and AVR)?
Can you show me the code? I don't know something wrong with the code?

Whether the software is wrong or others? Hardware is no change.So I think the software is wrong or not? :oops:

Thank you so much.
ayu

Last Edited: Tue. Dec 12, 2006 - 06:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi ayu,
I'm glad that fixed it. The problem was in the Visual Basic (VB) program, not the AVR program. It was a misuse of the serial communications control that sends the data to the AVR. When a number was larger than 127 it sent 0 instead. You may already have the program (it is a file with a .frm extension from that web site) although it may be confusing. I only changed a few lines.

All the program does is send 3 bytes each time a servo slider changes. The first byte has a value of 255 and acts as a marker that it is the first byte (synchronization byte). The second byte has a value of 0 to 15 and specifies the servo. The third byte is the value for the servo position, from 0 to 254. They do not use a position value of 255 because that would be confused with the first byte's special value.

That's all the PC program does.

The AVR program is a little more complicated, and while it is not terribly difficult, I don't think I would be able to work through it here. I would suggest searching in this forum and avrbeginners.net for an introduction to assembly language programming, and as you learn it work through the program. It should not be too difficult after you're familiar with the fundamentals.

Your hardware is fine. No changes.

Glad I could help. Good luck with the project.

Chuck

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,all
Hope a free AVR simulator to learn the code,which have the UART.

Thanks a lot.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
; *******************************************
; **                                       **
; **  16 Channel Serial Servo Controller   **
; **       For Robotic Applications        **
; **                                       **
; **    Microcontroller's Unit Software    **
; **                                       **
; **       Copyright (c) March 2000        **
; **          by George Vastianos          ** 
; **                                       **
; ******************************************* 

; *******************
; * Microcontroller *
; * characteristics *
; *******************

; MCU  = AT90S8515
; Fclk = 3.6864 MHz

.include "8515def.inc"

.cseg
.org	$0000			; * Reset handler
	rjmp	start		 
.org	$0009			; * UART RX Complete handler 
	rjmp	uart_rxc	
.org	$000d			; * Main program start
	
;******************************
;* Interrupt Service Routines *
;******************************

.def	sregb	=	r16
.def	stemp	=	r17

uart_rxc:
	in	sregb,	SREG	; * Store status register
	rjmp	rcvdchar	; * Start the task
uart_rxcf:
	out	SREG,	sregb	; * Restore status register
	ldi	stemp,	$90	; * Enable UART Receiver & RX Complete Interrupt
	out	UCR,	stemp
	reti			; * Return to main program

;**************************
;* UART Reception Routine *
;**************************

.def	rxchar	=	r18

rcvdchar:			; * Store the received character
	in	rxchar,	udr	
	cpi	rxchar,	$ff	; * Check if character is sync byte
	brne	rcvdchar1
	ldi	r30,	$60	; * If character is sync byte then
	ldi	r31,	$00	; * set Z register in the begin of packet area (in int. SRAM)
	rjmp	uart_rxcf
rcvdchar1:			; * If character is not sync byte then
	st	Z+,	rxchar	; * increase Z and store in int. SRAM the character
	cpi	r30,	$62	; * Check if packet finished
	brne	rcvdchar2
	ldi	r30,	$60
	rjmp	panalysis	; * If packet finished go to analyze it
rcvdchar2:
	rjmp	uart_rxcf	

;********************************
;* Data Packet Analysis Routine *
;********************************

.equ	baddr	=	0	; * Base address = 0 (in case of use up to 16 servos)

panalysis:
	lds	stemp,	$0060	; * Check if the base address of packet is the same
	andi	stemp,	$F0
	cpi	stemp,	baddr * 10
	brne	panalysis1	; * If its not the same then ignore the packet
	lds	stemp,	$0060	; * If its the same then update the servo position data
	andi	stemp,	$0F
	ldi	r28,	$80	
	ldi	r29,	$00	
	add	r28,	stemp
	lds	stemp,	$0061		
	st	Y,	stemp
panalysis1:
	rjmp	uart_rxcf	; * Analysis finished

;*************************************
;* End Of Interrupt Service Routines *
;*************************************

;****************
;* Main Program *
;****************

start:

;**************
;* Initiation *
;**************

.def	temp	=	r19

init:
	ldi	temp,	$01	; * Set Stack pointer to $015F of internal SRAM
	out	SPH,	temp		
	ldi	temp,	$5F
	out	SPL,	temp
	ldi	temp,	$17	; * Set UART on 9600 bps (for 115200 bps use $01)
	out	UBRR,	temp
	ldi	temp,	$90	; * Enable UART Receiver & RX Complete Interrupt
	out	UCR,	temp
	ldi	temp,	$00
	out	WDTCR,	temp	; * Watchdog Timer disable
	out    ACSR,	temp	; * Analog Comparator disable
	sts	$0060,	temp	; * Init pck byte 01 
	sts	$0061,	temp	; * Init pck byte 02 
	ldi	temp,	$fe
	sts	$0080,	temp	; * Init pos byte 01 
	sts	$0081,	temp	; * Init pos byte 02 
	sts	$0082,	temp	; * Init pos byte 03 
	sts	$0083,	temp	; * Init pos byte 04 
	sts	$0084,	temp	; * Init pos byte 05 
	sts	$0085,	temp	; * Init pos byte 06 
	sts	$0086,	temp	; * Init pos byte 07 
	sts	$0087,	temp	; * Init pos byte 08 
	sts	$0088,	temp	; * Init pos byte 09 
	sts	$0089,	temp	; * Init pos byte 10 
	sts	$008A,	temp	; * Init pos byte 11 
	sts	$008B,	temp	; * Init pos byte 12 
	sts	$008C,	temp	; * Init pos byte 13 
	sts	$008D,	temp	; * Init pos byte 14 
	sts	$008E,	temp	; * Init pos byte 15 
	sts	$008F,	temp	; * Init pos byte 16 
	ldi	temp,	$ff	; * Init all PWM outputs
	out	ddra,	temp
	out	ddrc,	temp
	ldi	temp,	$00	; * Reset all PWM outputs
	out	porta,	temp
	out	portc,	temp
	sei			; * Global interrupt enable

mainloop:

;************************
;* PWM Control Routines *
;************************

.equ	servo0	=	PA0	; * Set the output pin of Servo01
.equ	servo1	=	PA1	; * Set the output pin of Servo02
.equ	servo2	=	PA2	; * Set the output pin of Servo03
.equ	servo3	=	PA3	; * Set the output pin of Servo04
.equ	servo4	=	PA4	; * Set the output pin of Servo05
.equ	servo5	=	PA5	; * Set the output pin of Servo06
.equ	servo6	=	PA6	; * Set the output pin of Servo07
.equ	servo7	=	PA7	; * Set the output pin of Servo08
.equ	servo8	=	PC7	; * Set the output pin of Servo09
.equ	servo9	=	PC6	; * Set the output pin of Servo10
.equ	servoA	=	PC5	; * Set the output pin of Servo11
.equ	servoB	=	PC4	; * Set the output pin of Servo12
.equ	servoC	=	PC3	; * Set the output pin of Servo13
.equ	servoD	=	PC2	; * Set the output pin of Servo14
.equ	servoE	=	PC1	; * Set the output pin of Servo15
.equ	servoF	=	PC0	; * Set the output pin of Servo16

.def	tsoutA	=	r20	; * Temp servoA output pin register
.def	tsoutB	=	r21	; * Temp servoB output pin register
.def	tsposA	=	r22	; * Temp servoA position   register
.def	tsposB	=	r23	; * Temp servoB position   register

pwmmark:	
	ldi	tsoutA,	exp2(servo0)	; * Control Servo0 & Servo1
	ldi	tsoutB,	exp2(servo1)
	lds	tsposA,	$0080
	lds	tsposB,	$0081
	rcall	pwmA
	ldi	tsoutA,	exp2(servo2)	; * Control Servo2 & Servo3
	ldi	tsoutB,	exp2(servo3)
	lds	tsposA,	$0082
	lds	tsposB,	$0083
	rcall	pwmA
	ldi	tsoutA,	exp2(servo4)	; * Control Servo4 & Servo5
	ldi	tsoutB,	exp2(servo5)
	lds	tsposA,	$0084
	lds	tsposB,	$0085
	rcall	pwmA
	ldi	tsoutA,	exp2(servo6)	; * Control Servo6 & Servo7
	ldi	tsoutB,	exp2(servo7)
	lds	tsposA,	$0086
	lds	tsposB,	$0087
	rcall	pwmA
	ldi	tsoutA,	exp2(servo8)	; * Control Servo8 & Servo9
	ldi	tsoutB,	exp2(servo9)
	lds	tsposA,	$0088
	lds	tsposB,	$0089
	rcall	pwmB
	ldi	tsoutA,	exp2(servoA)	; * Control ServoA & ServoB
	ldi	tsoutB,	exp2(servoB)
	lds	tsposA,	$008A
	lds	tsposB,	$008B
	rcall	pwmB
	ldi	tsoutA,	exp2(servoC)	; * Control ServoC & ServoD
	ldi	tsoutB,	exp2(servoD)
	lds	tsposA,	$008C
	lds	tsposB,	$008D
	rcall	pwmB
	ldi	tsoutA,	exp2(servoE)	; * Control ServoE & ServoF
	ldi	tsoutB,	exp2(servoF)
	lds	tsposA,	$008E
	lds	tsposB,	$008F
	rcall	pwmB
	rjmp	mainloopend

;********************
;* PWM Mark Routine *
;********************

.def	count	=	r24

; * PWM routine for Servos 01-08 *

pwmA:
	in	temp,	porta	; * Set output pins of ServoA & Servo B
	or	temp,	tsoutA
	or	temp,	tsoutB
	out	porta,	temp
	rcall	delay		; * Wait for 900uS
	ldi	count,	$00	; * Start 1400uS delay
pwmA1:
	cp	count,	tsposA	; * Reset output pin of ServoA if positionA = count
	brne	pwmA2
	in	temp,	porta
	com	tsoutA	
	and 	temp,	tsoutA
	com	tsoutA	
	out	porta,	temp
pwmA2:
	cp	count,	tsposB	; * Reset output pin of ServoB if positionB = count
	brne	pwmA3
	in	temp,	porta
	com	tsoutB	
	and 	temp,	tsoutB
	com	tsoutB	
	out	porta,	temp
pwmA3:
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	inc	count
	cpi	count,	$ff	; * Check if delay completed
	brne	pwmA1
	ret			; * Stop 1400uS delay

; * PWM routine for Servos 09-16 *

pwmB:
	in	temp,	portc	; * Set output pins of ServoA & Servo B
	or	temp,	tsoutA
	or	temp,	tsoutB
	out	portc,	temp
	rcall	delay		; * Wait for 900uS
	ldi	count,	$00	; * Start 1400uS delay
pwmB1:
	cp	count,	tsposA	; * Reset output pin of ServoA if positionA = count
	brne	pwmB2
	in	temp,	portc
	com	tsoutA	
	and 	temp,	tsoutA
	com	tsoutA	
	out	portc,	temp
pwmB2:
	cp	count,	tsposB	; * Reset output pin of ServoB if positionB = count
	brne	pwmB3
	in	temp,	portc
	com	tsoutB	
	and 	temp,	tsoutB
	com	tsoutB	
	out	portc,	temp
pwmB3:
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	inc	count
	cpi	count,	$ff	; * Check if delay completed
	brne	pwmB1
	ret			; * Stop 1400uS delay

;*****************
;* Delay Routine *
;*****************

delay:
	ldi	temp,	$DD	; * Start of 900 uSec delay
delay1:
	nop
	nop	
	nop
	nop	
	nop
	nop
	nop	
	nop
	nop	
	nop
	nop	
	dec	temp
	cpi	temp,	$00
	brne	delay1	
	ret			; * End of 900 uSec delay

;*******************************
;* End Of PWM Control Routines *
;*******************************

mainloopend:
	rjmp	mainloop

;***********************
;* End Of Main Program *
;***********************
.

pwmmark:
ldi tsoutA, exp2(servo0) ; * Control Servo0 & Servo1
ldi tsoutB, exp2(servo1)

Had a code question

exp2(servo0) ,what mean ?

Load PA0 and PA1 into tsoutA or other meaning ?

Thanks.

Last Edited: Fri. Jan 12, 2007 - 10:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR Assembler User Guide:

Quote:
EXP2(expression) returns 2^expression

In this case it is used to make a bit mask from a bit number.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon wrote:
AVR Assembler User Guide:
Quote:
EXP2(expression) returns 2^expression

In this case it is used to make a bit mask from a bit number.

/Lars


Hi,Lajon

Was meaning
r20=PA1
r21=PA2 ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ldi tsoutA, exp2(servo0) ; * Control Servo0 & Servo1 
ldi tsoutB, exp2(servo1) 

tsoutA (r20) is loaded with the bit mask that controls servo 0 (when output on PORTA). This is exp2(PA0) = exp2(0) = 1. tsoutB (r21) is loaded with the mask for servo 1 (exp2(PA1) = exp2(1) = 2). In binary the servo masks look like this:

servo pin mask
0     PA0 00000001
1     PA1 00000010
2     PA2 00000100
3     PA3 00001000
4     PA4 00010000
5     PA5 00100000
6     PA6 01000000
7     PA7 10000000
pwmA: 
in temp, porta ; * Set output pins of ServoA & Servo B 
or temp, tsoutA 
or temp, tsoutB 
out porta, temp 

Here the masks for two servos are combined (using the bitwise or operation) and output on porta, this will start the pulse for both servos.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,again

So the output,
PA0=1
PA1=1

ie

ldi tsoutA, exp2(servo0) ; r20=00000001
ldi tsoutB, exp2(servo1) ; r21=00000010
rcall pwmA

and run to pwmA

pwmA:
in temp, porta ;
or temp, tsoutA ; temp=00000001
or temp, tsoutB ; temp=00000011
out porta, temp

Then porta=00000011,
isn't that?

Thank for your help,thank you.
If stupid answer,pls don't mind.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
Used eagle to create a board :P .

Attachment(s): 

Last Edited: Fri. Jan 12, 2007 - 11:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Add cap 0.01u from RESET to GND. I use 0.1u

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What about ISP programming ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a3v2r wrote:
Add cap 0.01u from RESET to GND. I use 0.1u What about ISP programming ?

Hi,a3v2r
I used the ISP programmer(Source from http://myweb.hinet.net/home17/ru...前言:) ,PonyProg,burn to chip on the breadboard,then put the chip into the target board.
Because the hardware worked fine on the breadboard in my original tested,so I didn't add the RESET part to schmatic. :wink:I hope it was a tiny board,so deleted power circuit and supplied external power. :)

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
In the code,I had trouble,How to use the r00-r15 ?It is so stupid question, :cry: but hope someone to help,Thanks a lot.
Best Regards.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
The code on the post Dec 20, 2006 - 09:40 PM https://www.avrfreaks.net/index.p...
I had study the code and have some questions need to help,thanks a lot.

Simulate 255,01,100 send to udr

In the * Interrupt Service Routines *

first udr = ff,the rxchar(=r18)=ff,

second udr=0x01,then rxchar(=r18)=0x01,and $0060=0x01.

third udr=0x64,then rxchar(=r18)=0x64,and $0061=0x64.and $0080=0x64

now interrupt end jump to mainloop:

pwmmark:
ldi tsoutA, exp2(servo0)
ldi tsoutB, exp2(servo1)
lds tsposA, $0080 ;$0080=0x64=tsposA=r22

and run to pwmA:

pwmA:
.
.
.
ldi count,$00

pwmA1:

cp count, tsposA ;
.
.
.
It is the same as no interrupt changed ?
The pwm was the same with first main program ?
The count(=r24)=$00 was no changed, so the pwm was the same with first?
That confused me ? :( Need somebody to help.Thanks a lot.
Best Regards.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sending 0xff, 0x01, 0x64 would update the $0081 location (for the second servo). In the pwm routine this would affect the tsposB register. The count itself is just incremented (it goes from 0 - 255). The tsposA and tsposB registers decide when the servo pulse must end for the first and 2:nd servo in each call of pwmA (and pwmB).

It would be easy to check this and the timing using simulation in AVR Studio and the stop watch (it is in the I/O view under "Processor"). First you would need to set your clock frequency (in the Debug menu, "AVR Simulator Options"). Then set breakpoints and measure the time:

pwmA: 
   in   temp,   porta   ; * Set output pins of ServoA & Servo B 
   or   temp,   tsoutA 
   or   temp,   tsoutB 
   out   porta,   temp ; <-- Time from here...
   rcall   delay      ; * Wait for 900uS 
   ldi   count,   $00   ; * Start 1400uS delay 
pwmA1: 
   cp   count,   tsposA   ; * Reset output pin of ServoA if positionA = count 
   brne   pwmA2 
   in   temp,   porta 
   com   tsoutA    
   and    temp,   tsoutA 
   com   tsoutA    
   out   porta,   temp ; <-- to here (1:st servo pulse time)
pwmA2: 
   cp   count,   tsposB   ; * Reset output pin of ServoB if positionB = count 
   brne   pwmA3 
   in   temp,   porta 
   com   tsoutB    
   and    temp,   tsoutB 
   com   tsoutB    
   out   porta,   temp ; <-- and to here (2:nd servo pulse time)

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
Thanks everybody what you helped.After studied the code,tried to increase PWM pins,up to 24 channel successfully :o .

And changed to AT89S51 chip(used assembly code),which worked fine,but AT89S51 chip only run 0.5uS(crystal=24MHz) a code,so the 255 resolution must changed as the same AVR program's architecture.

Thanks Chuck,/Lars...without your helped,can't tried so funny. :wink:

Best Regards,
ayu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Last Edited: Fri. Jan 26, 2007 - 12:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ayu da da hi

good!!

Attachment(s):