Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
a problem with reading continuous values into Microcontroller - roopa valluri - Sep 22 17:32:59 2008
hello can any body help me with a problem of reading continuous voltages into the
controller comparing the voltages read and generating pulses as per the logic listed in
the program.
the code should basically read the voltages continuously and compare the voltages and
generate pulses at PWM port. But my code is not reading the voltages as and when they are
changed it has to be compiled for the new values to reflect but I believe I have written
the code to read the values continuously. Please somebody go through my code and please
help me solve this issue.
.nolist
#include hc12.inc
;#INCLUDE 'EQUATES.ASM' ;Equates for all registers
.list
;RAM_START equ $0800
org RAM_START
; ----------------------------------------------------------------------
; MAIN PROGRAM
; ----------------------------------------------------------------------
BSR INIT ; Branch to INIT subroutine to Initialize ATD
BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for breakpoint
; ----------------------------------------------
; Subroutine INIT: Initialize ATD ;
; ----------------------------------------------
INIT:
LDAA #$80 ; Allow ATD to function normally,
STAA ATDCTL2 ; ATD Flags clear normally & disable interrupts
BSR DELAY ; Delay (100 uS) for WAIT delay time.
LDAA #$00 ; Select continue conversion in BGND Mode
STAA ATDCTL3 ; Ignore FREEZE in ATDCTL3
LDAA #$02 ; Select Final Sample time = 2 A/D clocks
STAA ATDCTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
RTS ; Return from subroutine
CONVERT:LDAA #%00010110
STAA ATDCTL5
WTCONV: BRCLR ATDSTATH,#$80,WTCONV ; Wait for Sequence Complete Flag
LDAA ADR2H ; Loads conversion result(ADR2H) into Accumulator
LDAB ADR3H
swi
movb #%01111111,PWCLK ;CON01, clk A = PCLK/128, clk B = PCLK/128
movb #$01,PWPOL ;source is clk A
clr PWCTL
clr PWTST
movb #%00000011,PWEN ;enable PWEN0/1
CBA
;swi
BMI PWM1
BPL PWM2
jsr delay_1
jmp CONVERT
RTS ; Return from subroutine
;* -------------------------------
;* Subroutine DELAY 100 uS *
;* -------------------------------
; Delay Required for ATD converter to Stabilize (100 uSec)
LDAA #$C8 ; Load Accumulator with "100 uSec delay value"
DELAY: DECA ; Decrement ACC
BNE DELAY ; Branch if not equal to Zero
RTS ; Return from subroutine
PWM1:
movw #$0005,PWPER0 ;period
movw #$0003,PWDTY0 ;duty
RTS
;end of pwm1
PWM2:
movw #$0005,PWPER0 ;period
movw #$0001,PWDTY0 ;duty
RTS
; end of pwm
delay_1:pshx
movb #$90,TSCR
movb #$03,TMSK2
movb #$01,TIOS
ldx #20
ldd TCNTH
again: addd #50000
std TC0H
brclr TFLG1,$01,*
ldd TC0H
dbne x,again
pulx
rts
swi
END ; End of program
thank you.
P.S. please help me with this issue asap.
________________________________
Unlimited freedom, unlimited storage. Get it now
Add more friends to your messenger and enjoy! Go to
http://in.messenger.yahoo.com/invite/
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
RE: a problem with reading continuous values into Microcontroller - Darren Moore - Sep 22 19:54:08 2008
Hi,
The first item I noticed is the Delay 'label' is after the
ldaa #$c8 instruction, so A is not loaded.
Regards,
Darren
-----Original Message-----
From: 6...@yahoogroups.com [mailto:6...@yahoogroups.com] On Behalf Of
roopa valluri
Sent: Tuesday, 23 September 2008 07:32
To: 6...@yahoogroups.com
Subject: [68HC12] a problem with reading continuous values into
Microcontroller
hello can any body help me with a problem of reading continuous voltages
into the controller comparing the voltages read and generating pulses as per
the logic listed in the program.
the code should basically read the voltages continuously and compare the
voltages and generate pulses at PWM port. But my code is not reading the
voltages as and when they are changed it has to be compiled for the new
values to reflect but I believe I have written the code to read the values
continuously. Please somebody go through my code and please help me solve
this issue.
.nolist
#include hc12.inc
;#INCLUDE 'EQUATES.ASM' ;Equates for all registers
.list
;RAM_START equ $0800
org RAM_START
; ----------------------------------------------------------------------
; MAIN PROGRAM
; ----------------------------------------------------------------------
BSR INIT ; Branch to INIT subroutine to Initialize
ATD
BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for
breakpoint
; ----------------------------------------------
; Subroutine INIT: Initialize ATD ;
; ----------------------------------------------
INIT:
LDAA #$80 ; Allow ATD to function normally,
STAA ATDCTL2 ; ATD Flags clear normally & disable
interrupts
BSR DELAY ; Delay (100 uS) for WAIT delay time.
LDAA #$00 ; Select continue conversion in BGND Mode
STAA ATDCTL3 ; Ignore FREEZE in ATDCTL3
LDAA #$02 ; Select Final Sample time = 2 A/D clocks
STAA ATDCTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
RTS ; Return from subroutine
CONVERT:LDAA #%00010110
STAA ATDCTL5
WTCONV: BRCLR ATDSTATH,#$80,WTCONV ; Wait for Sequence Complete Flag
LDAA ADR2H ; Loads conversion result(ADR2H) into
Accumulator
LDAB ADR3H
swi
movb #%01111111,PWCLK ;CON01, clk A = PCLK/128, clk B = PCLK/128
movb #$01,PWPOL ;source is clk A
clr PWCTL
clr PWTST
movb #%00000011,PWEN ;enable PWEN0/1
CBA
;swi
BMI PWM1
BPL PWM2
jsr delay_1
jmp CONVERT
RTS ; Return from subroutine
;* -------------------------------
;* Subroutine DELAY 100 uS *
;* -------------------------------
; Delay Required for ATD converter to Stabilize (100 uSec)
LDAA #$C8 ; Load Accumulator with "100 uSec delay
value"
DELAY: DECA ; Decrement ACC
BNE DELAY ; Branch if not equal to Zero
RTS ; Return from subroutine
PWM1:
movw #$0005,PWPER0 ;period
movw #$0003,PWDTY0 ;duty
RTS
;end of pwm1
PWM2:
movw #$0005,PWPER0 ;period
movw #$0001,PWDTY0 ;duty
RTS
; end of pwm
delay_1:pshx
movb #$90,TSCR
movb #$03,TMSK2
movb #$01,TIOS
ldx #20
ldd TCNTH
again: addd #50000
std TC0H
brclr TFLG1,$01,*
ldd TC0H
dbne x,again
pulx
rts
swi
END ; End of program
thank you.
P.S. please help me with this issue asap.
________________________________
Unlimited freedom, unlimited storage. Get it now
Add more friends to your messenger and enjoy! Go to
http://in.messenger.yahoo.com/invite/
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: a problem with reading continuous values into Microcontroller - Michael Burgess - Sep 24 16:26:45 2008
*Well, your CONVERT routine has a number of issues. I'm not sure what
your intent really is,
however, it certainly is not an endless loop as you might want. Your
PWM1:, and PWM2:
labels execute to an RTS which will cause a return from the CONVERT
routine. The delay_1
subroutine will never be executed, nor your JMP CONVERT instruction! You
also have the
issues that are mentioned by others on this forum.
Mike B.*
roopa valluri wrote:
>
> hello can any body help me with a problem of reading continuous
> voltages into the controller comparing the voltages read and
> generating pulses as per the logic listed in the program.
> the code should basically read the voltages continuously and compare
> the voltages and generate pulses at PWM port. But my code is not
> reading the voltages as and when they are changed it has to be
> compiled for the new values to reflect but I believe I have written
> the code to read the values continuously. Please somebody go through
> my code and please help me solve this issue.
>
> .nolist
> #include hc12.inc
> ;#INCLUDE 'EQUATES.ASM' ;Equates for all registers
> .list
> ;RAM_START equ $0800
> org RAM_START
>
> ; ----------------------------------------------------------
> ; MAIN PROGRAM
> ; ----------------------------------------------------------
>
> BSR INIT ; Branch to INIT subroutine to Initialize ATD
> BSR CONVERT ; Branch to CONVERT Subroutine for conversion
> DONE: BRA DONE ; Branch to Self, Convenient place for breakpoint
>
> ; ----------------------------------------------
> ; Subroutine INIT: Initialize ATD ;
> ; ----------------------------------------------
>
> INIT:
> LDAA #$80 ; Allow ATD to function normally,
> STAA ATDCTL2 ; ATD Flags clear normally & disable interrupts
>
> BSR DELAY ; Delay (100 uS) for WAIT delay time.
>
> LDAA #$00 ; Select continue conversion in BGND Mode
> STAA ATDCTL3 ; Ignore FREEZE in ATDCTL3
>
> LDAA #$02 ; Select Final Sample time = 2 A/D clocks
> STAA ATDCTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
>
> RTS ; Return from subroutine
>
> CONVERT:LDAA #%00010110
> STAA ATDCTL5
> WTCONV: BRCLR ATDSTATH,#$80,WTCONV ; Wait for Sequence Complete Flag
> LDAA ADR2H ; Loads conversion result(ADR2H) into Accumulator
> LDAB ADR3H
> swi
> movb #%01111111,PWCLK ;CON01, clk A = PCLK/128, clk B = PCLK/128
> movb #$01,PWPOL ;source is clk A
> clr PWCTL
> clr PWTST
> movb #%00000011,PWEN ;enable PWEN0/1
> CBA
> ;swi
> BMI PWM1
> BPL PWM2
> jsr delay_1
> jmp CONVERT
> RTS ; Return from subroutine
>
> ;* -------------------------------
> ;* Subroutine DELAY 100 uS *
> ;* -------------------------------
> ; Delay Required for ATD converter to Stabilize (100 uSec)
>
> LDAA #$C8 ; Load Accumulator with "100 uSec delay value"
> DELAY: DECA ; Decrement ACC
> BNE DELAY ; Branch if not equal to Zero
> RTS ; Return from subroutine
>
> PWM1:
> movw #$0005,PWPER0 ;period
> movw #$0003,PWDTY0 ;duty
>
> RTS
> ;end of pwm1
> PWM2:
> movw #$0005,PWPER0 ;period
> movw #$0001,PWDTY0 ;duty
>
> RTS
> ; end of pwm
>
> delay_1:pshx
> movb #$90,TSCR
> movb #$03,TMSK2
> movb #$01,TIOS
> ldx #20
> ldd TCNTH
> again: addd #50000
> std TC0H
> brclr TFLG1,$01,*
> ldd TC0H
> dbne x,again
> pulx
> rts
> swi
> END ; End of program
>
> thank you.
> P.S. please help me with this issue asap.
>
> _
>
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: a problem with reading continuous values into Microcontroller - "William R. Elliot" - Sep 25 0:20:50 2008
Good post. I obviously didn't follow the code to its logical
conclusion and made some assumptions (as it seems several
have...including the OP). I humbly apologize.
Note to original programmer: Many on this list could write the
program for you but it won't help you learn anything. Try working
through a small section of the intended activity and ask a specific
question or two.
Bill
At 04:26 PM 9/24/2008, you wrote:
>*Well, your CONVERT routine has a number of issues. I'm not sure what
>your intent really is,
>however, it certainly is not an endless loop as you might want. Your
>PWM1:, and PWM2:
>labels execute to an RTS which will cause a return from the CONVERT
>routine. The delay_1
>subroutine will never be executed, nor your JMP CONVERT instruction! You
>also have the
>issues that are mentioned by others on this forum.
>
>Mike B.*
>
>roopa valluri wrote:
> >
> > hello can any body help me with a problem of reading continuous
> > voltages into the controller comparing the voltages read and
> > generating pulses as per the logic listed in the program.
> > the code should basically read the voltages continuously and compare
> > the voltages and generate pulses at PWM port. But my code is not
> > reading the voltages as and when they are changed it has to be
> > compiled for the new values to reflect but I believe I have written
> > the code to read the values continuously. Please somebody go through
> > my code and please help me solve this issue.
> >
> > .nolist
> > #include hc12.inc
> > ;#INCLUDE 'EQUATES.ASM' ;Equates for all registers
> > .list
> > ;RAM_START equ $0800
> > org RAM_START
> >
> > ; ----------------------------------------------------------
> > ; MAIN PROGRAM
> > ; ----------------------------------------------------------
> >
> > BSR INIT ; Branch to INIT subroutine to Initialize ATD
> > BSR CONVERT ; Branch to CONVERT Subroutine for conversion
> > DONE: BRA DONE ; Branch to Self, Convenient place for breakpoint
> >
> > ; ----------------------------------------------
> > ; Subroutine INIT: Initialize ATD ;
> > ; ----------------------------------------------
> >
> > INIT:
> > LDAA #$80 ; Allow ATD to function normally,
> > STAA ATDCTL2 ; ATD Flags clear normally & disable interrupts
> >
> > BSR DELAY ; Delay (100 uS) for WAIT delay time.
> >
> > LDAA #$00 ; Select continue conversion in BGND Mode
> > STAA ATDCTL3 ; Ignore FREEZE in ATDCTL3
> >
> > LDAA #$02 ; Select Final Sample time = 2 A/D clocks
> > STAA ATDCTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
> >
> > RTS ; Return from subroutine
> >
> > CONVERT:LDAA #%00010110
> > STAA ATDCTL5
> > WTCONV: BRCLR ATDSTATH,#$80,WTCONV ; Wait for Sequence Complete Flag
> > LDAA ADR2H ; Loads conversion result(ADR2H) into Accumulator
> > LDAB ADR3H
> > swi
> > movb #%01111111,PWCLK ;CON01, clk A = PCLK/128, clk B = PCLK/128
> > movb #$01,PWPOL ;source is clk A
> > clr PWCTL
> > clr PWTST
> > movb #%00000011,PWEN ;enable PWEN0/1
> > CBA
> > ;swi
> > BMI PWM1
> > BPL PWM2
> > jsr delay_1
> > jmp CONVERT
> > RTS ; Return from subroutine
> >
> > ;* -------------------------------
> > ;* Subroutine DELAY 100 uS *
> > ;* -------------------------------
> > ; Delay Required for ATD converter to Stabilize (100 uSec)
> >
> > LDAA #$C8 ; Load Accumulator with "100 uSec delay value"
> > DELAY: DECA ; Decrement ACC
> > BNE DELAY ; Branch if not equal to Zero
> > RTS ; Return from subroutine
> >
> > PWM1:
> > movw #$0005,PWPER0 ;period
> > movw #$0003,PWDTY0 ;duty
> >
> > RTS
> > ;end of pwm1
> > PWM2:
> > movw #$0005,PWPER0 ;period
> > movw #$0001,PWDTY0 ;duty
> >
> > RTS
> > ; end of pwm
> >
> > delay_1:pshx
> > movb #$90,TSCR
> > movb #$03,TMSK2
> > movb #$01,TIOS
> > ldx #20
> > ldd TCNTH
> > again: addd #50000
> > std TC0H
> > brclr TFLG1,$01,*
> > ldd TC0H
> > dbne x,again
> > pulx
> > rts
> > swi
> > END ; End of program
> >
> > thank you.
> > P.S. please help me with this issue asap.
> >
> > _
> >------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )