Knowledge Base

Example: “Analog” timer setting using potentiometers

The SPice10211 contains two onboard potentiometers that can be used for various parameter setting applications. In this example potentiometer “Trim1” is used to control the duty cycle of an output pulse train on output 0. The pulse train generates one pulse every 2.55 seconds, with the width of the pulse being proportional to the setting on the potentiometer.

;TimePot.spt  Demo program for SPice10211 potentiometer

;Potentiometer Trim1 is read in and used to control the duration of an
;output pulse. A fresh pulse is started every 2.55 seconds using time 5,
;and its duration is varied between 0 and 2.55 seconds using timer 4

;The program is written for an MS12. The output pulse train is produced on output
;8 because that is a visible LED.

On 20 ;LCD backlight (just in case)

;Initialize the SPice connector for the SPice10211

ClrU
setu 0,3 ;set spice connector pin 4 as analog input
setu 1,3 ;set spice connector pin 5 as analog input
setu 2,3 ;set spice connector pin 6 as analog input
setu 3,3 ;set spice connector pin 7 as analog input
setu 4,4 ;set spice connector pin 8 as analog output
setu 5,4 ;set spice connector pin 9 as analog output
SpiceConfigU

Loop:
Test 5 ;Check if time for another pulse
GoIfT Loop
SetTimer 5,255 ;Restart the pulse interval timer

AnInF ;Read the potentiometer
float ;Convert to floating point
fSetTimer 4 ;Set pulse duration timer timer
ON 8
Timing:
Test 4 ;Check if pulse duration has expired
GoIfT Timing

Off 8
GoTo Loop