Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up ADC code #456

Closed
TG9541 opened this issue Jan 28, 2023 · 3 comments
Closed

Clean up ADC code #456

TG9541 opened this issue Jan 28, 2023 · 3 comments

Comments

@TG9541
Copy link
Owner

TG9541 commented Jan 28, 2023

STM8S / STM8L conditional code in stm8_adc.inc is a bit hard to read and Forth headers are duplicated. Clean it up.

@TG9541
Copy link
Owner Author

TG9541 commented Jan 28, 2023

The instruction BRES ADC1_CR1,#0 ; disable ADC in stm8_adc.inc is unreachable.

 
 ;       ADC@  ( -- w )
 ;       start ADC conversion, read result
 
         HEADER  ADCAT "ADC@"
 ADCAT:
         .ifeq   (FAMILY - STM8L)
 ;       ADC for the STM8L family
         BRES    ADC1_SR,#0      ; reset EOC
         BSET    ADC1_CR1,#0     ; enable ADC
         BSET    ADC1_CR1,#1     ; start ADC
 1$:     BTJF    ADC1_SR,#0,1$   ; wait until EOC
         LDW     Y,ADC1_DRH      ; read ADC
         JP      YSTOR
         BRES    ADC1_CR1,#0     ; disable ADC

@Eelkhoorn the STM8L ADC@ code was provided by you. Should I fix and test something (maybe the intention was to conserve power)? Otherwise I'll just remove that line.

@Eelkhoorn
Copy link
Collaborator

Eelkhoorn commented Jan 29, 2023 via email

@TG9541
Copy link
Owner Author

TG9541 commented Jan 29, 2023

Hoi @Eelkhoorn, thanks, that explains it :-)

Unreachable it is because the JP YSTOR effectively ends the subroutine (it contains the RET instruction).

The following would work:

1$:     BTJF    ADC1_SR,#0,1$   ; wait until EOC
        LDW     Y,ADC1_DRH      ; read ADC
        CALL      YSTOR
        BRES    ADC1_CR1,#0     ; disable ADC
        RET

But then it's better to do this:

1$:     BTJF    ADC1_SR,#0,1$   ; wait until EOC
        LDW     Y,ADC1_DRH      ; read ADC
        BRES    ADC1_CR1,#0     ; disable ADC
        JP      YSTOR

Since more tests are needed in order to optimize power consumption in an application, the line will be removed for now. Control of the peripheral and the clock setting can also be done in the application.

@TG9541 TG9541 closed this as completed Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants