EmbeddedRelated.com
Forums

a problem with reading continuous values into Microcontroller

Started by roopa valluri September 6, 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, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/


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/


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... [mailto:6...] On Behalf Of
roopa valluri
Sent: Tuesday, 23 September 2008 07:32
To: 6...
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/


Also this looks like a single conversion per reset:

BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for
breakpoint

Edward
----- Original Message -----
From: "Darren Moore"
To: <6...>
Sent: Tuesday, September 23, 2008 2:52 AM
Subject: RE: [68HC12] a problem with reading continuous values into
Microcontroller
> 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... [mailto:6...] On Behalf Of
> roopa valluri
> Sent: Tuesday, 23 September 2008 07:32
> To: 6...
> 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/
>
>
>
Hello Edward,
if i need to make this a continuous conversion what needs to be done ..I am unable to figure it out. I also tried making it to scan continuously but havent found any difference. So if it has to continuously do the conversion what changes do you suggest.

thanks,
roopa

----- Original Message ----
From: Edward Karpicz
To: 6...
Sent: Tuesday, 23 September, 2008 12:06:28 AM
Subject: Re: [68HC12] a problem with reading continuous values into Microcontroller
Also this looks like a single conversion per reset:

BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for
breakpoint

Edward

----- Original Message -----
From: "Darren Moore"
To: <68HC12@yahoogroups. com>
Sent: Tuesday, September 23, 2008 2:52 AM
Subject: RE: [68HC12] a problem with reading continuous values into
Microcontroller

> 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: 68HC12@yahoogroups. com [mailto:68HC12@yahoogroups. com] On Behalf Of
> roopa valluri
> Sent: Tuesday, 23 September 2008 07:32
> To: 68HC12@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/
>
>
> ------------ --------- --------- ------
bsr CONVERT - that's a single call to convert subroutine, right?
done : bra done - that's a forever loop.

So CONVERT routine is called once per reset. If you didn't see that, then I
guess you can't explain also what SWI instructions are doing in your code.

Edward
----- Original Message -----
From: "roopa valluri"
To: <6...>
Sent: Wednesday, September 24, 2008 03:23
Subject: Re: [68HC12] a problem with reading continuous values into
Microcontroller
> Hello Edward,
> if i need to make this a continuous conversion what needs to be done ..I
> am unable to figure it out. I also tried making it to scan continuously
> but havent found any difference. So if it has to continuously do the
> conversion what changes do you suggest.
>
> thanks,
> roopa
>
> ----- Original Message ----
> From: Edward Karpicz
> To: 6...
> Sent: Tuesday, 23 September, 2008 12:06:28 AM
> Subject: Re: [68HC12] a problem with reading continuous values into
> Microcontroller
> Also this looks like a single conversion per reset:
>
> BSR CONVERT ; Branch to CONVERT Subroutine for conversion
> DONE: BRA DONE ; Branch to Self, Convenient place for
> breakpoint
>
> Edward
>
> ----- Original Message -----
> From: "Darren Moore"
> To: <68HC12@yahoogroups. com>
> Sent: Tuesday, September 23, 2008 2:52 AM
> Subject: RE: [68HC12] a problem with reading continuous values into
> Microcontroller
>
>> 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: 68HC12@yahoogroups. com [mailto:68HC12@yahoogroups. com] On Behalf
>> Of
>> roopa valluri
>> Sent: Tuesday, 23 September 2008 07:32
>> To: 68HC12@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/
>>
>>
>> ------------ --------- --------- ------
Note that CONVERT is itself an endless loop once it is entered.

At 03:02 AM 9/24/2008, you wrote:
> bsr CONVERT - that's a single call to convert subroutine, right?
> done : bra done - that's a forever loop.
>
>So CONVERT routine is called once per reset. If you didn't see that, then I
>guess you can't explain also what SWI instructions are doing in your code.
>
>Edward
>----- Original Message -----
>From: "roopa valluri"
>To: <6...>
>Sent: Wednesday, September 24, 2008 03:23
>Subject: Re: [68HC12] a problem with reading continuous values into
>Microcontroller
> > Hello Edward,
> > if i need to make this a continuous conversion what needs to be done ..I
> > am unable to figure it out. I also tried making it to scan continuously
> > but havent found any difference. So if it has to continuously do the
> > conversion what changes do you suggest.
> >
> > thanks,
> > roopa
> >
> > ----- Original Message ----
> > From: Edward Karpicz
> > To: 6...
> > Sent: Tuesday, 23 September, 2008 12:06:28 AM
> > Subject: Re: [68HC12] a problem with reading continuous values into
> > Microcontroller
> >
> >
> > Also this looks like a single conversion per reset:
> >
> > BSR CONVERT ; Branch to CONVERT Subroutine for conversion
> > DONE: BRA DONE ; Branch to Self, Convenient place for
> > breakpoint
> >
> > Edward
> >
> > ----- Original Message -----
> > From: "Darren Moore"
> > To: <68HC12@yahoogroups. com>
> > Sent: Tuesday, September 23, 2008 2:52 AM
> > Subject: RE: [68HC12] a problem with reading continuous values into
> > Microcontroller
> >
> >> 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: 68HC12@yahoogroups. com [mailto:68HC12@yahoogroups. com] On Behalf
> >> Of
> >> roopa valluri
> >> Sent: Tuesday, 23 September 2008 07:32
> >> To: 68HC12@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/
> >>
> >>
> >>
> >>
> >> ------------ --------- --------- ------
> >>
> >>
*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.
>
> _
>

Hello Micheal,
Thanks for the reply.
The requirement with the code is that it should keep on reading voltages from 2 sources and when there is a change in the voltage ( if voltage to one pin is higher than the other or vice-versa) then it should go into the loop PWM1 or PWM2 and do the necessary. But the code once executed should keep on running as opposed to my code which needs constant execution. So can you help me in changing the code as per the requirement.

thanks,
Roopa

----- Original Message ----
From: Michael Burgess
To: 6...
Sent: Wednesday, 24 September, 2008 4:26:32 PM
Subject: Re: [68HC12] a problem with reading continuous values into Microcontroller
*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.
>
> _
>