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:
- Configure the ADC
- Start a conversion when ready
- Wait for a conversion to be completed (more advanced programs can do other stuff while it's waiting)
- Once a conversion is complete, get the data and process it
- Start another conversion (omit this step if SCAN mode is enabled)
- 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.