DynamicRC 광팬 커뮤니티에 오신 것을 환영합니다!
DynamicRC 광팬 커뮤니티

게시판 통합검색 help
subject/ name/ content/ comment

공지사항 자유게시판 QnA 제작일지 비행일지
RC전자공작 MCU STUDY IR·RF 자료실 Link 옛날 프로젝트룸

* *

 tiny10 pwm2ppm 컨버터

2012-04-29 03:00:38, Hit : 3415

작성자 : 이학종
- Download #1 : A013___20120429_023552.jpg(488.1 KB), Download : 35
원래크기로보기

tiny10으로 pwm2ppm 컨버터를 만들었습니다.
2ch도 충분히 할 수 있고 코드도 있지만 테스트를 안해봐서 1ch짜리를 올립니다.
이것도 상당히 더 편리하고 좋게 다듬을 수 있는데 구찬으니까 구냥 쓸랍니다.

tiny13을 쓴게 공개되어 있지만 변속기에 기생하기에는 크기가 좀 큽니다.
이거는 변속기에 작은 공간이라도 비집고 들어가서 기성부품처럼 자리잡을 수 있습니다.
사용하지 않는 2핀은 hi 임피던스로 처리해서 전원단자와 쇼트시켜도 무방하게해서 부착을 쉽게 했습니다.


/*****************************************************
**********    attiny10 pwm2ppm 컨버터 1CH  ***********
******************************************************
        tiny10
      (data)  (rst)
      PB0-[..]-PB3
(-)-- GND-[..]-VCC --(+)
out<- PB1-[..]-PB2 <-in
(clk)

서보신호 ___-_______--___   주기:16ms 펄스폭:1~2ms
PB0,3 : high 임피던스(입력)
PB1 : ppm신호 out
PB2 : pwm신호 in
                            2012년 4월 29일 이학종 만듦
******************************************************/

;     8Mhz 시스템에서 1msec에 상당하는 클럭수
;     8000회 / 10클럭(루프당) = 800

.equ CNT_1MS  = (8000 / 10)
.equ PWM_IN  = PB2  ; PB2
.equ PPM_OUT  = PB1  ; PB1
.equ PERIOD_MS = 22  ; 19 이상 권장

.def cnt_h  = r16
.def cnt_l  = r17
.def loop_h  = r18
.def loop_l  = r19
.def set_timer = r20
.def temp1  = r21
.def temp2  = r22
.def i_temp1  = r23  ; interrupt temporary
.def i_temp2  = r24  ; interrupt temporary
.def i_sreg  = r25  ; interrupt temporary
;#####################################################
.cseg
.org 0
  rjmp reset
  nop ; ext0_int
  nop ; pci0_int
  nop ; capt0_int
  rjmp  ovf0_int
  nop ; ccma_int
  nop ; ccmb_int
  nop ; comp_int
  nop ; wdc
  nop ; vlm
  nop ; adc

version:.db "pwm2ppm_1 v1.0"

;#####################################################
reset:
;#####  8Mhz 지정  
  ldi  temp1, 0xd8
  ldi  temp2, 0
  out  CCP, temp1
  out  CLKMSR, temp2

  out  CCP, temp1
  out  CLKPSR, temp2

;#####  초기화
  ldi  temp1, (1<<PWM_IN) ; PPM_IN pull-up
  out  PORTB, temp1
  ldi  temp1, (1<<PPM_OUT) ; PPM_OUT만 출력으로 설정
  out  DDRB, temp1

  ldi  temp1, 2  ; (1,2,3,4,5) => clk / (1,8,64,256,1024)
  out  TCCR0B, temp1
  ldi  temp1, (1 << TOIE0)
  out  TIMSK0, temp1
  ser  set_timer
  ldi  temp1,  high(65536 - (1000*PERIOD_MS))
  ldi  temp2,  low (65536 - (1000*PERIOD_MS))
  out  TCNT0H,   temp1
  out  TCNT0L,   temp2

  cbi  PORTB, PPM_OUT ; ppm 신호를 '0'으로
  sei

;#####################################################
;##### 메인루프
loop:
  ldi  loop_h, high  (CNT_1MS * 16)  // PERIOD 16ms초
  ldi  loop_l, low   (CNT_1MS * 16)
  clr  cnt_h
  clr  cnt_l

;##### 16ms동안 PB1의 신호가 '1'인 횟수를 카운트하여 cnt_h,l에 저장
  clr  temp1
  clr  temp2
count_on:    // 11*(loop_l+1) + (14 + 11*255)*loop_h
  sbis PINB, PWM_IN  ; pwm신호가 '1'이면 점프
  ldi  temp1, 0
  sbic PINB, PWM_IN  ; pwm신호가 '0'이면 점프
  ldi  temp1, 1
  add  cnt_l, temp1
  adc  cnt_h, temp2

  dec  loop_l
  cpi  loop_l, 0xff
  brne count_on
  dec  loop_h
  cpi  loop_h, 0xff
  brne count_on

;##### 변수값 저장
; loop_l,h <- CNT_1MS + 추가할 펄스폭
  ldi  loop_l, low (CNT_1MS)
  ldi  loop_h, high(CNT_1MS)
  lsr  cnt_h
  ror  cnt_l
  lsr  cnt_h
  ror  cnt_l
  lsr  cnt_h
  ror  cnt_l
  lsr  cnt_h
  ror  cnt_l ; cnt / 16 ... 1ms동안 카운트된 '1'의 수

  add  loop_l, cnt_l
  adc  loop_h, cnt_h

;#####  ppm 펄스 출력
  clr  temp1
  clr  temp2
  sbi  PORTB,  PPM_OUT ; ppm신호를 '1'로
delay_plus:
  sbis PINB, PWM_IN
  ldi  temp1, 0
  sbic PINB, PWM_IN
  ldi  temp1, 0
  add  cnt_l, temp1
  add  cnt_h, temp2

  dec  loop_l
  cpi  loop_l, 0xff
  brne delay_plus
  dec  loop_h
  cpi  loop_h, 0xff
  brne delay_plus

  cbi  PORTB, PPM_OUT ; ppm 신호를 '0'으로
  ser  set_timer
wait_tmr:
  tst  set_timer
  brne wait_tmr
    
  rjmp loop

;#####################################################
;#####  timer interrupt
ovf0_int:
  in  i_sreg,  SREG

  clr  set_timer
  ldi  i_temp1,  high(65536 - (1000*PERIOD_MS))
  ldi  i_temp2,  low (65536 - (1000*PERIOD_MS))
  out  TCNT0H,   i_temp1
  out  TCNT0L,   i_temp2

  out  SREG,   i_sreg
  reti

.exit

;#####################################################

/*
AVR Studio 5.0에서 컴파일
pwm2ppm_xy.hex : PBx(in)--->PBy(out)

ex)pwm2pp_01.hex : PB0(pwm input)--->PB1(ppm out)

### pwm2ppm_01.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300051E052B952E051B952E05DBD51E05BBDB3
:100040004FEF5AEA60E159BD68BD1198789422E3F8
:1000500030E00027112755276627009B50E00099C4
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627119A4A
:10009000009B50E0009950E0150F060F3A953F3F46
:1000A000B9F72A952F3FA1F711984FEF4423F1F7A5
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_02.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300051E052B954E051B952E05DBD51E05BBDB1
:100040004FEF5AEA60E159BD68BD1298789422E3F7
:1000500030E00027112755276627009B50E00099C4
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627129A49
:10009000009B50E0009950E0150F060F3A953F3F46
:1000A000B9F72A952F3FA1F712984FEF4423F1F7A4
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_03.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300051E052B958E051B952E05DBD51E05BBDAD
:100040004FEF5AEA60E159BD68BD1398789422E3F6
:1000500030E00027112755276627009B50E00099C4
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627139A48
:10009000009B50E0009950E0150F060F3A953F3F46
:1000A000B9F72A952F3FA1F713984FEF4423F1F7A3
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_10.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300052E052B951E051B952E05DBD51E05BBDB3
:100040004FEF5AEA60E159BD68BD1098789422E3F9
:1000500030E00027112755276627019B50E00199C2
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627109A4B
:10009000019B50E0019950E0150F060F3A953F3F44
:1000A000B9F72A952F3FA1F710984FEF4423F1F7A6
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_12.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300052E052B954E051B952E05DBD51E05BBDB0
:100040004FEF5AEA60E159BD68BD1298789422E3F7
:1000500030E00027112755276627019B50E00199C2
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627129A49
:10009000019B50E0019950E0150F060F3A953F3F44
:1000A000B9F72A952F3FA1F712984FEF4423F1F7A4
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_13.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300052E052B958E051B952E05DBD51E05BBDAC
:100040004FEF5AEA60E159BD68BD1398789422E3F6
:1000500030E00027112755276627019B50E00199C2
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627139A48
:10009000019B50E0019950E0150F060F3A953F3F44
:1000A000B9F72A952F3FA1F713984FEF4423F1F7A3
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_20.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300054E052B951E051B952E05DBD51E05BBDB1
:100040004FEF5AEA60E159BD68BD1098789422E3F9
:1000500030E00027112755276627029B50E00299C0
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627109A4B
:10009000029B50E0029950E0150F060F3A953F3F42
:1000A000B9F72A952F3FA1F710984FEF4423F1F7A6
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_21.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300054E052B952E051B952E05DBD51E05BBDB0
:100040004FEF5AEA60E159BD68BD1198789422E3F8
:1000500030E00027112755276627029B50E00299C0
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627119A4A
:10009000029B50E0029950E0150F060F3A953F3F42
:1000A000B9F72A952F3FA1F711984FEF4423F1F7A5
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_23.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300054E052B958E051B952E05DBD51E05BBDAA
:100040004FEF5AEA60E159BD68BD1398789422E3F6
:1000500030E00027112755276627029B50E00299C0
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627139A48
:10009000029B50E0029950E0150F060F3A953F3F42
:1000A000B9F72A952F3FA1F713984FEF4423F1F7A3
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_30.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300058E052B951E051B952E05DBD51E05BBDAD
:100040004FEF5AEA60E159BD68BD1098789422E3F9
:1000500030E00027112755276627039B50E00399BE
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627109A4B
:10009000039B50E0039950E0150F060F3A953F3F40
:1000A000B9F72A952F3FA1F710984FEF4423F1F7A6
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_31.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300058E052B952E051B952E05DBD51E05BBDAC
:100040004FEF5AEA60E159BD68BD1198789422E3F8
:1000500030E00027112755276627039B50E00399BE
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627119A4A
:10009000039B50E0039950E0150F060F3A953F3F40
:1000A000B9F72A952F3FA1F711984FEF4423F1F7A5
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

### pwm2ppm_32.hex ###
:020000020000FC
:1000000011C000000000000054C00000000000000B
:1000100000000000000070776D3270706D5F31205D
:1000200076312E3058ED60E05CBF67BF5CBF66BFC5
:1000300058E052B954E051B952E05DBD51E05BBDAA
:100040004FEF5AEA60E159BD68BD1298789422E3F7
:1000500030E00027112755276627039B50E00399BE
:1000600051E0150F061F3A953F3FB9F72A952F3FEC
:10007000A1F730E223E006951795069517950695AA
:10008000179506951795310F201F55276627129A49
:10009000039B50E0039950E0150F060F3A953F3F40
:1000A000B9F72A952F3FA1F712984FEF4423F1F7A4
:1000B000CECF9FB744277AEA80E179BD88BD9FBF44
:0200C000189591
:00000001FF

*/

 




이학종
참, 사진에 있는 t10은 전시용이고 실제는 뒤집어서 납땝되어 있습니다. 2012-04-29
03:03:41

수정  
김영일
이시간에 잠 들지않은 2인입니다.
이작품을 처음보시는 분은 이 것의 목적을 궁금해 하실것 같은데요. 부연설명도
부탁합니다.
2012-04-29
03:11:06

수정  
박재량
PWM 2 PPM이라면 적외선 수신기에서나오는 PWM파형을 일반 변속기에 쓸수있도록 PPM으로 바꾸어준다 라는것 인가요?
작은 부품하나 추가로 적외선 수신기에서 브러쉬리스도 쓸수있겠네요 ㅎㅎ
2012-04-29
09:42:37

수정 삭제
김창문
어느 hex파일을 쓰는건가요? 고이찌사이트에도 같은 것이 있어 전에 만들어 보았는데 잘 작동하더군요. PIC10F200 을 씁니다. 2012-04-29
13:32:02

수정 삭제
이학종
다리 4개중에 2개를 선택해서 하나는 입,하나는 출력으로 쓰는거죠. 그러니까 4C2 * 2 = 12가지가 있어요.
끝에있는 숫자 32 라면 B3을 입력 B2를 출력으로 쓰는 코드입니다.
끝에있는 숫자 01 이라면 B0을 입력 B1를 출력으로 쓰는 코드입니다.
2012-04-29
18:41:27

수정  
윤한덕
오~ 멋집니다. 그런데 어디에 쓰는 줄은 모르고 있는 1인.... 2012-04-30
02:02:32

수정  
정재광
브러시용 헬기나 기체를 브러시리스화 하실 목적인 것 같습니다. 상용기판에서 나오는 브러시모터용 pwm 신호를 ppm 신호로 변환하면 브러시리스 모터를 사용할 수 있습니다. 2012-04-30
21:21:41

수정  

버튼입력 프로그램소스좀 구할수 있을까요? [2]
ATTiny10 - 6핀짜리 최소형 8bit MCU에 프로그램 써넣기

Copyright 1999-2017 Zeroboard / skin by 또미
Copyright 2003-2010 DYNAMICRC.COM All rights reserved