ADC to LED problem MC68HC12

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

ADC to LED problem MC68HC12

704 Views
laguna
Contributor I

I have code that is not working for the MC68HC12, it takes 0-5V into the
ADC and does some math to convert to revolutions per second and outputs
to 2 LED's. Could someone analyze the code to tell me in general what
might be wrong with the code. Some where I've think I've made a basic
mistake, I have not used the ADC before. I get not display on LED's.

 

The code is also attached.
      
     

        include 'MC9S12C128.inc'                org     $800          movb    #$FF, DDRB          movb    #$C0, ATDCTL2          movb    #$00, ATDCTL3          movb    #$00, ATDCTL4          ldaa    #1Wait      deca           bne     Wait          movb    #$20, ATDCTL5          ldab    ATDDR0H           ;AB will hold the input          loop      clra                    ;clear AA- AB holds converted input          ldab    #$80            ;test data -to be commented out          ldx     #51             ;relationship between digital number and BCD                   idiv                    ;as defined in prelab          stx     holder          ;holder holds the ones place          ldaa     #10            ;there will be a remainder. Want at least 1 decimal point accuracy          mul          ldx     #51             ;repeat dividing by 51          idiv              stx     holder2         ;holder2 holds the tenths place                                               ldd     holder          ;what follows is multiplying both the ones and teneths place by (18/5)          ldy     #18             ;as shown in pre-lab work          emul          std     holder          ldd     holder2          ldy     #18          emul          std     holder2          ldd     holder          ldx     #5          idiv          stx     holder          ldd     holder2          ldx     #5          idiv          stx     holder2          ldd     holder2         ;we then want to divide holder2 (tenths place) by 10 and add it to holder          ldx     #10             ;in order to get 1 number with which to continue calculation of RSP          idiv          xgdx          addd    holder          std     Va          ldd     #14             ;we want to add 1.4 to Va, per pre-lab work. divide 14 by 10 to achieve this          ldx     #10          idiv          stx     holder          std     holder2          ;remainder stored in holder2          ldd     Va          addd    holder          std     Va          ldd     holder2          ldx     #10          idiv          ldd     Va          addd    0,x          std     Va          ldy     #2                ;multiply by 2          emul              std     Va          ldd     #46               ;multiply by .46 = (46/100)          ldx     #100          idiv          stx     Va                 ;Va now contains RPS                    ldd     Va          cpd    #10          bge     output1          ldaa    #00           output1   ldd     Va                ;checks value of tens place of RPS          ldx     #10          idiv          stx     tensplace          ldd     tensplace          cpd     #1          beq     one1          ldd     tensplace          cpd     #2          beq     two1          ldd     tensplace          cpd     #3          beq     three1          ldd     tensplace          cpd     #4          beq     four1          ldd     tensplace          cpd     #5          beq     five1          ldd     tensplace          cpd     #6          beq     six1          ldd     tensplace          cpd     #7          beq     seven1          ldd     tensplace          cpd     #8          beq     eight1          ldd     tensplace          beq     nine1          ldaa    #00          one1      ldaa    one           ;will load appropriate hex number to have 7-seg display output two1      ldaa    two           ;appropriate numberthree1    ldaa    threefour1     ldaa    fourfive1     ldaa    fivesix1      ldaa    sixseven1    ldaa    seveneight1    ldaa    eightnine1     ldaa    nine            staa    tensplace                    ldd     Va                ;checks value of tens place of RPS          ldx     #10          idiv          stx     onesplace          ldd     onesplace          cpd     #1          beq     one2          ldd     onesplace          cpd     #2          beq     two2          ldd     onesplace          cpd     #3          beq     three2          ldd     onesplace          cpd     #4          beq     four2          ldd     onesplace          cpd     #5          beq     five2          ldd     onesplace          cpd     #6          beq     six2          ldd     onesplace          cpd     #7          beq     seven2          ldd     onesplace          cpd     #8          beq     eight2          ldd     onesplace          beq     nine1          ldaa    #00          one2      ldaa    one           ;will load appropriate hex number to have 7-seg display output two2      ldaa    two           ;appropriate numberthree2    ldaa    threefour2     ldaa    fourfive2     ldaa    fivesix2      ldaa    sixseven2    ldaa    seveneight2    ldaa    eightnine2     ldaa    nine            staa    onesplace                              movb    #$7C, DDRCAN   ;configure portcan for output (from textbook)          movb    #$FF, DDRP    ;configure portp for output          movb    tensplace, PORTP   ;place tens-place output code on portp          movb    #$40, PORTCAN       ;activate pcan6 so that led will illuminate with tensplace digit          movb    #$30, PORTCAN       ;activate pcan5          movb    onesplace, PORTP    ;illuminate ones-place output code          lbra     loop                    swiholder    rmb     2 holder2   rmb     2Va        rmb     2tensplace rmb     1onesplace rmb     1zero      equ     $7Eone       equ     $30two       equ     $6Dthree     equ     $79four      equ     $33five      equ     $5Bsix       equ     $5Fseven     equ     $70eight     equ     $7Fnine      equ     $7B PORTP     equ     $56PORTCAN   equ     $13E DDRCAN    equ     $13F                                              
Labels (1)
0 Kudos
2 Replies

458 Views
AirDragon
Contributor III

Ohhh boy, there's all sorts of nonsense in that program... you really need to solidify your program algorithm before doing any assembler coding, or else you'll get lost easily (especially in absolute assembler)!

 

 

Are you trying to use just 2 LED's on a 7-segment display?

0 Kudos

458 Views
AirDragon
Contributor III

Well, what's not working?

 

Are you using a development board for this chip, if so, which one?

 

Edit:

 

Ok, found it.

 

Your only checking the first data that came in... which is probably junk data becuase you didn't wait for a conversion to finish.

 

Scan mode does indeed make the ADC run continously, BUT, you have to have your program continuosly check to see if a conversion is completed. This can be done by checking the SCF flag in ATDSTAT0.

 

For ATD operations, you need to:

  1. Configure the ADC
  2. Start a conversion when ready
  3. Wait for a conversion to be completed (more advanced programs can do other stuff while it's waiting)
  4. Once a conversion is complete, get the data and process it
  5. Start another conversion (omit this step if SCAN mode is enabled)
  6. Repeat steps 3 to 5

 

Rethink your algorithm, and try placing down on paper in a graphical form, such as a flow chart.

 

It would probably be a good idea to disable Scan mode and have the program start a new conversion manually for the time being. Writing to the ATDCTL5 register will always start a new conversion, even if one is currently being process by the ADc module.

 

Highly suggest you read over Cahpter 8 of your MCU's user manual, and also ensure that your develpment board isn't using an ADC channel for something else.

 

0 Kudos