Pedro Vinicius Machado Borges

10-bit ADC to 10-bit PWM

Discussion created by Pedro Vinicius Machado Borges on Jul 6, 2011
Latest reply on Jul 8, 2011 by bigmac

Hello people!

 

I'm new with HCS08 and I'm having a problem in HOW to Send the ADCR to the PWM output.

 

We're using the MC9S08QG8 with Assembly language.

 

 

Here's the code:

 

 

;*******************************************************************
;* This stationery serves as the framework for a user application. *
;* For a more comprehensive program that demonstrates the more     *
;* advanced functionality of this processor, please see the        *
;* demonstration applications, located in the examples             *
;* subdirectory of the "Freescale CodeWarrior for HC08" program    *
;* directory.                                                      *
;*******************************************************************

; Include derivative-specific definitions
            INCLUDE 'derivative.inc'
;
; export symbols
;
            XDEF _Startup
            ABSENTRY _Startup

;
; variable/data section
;
            ORG    RAMStart         ; Insert your data definition here
ExampleVar: DS.B   1

;
; code section
;
            ORG    ROMStart

_Startup:
      LDA #%01100001
      STA ADCSC1                                                                       
      LDA APCTL1
      BSET 2, APCTL1
      LDA #%0100000
      STA ADCSC2
      LDA #%00110100
      STA ADCCFG
      LDA #%00001000
      STA TPMSC
      LDA #%00100000
      STA PTBDD
      BSET 5, PTBD
      LDA #%00000010
      STA PTADD
      BSET 1, PTAD

      LDA #$02
      STA SOPT1
      LDHX   #RAMEnd+1        ; initialize the stack pointer
      TXS
      CLI                     ; enable interrupts



        

mainLoop:
 
    
    
    
      BSR RandW

      NOP

     ; feed_watchdog
        BRA    mainLoop

  RandW:  ;function to read and write at the Channel 1 of the tpm
      LDHX ADCRH
      STHX TPMC1V
      RTS
;**************************************************************
;* spurious - Spurious Interrupt Service Routine.             *
;*             (unwanted interrupt)                           *
;**************************************************************
spurious:                           ; placed here so that security value
            NOP                     ; does not change all the time.
            RTI

;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
            ORG   $FFFA

            DC.W  spurious          ;
            DC.W  spurious          ; SWI
            DC.W  _Startup          ; Reset

 

 

We really don't know if we need interruptions or what.

 

 

Att,

Pedro Vinícius.

 

(Computer's Engineering student)

Outcomes