Problems with QD2 ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with QD2 ADC

1,742 Views
Zetta08
Contributor I
I am using the QD2 and I have problems with the ADC
 
The instructions for Init_ADC init code are:
 
                     LDA     #$18
                     STA     SPMSC1
 
                     LDA     #$F0
                     STA     ADCCFG                                               
      
                     MOV     #$01,ADCSC1
      
                     LDA     #$02
                     STA     APCTL1
 
In de Loop:
 
                    BSET    ADCSC1_ADCH1,ADCSC1
              
            
WAIT           TST     ADCSC1 
                    BPL     WAIT
                                                                               
                    LDA     ADCRL   
                    ........................
 
But ADCRL it is always $00
 
I need some help  
That I am making bad
 
 
      
Labels (1)
0 Kudos
Reply
4 Replies

688 Views
bigmac
Specialist III
Hello, and welcome to the forum.

I will comment your code, and you can judge whether it meets your intention - I don't believe it does.


Zetta08 wrote:
I am using the QD2 and I have problems with the ADC
 
The instructions for Init_ADC init code are:
 
     LDA  #$18
     STA  SPMSC1

     LDA  #$F0
     STA  ADCCFG                                               
      
     MOV  #$01,ADCSC1  ; Commence conversion Ch 1
      
     LDA  #$02         ; Select Ch 1 for analog operation
     STA  APCTL1
 
In de Loop:
 
     BSET ADCSC1_ADCH1,ADCSC1
     ; Abort conversion & commence new conversion Ch 3

WAIT:
     TST  ADCSC1 
     BPL  WAIT         ; Loop until conversion complete
                                                                               
     LDA     ADCRL   
     ........................
 
But ADCRL it is always $00
 
    


Regards,
Mac


0 Kudos
Reply

688 Views
Zetta08
Contributor I

Hello Mac

 

For that say that  
BSET    ADCSC1_ADCH1,ADCSC1  ;it begins a new conversion in the channel CH3

 

In the Loop I use the following instructions but it always jumps to HAB_DISPARO

This means that ADCRL is always > #$64 (Not #$00, sorry)

 

LDA                 ADCRL                      

                      CMP     #$64
                      BHS     HAB_DISPARO             
             
INH_DISPARO    BSET    F_NIVEL,CONDICION
                      BRA     FIN_CICLO

HAB_DISPARO   BCLR    F_NIVEL,CONDICION  

..............................

 

Thank you and regards

Zetta08 

 

 

 

0 Kudos
Reply

688 Views
bigmac
Specialist III

Hello Zetta08,

 

I might have expected that your intent was to measure channel 1, rather than channel 3.  As you have not selected analog operation for channel 3 (APCTL1 register), it is possible that this input may have its digital pullup enabled, which may account for your observations.

 

I suggest that you don't use the BSET instruction for initiating a conversion - simultaneously write to all bits of the ADCSC1 register to reduce the confusion over what bits are already set.

 

   MOV  #$01,ADCSC1  ; Commence conversion Ch 1

or 

   MOV  #$03,ADCSC1  ; Commence conversion Ch 3

 

Regards,

Mac

 

0 Kudos
Reply

688 Views
Zetta08
Contributor I

Finally I found the solution.

 

It is necessary to disable the PTA1 before beginning the conversion.

 

In my case the correct instructions are:

 

Common initialization of the write once registers

 

        LDA     #$F0
        STA     ADCCFG

 

; ADCCFG: ADLPC=1,ADIV1=1,ADIV0=1,ADLSMP=1,MODE1=0,MODE0=0,ADICLK1=0,ADICLK0=0

 

In de loop:

 

              LDA     #$02                             ; Disable the Port PTA1 as I/O
              STA     APCTL1
              MOV     #$01,ADCSC1                ; It begins the convertion

                                                           ; Or:   BSET    ADCSC1_ADCH1,ADCSC1
          

WAIT       TST     ADCSC1                        ; Waits to that finishes the conversion                
              BPL     WAIT
                                                                  
              LDA     ADCRL

              . . . . . . . . . . .    

 

It works correctly

 

Thanks to all and greetings        

 

 

 

 

0 Kudos
Reply