• 0

[ASM] Sampling an inputted sine wave


Question

I'm working on this project for school... and here's the assignment:

  Quote
Input shall be a 100 Hz sinewave of amplitude 2 volts peak-to-peak with no offset. You are to take samples at 100 Hz, 200 Hz, and 300 Hz. There shall be 300 samples of each stored in the microprocessor memory. The results shall be sent to and stored in the PC for analysis using an application program.

The microprocessor I'm using is a Motorola M68HC08. The circuit is constructed using a USB->Serial Cable which connects the Tx/Rx of the cpu. Here is the current code (some was given, some wasn't). The idea is to read the Rx at obviously 100hz.. etc... I'm confused as to exactly what needs to be done. I figured: load the sampling rate into memory, decrement the register, get the sample, and loop until it's at 0. I'm just stuck on exactly how this needs to be implemented. Once that is done then I'm using Matlab to read what is outputted and displaying on a graph...

Can I get some help... if you can?

;ASSUMES PTA0 IS TX/RX
DDRA			 EQU	 $04
PTA			  EQU	 $00
;-----SCI PARAMETERS-------------
RXTXPIN		  EQU	 $0	  ;PIN PTA0
DATA_BITS		EQU	 $08
;NOTE- ONLY 1 STOP BIT IMPLEMENTED
;NOTE- PARITY NOT IMPLEMENTED
;---------------------------------
ADCCLK		   EQU	 $3F	 ;DEFINE ADCCLK
ADCSCR		   EQU	 $3C	 ;DEFINE ADCSCR
ADCDATA		  EQU	 $3E	 ;DEFINE ADCDATA

				ORG	  $EE00

start:		  mov	  #$31,$1f;disable COP, set 3V operation

			  ;PLACE your program between the lines
;--------------------------------------------------------------
;		  configure adc... continous conversion on.  3.2mhz clock
				MOV	   #0,ADCCLK	 ;configure ADC clock
				MOV	   #$21,ADCSCR;configure ADC statue control register

wait			bclr	  7,ADCSCR,wait


				lda	   $64
				deca
				bsr	   putstr		;output string
loop:		   bsr	   getbyte	;get a character
				bsr	   putbyte	;output it
				ldhx	  #command	  ;point to command string
				bsr	   putstr		;output it

				bra	   loop		  ;repeat forever
;--------------------------------------------------------------
			  ;putstr(HX)
putstr		  psha			  ;callee save
				pshx
				pshh
nextchr		 lda	 ,x		;get next character from string
				beq	 donestr;if zero, done
				bsr	 putbyte;else output it
				aix	 #1		;point to next char
				bra	 nextchr;repeat
donestr		 pulh			  ;callee restore
				pulx
				pula
				rts


			  ;putbyte(A)
putbyte		 pshx				  ;callee save
				psha
				bset	RXTXPIN,DDRA  ;set to TX
				bclr	RXTXPIN,PTA;output start bit
				bsr	 delbit		;wait 1 bit time
				ldx	 #DATA_BITS	;# data bits
nextb		   lsra				  ;shift next lsb out
				bcc	 zerob		 ;determine to send 0 or 1
oneb			bset	RXTXPIN,PTA;send '1'
				bsr	 delbit		;
				dbnzx   nextb
				bra	 stopb
zerob		   bclr	RXTXPIN,PTA;send '0'
				bsr	 delbit
				dbnzx   nextb
stopb		   bset	RXTXPIN,PTA;send 1 stop bit
				bsr	 delbit
				pula
				pulx
				rts

			  ;DELBIT()
delbit		  pshx						  ;delay approx 1/9600s
				ldx	 #!101
doit			dbnzx   doit
				pulx
				rts

			  ;A=GETBYTE()
getbyte		 bclr	RXTXPIN,DDRA		  ;set to input
gbpollst		brset   RXTXPIN,PTA,gbpollst  ;wait start bit
				bsr	 getbit				;get start bit
				bcs	 gbpollst			  ;check if false start
				lda	 #$80				  ;sentinel to catch done
bitlp		   bsr	 getbit				;get next bit (into C)
				rora						  ;shift it in
				bcc	  bitlp				;continue if not sentinel-done
				bsr	  getbit			;get stop bit
				rts

			  ;C=GETBIT()- uses majority vote algorithm, timed for 1 bit time
getbit		  pshx						  ;get one bit @9600 baud
				psha
				ldx	 #!31
				lda	 #!10
lloop		   brset   RXTXPIN,PTA,next	  ;test line value
next			sbc	 #0
				dbnzx   lloop
				rola
				pula
				pulx
				rts

command:		db	  " is the key you hit... do it again right now!",$0d,$0a,0
prompt:		 db	  "Type a key to begin...",$0d,$0a,0

DUMMYISR		RTI

				ORG	 $FDEB
			  ;interrupt redirect jump table- add a jump to your favority ISR
				JMP	 DUMMYISR	 ;Alternate ADC interrupt vector
				JMP	 DUMMYISR	 ;	'	 KBD wakeup '	'
				JMP	 DUMMYISR	 ;	'	 TOF		'	'
				JMP	 DUMMYISR	 ;	'	 Timer Ch.1 '	'
				JMP	 DUMMYISR	 ;	'	 Timer Ch.0 '	'
				JMP	 DUMMYISR	 ;	'	 IRQ		'	'
				JMP	 START		;	'	 RESET	  '	'

Link to comment
https://www.neowin.net/forum/topic/459315-asm-sampling-an-inputted-sine-wave/
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Fair shout! But the best way to get this on our news side would be to have Pulasti @LoneWolfSLhave a crack at Early Access when its in a playable state  
    • Interesting. Seems to promote or invite more people to use whatsapp.
    • AI is going to destroy online as well as offline worlds.
    • QOwnNotes 25.8.0 by Razvan Serea QOwnNotes is a open source (GPL) plain-text file notepad with markdown support and todo list manager for GNU/Linux, Mac OS X and Windows, that (optionally) works together with the notes application of ownCloud (or Nextcloud). So you are able to write down your thoughts with QOwnNotes and edit or search for them later from your mobile device (like with CloudNotes) or the ownCloud web-service. The notes are stored as plain text files and you can sync them with your ownCloud sync client. Of course other software, like Dropbox, Syncthing, Seafile or BitTorrent Sync can be used too. Features: the notes folder can be freely chosen (multiple note folders can be used) sub-string searching of notes is possible and search results are highlighted in the notes application can be operated with customizable keyboard shortcuts external changes of note files are watched (notes or note list are reloaded) older versions of your notes can be restored from your ownCloud server trashed notes can be restored from your ownCloud server differences between current note and externally changed note are showed in a dialog markdown highlighting of notes and a markdown preview mode notes are getting their name from the first line of the note text (just like in the ownCloud notes web-application) and the note text files are automatically renamed, if the the first line changes compatible with the notes web-application of ownCloud and mobile ownCloud notes applications compatible with ownCloud's selective sync feature by supporting an unlimited amount of note folders with the ability to choose the respective folder on your server manage your ownCloud todo lists (ownCloud tasks or Tasks Plus / Calendar Plus) or use an other CalDAV server to sync your tasks to encryption of notes (AES-256 is built in or you can use custom encryption methods like Keybase.io (encryption-keybase.qml) or PGP (encryption-pgp.qml)) dark mode theme support theming support for the markdown syntax highlighting all panels can be placed wherever you want, they can even float or stack (fully dockable) support for freedesktop theme icons, you can use QOwnNotes with your native desktop icons and with your favorite dark desktop theme support for hierarchical note tagging and note subfolders support for sharing notes on your ownCloud server portable mode for carrying QOwnNotes around on USB sticks Evernote import QOwnNotes is available in many different languages like English, German, French, Polish, Chinese, Japanese, Russian, Portuguese, Hungarian, Dutch and Spanish QOwnNotes 25.8.0 changelog: More warning log messages were ignored for Qt 6.9.1 Download: QOwnNotes 25.8.0 | 71.4 MB (Open Source) Download: QOwnNotes for Other Operating Systems View: QOwnNotes Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Patch My PC - Home Updater 5.3 Final is out.
  • Recent Achievements

    • Collaborator
      bullgod69 earned a badge
      Collaborator
    • Enthusiast
      Ed B went up a rank
      Enthusiast
    • Reacting Well
      Xinotema earned a badge
      Reacting Well
    • Dedicated
      Edward266 earned a badge
      Dedicated
    • First Post
      Markvens earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      760
    2. 2
      ATLien_0
      187
    3. 3
      +FloatingFatMan
      151
    4. 4
      Xenon
      118
    5. 5
      wakjak
      113
  • Tell a friend

    Love Neowin? Tell a friend!