HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Jan 15, 2010, 07:07 AM
Registered User
United Kingdom, Bristol
Joined Aug 2008
1,774 Posts
Help!
Walkera Q pwm > ppm & Q pwm>B pwm (broke)

Hi

I have had this code awhile now and i can't make it work. So rather than just delete i'll post it in vane chance someone can complete or fix it. But share code once completed.

Problem is duty cycle its reading half and outputs 100% power @ half stick.

Code:
; 4#3Q PWM output convert to 500Hz ESC PPM
; dual channel, 6ms update
; with LED

.include "tn85def.inc"

.def temp = r16
.def count = r17
.def mainDutyTemp = r18
.def tailDutyTemp = r19
.def mainDutyL = r20
.def mainDutyH = r21
.def tailDutyL = r22
.def tailDutyH = r23
.def temp2=r24
.def count2 = r25

.equ mainIn = 2 ; PB2 = pin 7
.equ tailIn = 3 ; PB3 = pin 2
.equ mainPwm = OCR1A
.equ tailPwm = OCR1B
.equ mainOut = 1 ; OC1A = PB1 = pin 6
.equ tailOut = 4 ; OC1B = PB4 = pin 3
.equ LEDpin = 0

.MACRO read_pwm
sbis PINB, tailIn
inc tailDutyTemp
sbis PINB, tailIn
inc tailDutyTemp
sbis PINB, mainIn
inc mainDutyTemp
.ENDMACRO
.MACRO read_pwm5
read_pwm
read_pwm
read_pwm
read_pwm
read_pwm
.ENDMACRO
.MACRO read_pwm25
read_pwm5
read_pwm5
read_pwm5
read_pwm5
read_pwm5
.ENDMACRO
.MACRO read_pwm125
read_pwm25
read_pwm25
read_pwm25
read_pwm25
read_pwm25
.ENDMACRO

.org 0x0000
rjmp main
nop ; INT0
nop ; PCINT0
nop ; T1_COMPA
nop ; T1_OVF
nop ; T0_OVF
nop ; EE_RDY
nop ; ANA_COMP
nop ; ADC
nop ; T1_COMPB
nop ; T0_COMPA
nop ; T0_COMPB
nop ; WDT
nop ; USI_START
nop ; USI_OVF

main:
; set up stack
ldi temp, low(RAMEND)
out SPL, temp
ldi temp, high(RAMEND)
out SPH, temp

; set up T1 for 2kHz nominal PWM
; internal clock 64 prescaler, PWM1A, OC1A clear on match
ldi temp, 0x7 | (1<<PWM1A) | 0x20
out TCCR1, temp
; PWM1B, OC1B clear on match
ldi temp, (1<<PWM1B) | 0x20
out GTCCR, temp
; turn off output
ldi temp, 0
out tailPwm, temp
out mainPwm, temp

; set up PORTB - output for main, tail, LED
sbi DDRB, mainOut
sbi DDRB, tailOut
sbi DDRB, LEDpin
; pull up for main, tail
sbi PORTB, mainIn
sbi PORTB, tailIn

main_loop:
sbi PORTB, LEDpin
ldi count2, 8
rcall delay_loop
cbi PORTB, LEDpin
ldi count2, 16
rcall delay_loop
sbi PORTB, LEDpin
ldi count2, 8
rcall delay_loop
cbi PORTB, LEDpin
ldi count2, 100
rcall delay_loop
sbi PORTB, LEDpin
ldi count2, 8
rcall delay_loop
cbi PORTB, LEDpin
ldi count2, 16
rcall delay_loop
sbi PORTB, LEDpin
ldi count2, 8
rcall delay_loop
cbi PORTB, LEDpin
ldi count2, 250
rcall delay_loop
ldi count2, 100
rcall delay_loop
rjmp main_loop

delay_loop:
rcall get_duty
dec count2
brne delay_loop
ret

get_duty:
clr temp
clr mainDutyL
clr mainDutyH
clr tailDutyL
clr tailDutyH

ldi count, 1
rcall duty_loop
;reset ppm PWM
clr temp2
out mainPwm, temp2
out tailPwm, temp2

ldi count, 63
rcall duty_loop

set_duty:
; clear prescalar
in temp, GTCCR
sbr temp, (1<<PSR1)
out GTCCR, temp
; set counter to OCR1C-1
ldi temp, 0xFE
out TCNT1, temp

; set main pwm
/*; for Flea?
lsl mainDutyL
rol mainDutyH
lsl mainDutyL
rol mainDutyH
*/
; for AEO
mov temp2, mainDutyH
lsl mainDutyL
rol mainDutyH
add maindutyH, temp2
subi mainDutyH, -125

out mainPwm, mainDutyH

; set tail pwm
lsl tailDutyL
rol tailDutyH
subi tailDutyH, -125
out tailPwm, tailDutyH
ret

duty_loop:
clr mainDutyTemp
clr tailDutyTemp
read_pwm125
add mainDutyL, mainDutyTemp
adc mainDutyH, temp
add tailDutyL, tailDutyTemp
adc tailDutyH, temp
dec count
breq end_duty_loop
rjmp duty_loop
end_duty_loop:
ret

**********************************************


Code:
; 4#3Q PWM output convert to 2kHZ 4#3B PWM
; dual channel, 8ms update both channels

.include "tn85def.inc"

.def temp = r16
.def count = r17
.def mainDutyTemp = r18
.def tailDutyTemp = r19
.def mainDutyL = r20
.def mainDutyH = r21
.def tailDutyL = r22
.def tailDutyH = r23

.equ mainIn = 2 ; PB2 = pin 7
.equ tailIn = 3 ; PB3 = pin 2
.equ mainPwm = OCR1A
.equ tailPwm = OCR1B
.equ mainOut = 1 ; OC1A = PB1 = pin 6
.equ tailOut = 4 ; OC1B = PB4 = pin 3

.MACRO read_pwm
sbis PINB, tailIn
inc tailDutyTemp
sbis PINB, mainIn
inc mainDutyTemp
.ENDMACRO
.MACRO read_pwm5
read_pwm
read_pwm
read_pwm
read_pwm
read_pwm
.ENDMACRO
.MACRO read_pwm25
read_pwm5
read_pwm5
read_pwm5
read_pwm5
read_pwm5
.ENDMACRO
.MACRO read_pwm125
read_pwm25
read_pwm25
read_pwm25
read_pwm25
read_pwm25
.ENDMACRO

.org 0x0000
rjmp main
nop ; INT0
nop ; PCINT0
nop ; T1_COMPA
nop ; T1_OVF
nop ; T0_OVF
nop ; EE_RDY
nop ; ANA_COMP
nop ; ADC
nop ; T1_COMPB
nop ; T0_COMPA
nop ; T0_COMPB
nop ; WDT
nop ; USI_START
nop ; USI_OVF

main:
; set up stack
ldi temp, low(RAMEND)
out SPL, temp
ldi temp, high(RAMEND)
out SPH, temp

; set up T1 for 2kHz nominal PWM
; internal clock 16 prescaler, PWM1A, OC1A set on match, CTC
ldi temp, 0x5 | (1<<PWM1A) | 0x30 | (1<<CTC1)
out TCCR1, temp
; PWM1B, OC1B set on match
ldi temp, (1<<PWM1B) | 0x30
out GTCCR, temp
; OCR1C 250 for 2kHz with 16 prescaler
ldi temp, 250
out OCR1C, temp
; turn off output
ldi temp, 0
out tailPwm, temp
out mainPwm, temp

; set up PORTB - output for main, tail
sbi DDRB, mainOut
sbi DDRB, tailOut
; pull up for main, tail
sbi PORTB, mainIn
sbi PORTB, tailIn

clr temp
get_duty:
ldi count, 64
clr mainDutyL
clr mainDutyH
clr tailDutyL
clr tailDutyH

duty_loop:
clr mainDutyTemp
clr tailDutyTemp
read_pwm125
read_pwm125
add mainDutyL, mainDutyTemp
adc mainDutyH, temp
add tailDutyL, tailDutyTemp
adc tailDutyH, temp
dec count
breq set_duty
rjmp duty_loop

set_duty:
; set main pwm
lsl mainDutyL
rol mainDutyH
lsl mainDutyL
rol mainDutyH
out mainPwm, mainDutyH
; set tail pwm
lsl tailDutyL
rol tailDutyH
lsl tailDutyL
rol tailDutyH
out tailPwm, tailDutyH
rjmp get_duty
Hope it helps, would great to have another option for 4#3Q.

Phil

edit : code pwm>pwm added
SadSack is offline Find More Posts by SadSack
Last edited by SadSack; Jan 17, 2010 at 06:29 AM.
Reply With Quote
Sign up now
to remove ads between posts
Old Jan 15, 2010, 07:34 AM
Registered User
UK
Joined Oct 2003
3,821 Posts
might help if you posted what language you wrote the code in
Malc C is offline Find More Posts by Malc C
Reply With Quote
Old Jan 15, 2010, 07:37 AM
Registered User
UK
Joined Oct 2003
3,821 Posts
Not sure if it has any bearing with this, but some walkera protocols don't or didn't follow standards set down with Futaba / JR - if so then this is why the code may work with normal main stream TX's such as Futaba but not with Walkera
Malc C is offline Find More Posts by Malc C
Reply With Quote
Old Jan 15, 2010, 07:49 AM
Registered User
United Kingdom, Bristol
Joined Aug 2008
1,774 Posts
Atmel AVR Studio

Brushed to Brushless converter
SadSack is offline Find More Posts by SadSack
Last edited by SadSack; Jan 15, 2010 at 09:08 AM.
Reply With Quote
Old Mar 16, 2010, 06:10 PM
flying beam
blackmoon's Avatar
through the Looking Glass
Joined Apr 2008
1,661 Posts
Quote:
Originally Posted by SadSack View Post
Hi

I have had this code awhile now and i can't make it work. So rather than just delete i'll post it in vane chance someone can complete or fix it. But share code once completed.

Problem is duty cycle its reading half and outputs 100% power @ half stick.


Hope it helps, would great to have another option for 4#3Q.

Phil

edit : code pwm>pwm added
"Problem is duty cycle its reading half and outputs 100% power @ half stick."


Do the two code give the same result ?

Paulo.
blackmoon is offline Find More Posts by blackmoon
Reply With Quote
Old Mar 18, 2010, 06:33 AM
Registered User
United Kingdom, Bristol
Joined Aug 2008
1,774 Posts
Quote:
Originally Posted by blackmoon View Post
"Problem is duty cycle its reading half and outputs 100% power @ half stick."


Do the two code give the same result ?

Paulo.

I never did try the pwm>pwm converter so can't say for sure how it working, sorry
SadSack is offline Find More Posts by SadSack
Reply With Quote
Old Mar 20, 2010, 05:47 AM
flying beam
blackmoon's Avatar
through the Looking Glass
Joined Apr 2008
1,661 Posts
Could you please post a schematic and part list to make the converter ?

I'll try to find a ATtiny85 and some time to conduct tests.

Thx.
blackmoon is offline Find More Posts by blackmoon
Last edited by blackmoon; Mar 20, 2010 at 05:55 AM.
Reply With Quote
Old Mar 20, 2010, 07:18 AM
Registered User
United Kingdom, Bristol
Joined Aug 2008
1,774 Posts
.equ mainIn = 2 ; PB2 = pin 7
.equ tailIn = 3 ; PB3 = pin 2

.equ mainOut = 1 ; OC1A = PB1 = pin 6
.equ tailOut = 4 ; OC1B = PB4 = pin 3
.equ LEDpin = 0

Thats all you need and 10nf cap from ground to power. Look at datasheet for pin numbers. Can use 45 if thats easyer to find!?

Phil
SadSack is offline Find More Posts by SadSack
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion The F.A.Q.s, ma'am, just the F.A.Q.s! Mode One AMA (Academy of Model Aeronautics) 12 Jan 20, 2010 07:23 AM
Sold Walkera BL motors and ESC's/converters for 4G3 and 4#3A,B,Q Crushalot Aircraft - Electric - Helis (FS/W) 2 Aug 03, 2009 05:44 PM
Question PPM decode + PWM encode in one PIC AnthonyRC UAV - Unmanned Aerial Vehicles 31 Mar 04, 2008 04:10 PM
Discussion PPM to PWM demux Tom Harper DIY Electronics 3 Jun 15, 2007 11:27 PM
Question PPM decode + PWM encode in one PIC AnthonyRC DIY Electronics 14 Jul 03, 2006 01:26 AM