MC68HC908QT2, Microcontroller Handles LED Brightness Control, PWM method


還好找到部份存檔, 半小時就恢復了工作, 繼續餘下的實驗

Drive 2CH LEDs only,

http://youtu.be/8GzU05ZW52M

Drive 2CH LEDs and one galvanometer, needle movement is quite linear motion

http://www.youtube.com/watch?v=RQRn08VXTNI

QT2 當 QT4 用

運行正常

ON/OFF control, PTA3 will be control pin if UserMonitor is used

ON/OFF control will be at PTA2 default as blank device without UserMonitor.

schematic and zipped code and firmware, download this image, rename to zip.

https://xiaolaba.files.wordpress.com/2012/06/microcontroller_handles_led_brightness_control_zipped_rev2.jpg

source code

——————-


****************************************************************
*     Two dimming LEDs driver                        *
******************************************************
* Internal fosc=12.8MHz,
* TIMER time T(decimal)=50*T(ms)
* Pulse Width increment/decrement=6,i.e 6/50=0.12ms

$nolist
;$include 'Fr908qt2.asm' ;frame file for 908QT2

; modified by xiaolaba, fit for QT2 / AT4
; 2012-06-29
; -------------------
RAM     equ     $80
ROM     equ     $EE00
prtA     equ     $0
pA0.     equ     $1
pA1.     equ     $2
TOF      equ     7

CONFIG2 EQU $001E
CONFIG1 EQU $001F

PORTA    EQU $0000
PORTB    EQU $0001
DDRA    EQU $0004
DDRB    EQU $0005
PTAPUE  EQU $000B
PTBPUE  EQU $000C

TSC    EQU $0020
TCNTH    EQU $0021
TCNTL    EQU $0022
TMODH    EQU $0023
TMODL    EQU $0024
TSC0    EQU $0025
TCH0H    EQU $0026
TCH0L    EQU $0027
TSC1    EQU $0028
TCH1H    EQU $0029
TCH1L    EQU $002A

OSCSTAT EQU $0036
OSCTRIM EQU $0038
; -------------------

$list
*I/O

*pA0 output PWM to LED1
*pA1 output PWM to LED2
*pA2 input ON/OFF Control: ON(1),OFF(0)

* CONSTANTS
PERIOD_PWM  EQU $320 ;period PWM=16ms (16*50=800=$320)

*VARIABLES
ORG RAM
Tcnt        RMB 1    ;Ramp time counter
cnt01s      RMB 1    ;delay counter

*INITIALIZATION
ORG ROM
init        RSP                ;$FF-->SP
MOV   #$01,CONFIG1 ;COP disabled
CLRH               ;clear H:X
CLRX
CLRA
clr   Tcnt        ;

MOV   #$03,Tch1H      ;set Initial pwLED2=6x128=800=$0300
clr   Tch1L

clr   Tch0H           ;set Initial pwLED1=0
clr   Tch0L

clr   cnt01s

MOV   #255T,Tcnt      ;set Initial Tcnt (to be 0 after INC)
CLR   prtA            ;
MOV   #pA0.+pA1.,DDRA ;set I/O prtA

LDHX  #PERIOD_PWM     ;PWM PERIOD-->TmodH
STHX  TmodH

MOV   #%00010110,TSC  ;clear & start TIMER,prescaler:64

.page
MAIN        brset 2,prtA,m4    ;start working only when pA2=1
CLR   TSC0
CLR   TSC1
BRA   MAIN
m4          BRCLR TOF,TSC,*    ;wait for the end of PERIOD_PWM
BCLR  TOF,TSC      ;TOF reset
INC   Tcnt         ;set the next time step
LDA   Tcnt         ;is the time overpassed the ramp 1
m1          CMP   #128T        ;duration?
BHS   m3
***************************************
tst   Tcnt         ;Tcnt=0?
bne   ramp1        ;If not, go to ramp1
jsr   dly          ;If yes, go to delay
ramp1       LDHX  Tch0H        ;increment pwLED1
AIX   #6T
STHX  Tch0H
LDHX  Tch1H        ;decrement pwLED2
AIX   #-6T
STHX  Tch1H
BRA   m2
****************************************
m3          bne   ramp2        ;Tcnt=128? If not,go to ramp2
jsr   dly          ;          If yes,go to delay
ramp2       LDHX  Tch1H        ;increment pwLED2
AIX   #6T
STHX  Tch1H
LDHX  Tch0H        ;decrement pwLED1
AIX   #-6T
STHX  Tch0H
****************************************
m2          MOV   #%00011010,TSC0 ;start Tch0H on pA0
MOV   #%00011010,TSC1 ;start Tch1H on pA1
JMP   MAIN
**************************************************************
dly         LDA   #30T          ;delay 3sec
lp0         JSR   dly01s
DBNZA lp0
rts
**************************************************************
dly01s      LDX   #250T         ;delay0.1sec
loop        DBNZ  cnt01s,loop
DBNZX loop
rts
**************************************************************
ORG $FFFE  ; Vector reset
FDB init   ; Set start address

——————-

firmware image

——————-


S113EE009C6E011F8C5F4F3F806E03293F2A3F2673
S113EE103F273F816EFF803F006E0304450320358A
S113EE20236E16200400063F253F2820F70F20FDFF
S113EE301F203C80B680A18024153D802603CDEEA2
S113EE40695526AF0635265529AFFA3529201126EE
S113EE5003CDEE695529AF0635295526AFFA352677
S113EE606E1A256E1A28CCEE24A61ECDEE714BFB2D
S10CEE7081AEFA3B81FD5BFB81DC
S105FFFEEE000F
S9030000FC

————-

原來參考的資料, 都斷了,

MCU Handles LED Brightness Control
http://blog.yahoo.com/_75UIOHG2UVM5RMBLG4ZZVVJLTA/articles/382189

MCU Handles LED Brightness Control
http://www.elecdesign.com/Articles/ArticleID/9254/9254.html

只剩解說, 圖片, 源碼都沒了

http://electronicdesign.com/print/components/microcontroller-handles-led-brightness-control9254

Evgeniy Freidlin, Abel Raynus

December 08, 2004

Usually, an MCU is considered a digital device. By default, its output voltage level can be either high or low and nothing in between. With the requirement to create an LED brightness control, the first idea that comes to mind is using a standard digital-to-analog converter, or design a controlled resistor network. Luckily, most modern MCUs have built-in pulse-width modulation (PWM), and this leads to the easiest and cheapest way to solve the problem.

According to our project requirements, the brightness of two LEDs has to be gradually changed from minimum to maximum and back, in the opposite phase and in a time of about several seconds. Also, the several seconds of delay between the ramps should be as shown in Figure 1. During Ramp 1 time, the PWM signal’s pulse width is incremented for LED 1 and decremented for LED 2. For example, let’s have the ramp time equal 2 seconds and consist of 128 up/down steps. Thus, each step lasts about 16 ms. Note that the pulse-width change should occur only once during the PWM period. Hence, the PWM period should also equal 16 ms.

The low-end 8-bit Motorola MC68HC908-QT2 flash MCU with built-in oscillator is used. Its oscillation frequency equals 12.8 MHz, together with the prescaler programmed to a selection of 1:64, and supplies a timer clock period of 0.02 ms. Then, to generate a PWM with a 16-ms period, the number of clocks to be loaded into Timer Counter Modulo Register (Tmod) should equal 16/0.02 = 800, or $0320 in hexadecimal.

The maximum pulse width (PWMAX) can be less than or equal to the PWM period. Consider PWmax to be equal to about 15 ms. To get this maximum value from zero, for 128 steps, each step should have a value of 15/128 = 0.117 ms. By rounding it to 0.12 ms, we get PWMAX = 15.36 ms , i.e., 96% of the PWM period. Thus, in each step, the PW should ramp up/down on 0.12-ms increments, equal to 0.12/0.02 = 6 timer clocks.

Any type of MCU with PWM and any timing consideration can be used to implement this technique. Resistors R1 and R2 should be chosen according to the LEDs used. Pin pA2 is used to activate (pA2 =1) or deactivate (pA2=0) the brightness control.

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s