udamonic.com
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
  • Create
    • Creating PCBs >
      • Designing PCBs
      • Fabricating PCBs
      • Soldering
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • FizzBuzz
    • Adding MRAM
    • Model Train Control
    • Adding a Real Time Clock
    • Scamp Projects on Youtube
  • Resources
  • Store
  • About
  • Contact
Your Scamp computer has a multi-channel 12-bit Analog to Digital Converter (ADC).
On a Scamp1/Scamp2 pins 1, 2, 3, 5, 6, 10, 11 can be assigned as analog inputs. The input voltage range is 0V to 3.3V. 
On a Scamp3 all pins except pin 8 can be assigned as analog inputs, giving you 11 channels of analog input. The input voltage range is 0V to 3.3V. 

Note: The datasheet for the PIC24FJ64GB202 processor indicates that RB15/AN9 (pin 12 on the Scamp1/Scamp2) is an analog input. This is an error on the datasheet, as RB15 is not available as an analog input on the PIC24FJ64GB202. See the Microchip Errata Sheet for more details.

Note: Pin 0 (AN2 on the PIC24) does not go down to 0 for a 0V input. A 0V input will read as a value of approx 20 or so. This is an issue with the PIC24 silicon and not your Scamp computer. I recommend using pin 0 only for analog inputs where approximate are acceptable. For more accurate results, use inputs 1..7 and 9..11. 

Sampling an Analog Input
​

The word adc12 will configure the ADC for 12-bit sampling, while adc10 will configure it for 10-bit sampling.
The word analog will configure a pin to be an analog input. The format is pin analog. For example, to make pin 2 an analog input:​
2 analog
To sample that analog input, first it must be selected as the current channel:
2 channel
Then the word sample performs the conversion and returns the result to the stack:​
sample
In addition to the input channels, channel 29 will sample the negative reference voltage AVss (GND) and channel 30 will select the positive reference voltage, AVcc (3.3V).
29 channel
​sample
will return 0​ to the stack, while 
30 channel
sample
will return 4096​.

Note that Scamp3s with BSP v1.4 have a bug where channel 4 doesn't allocate properly. This is fixed in BSP v1.5. To work around the bug in BSP v1.4, simply create the word  
       :  channel4  10  $228  !  ; 

This video shows you how to use analog inputs on a Scamp:

Setting the Conversion Clock
​

The ADC uses the system clock (Tcy) as the source for its conversion clock. On your Scamp, Tcy = 62.5 ns.

The word adcclk can be used to change the number of Tcy cycles used by the ADC. adcclk takes an 8-bit value from the stack (0..255). The conversion clock is equal to Tcy multiplied by this value plus 1.  
TAD = (n * TCY) + 1
For example, to make the conversion clock equal to 100 Tcy cycles:
#99 adcclk
The default setting for the conversion clock is 10, giving a conversion clock of 11 Tcy cycles (or 687.5 ns). On reset, the conversion clock resets back to 11 Tcy cycles. If you require a different setting, this should be configured in your initalization code. Note that a low value (fast conversion clock) may not give your ADC sufficient time to complete a conversion. The appropriate value depends on your application. For most simple applications, the default setting is fine.

Turning the ADC oFF and ON
​

The ADC module is enabled by default at reset. On a Scamp 3, you can turn off the module using the word adcoff. The module can be enabled using the word adcon. 

ADC Format
​

On a Scamp3, the word adcsgn lets you change the ADC format to a signed result, whereas adcunsgn lets you change the ADC format to an unsigned result.  The word adcfrac lets you change the ADC format to a left-justified fractional result, whereas adcdec lets you change the ADC format to a right-justified decimal result.

Learn : Interfacing : Analog Input
Site powered by Weebly. Managed by Hostwinds
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
  • Create
    • Creating PCBs >
      • Designing PCBs
      • Fabricating PCBs
      • Soldering
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • FizzBuzz
    • Adding MRAM
    • Model Train Control
    • Adding a Real Time Clock
    • Scamp Projects on Youtube
  • Resources
  • Store
  • About
  • Contact