$regfile = "atXtiny412.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24
'set the system clock and prescaler
Config Sysclock = 16_20mhz , Prescale = 1
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
PORTA_PIN6CTRL = &H04 'We will not use TXD release
portmux_ctrlb=&B00000001 'alternative TXD
config porta.1=output 'setting alternative TXD to output
config vref=dummy,DAC0=4V3,ADC0=4V3
Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32,Reference = internal
'CONFIG ACI0 = on, OUTPUT=enable , HYSMODE=25 , MUX_INVERT=enable , MUXMIN=DAC , MUXPOS=AINP0 'cannot translate,error for all parameters
'config DAC
DAC0_CTRLA=&B00000001 'run DAC
'config TCD
TCD0_FAULTCTRL = &H01
TCD0_CMPACLR = 0
TCD0_CMPbCLR = 1023
TCD0_CTRLA = &B01100001
'config CCL
ccl_lut0ctrlb=&B01101001 'AC0 TCD
ccl_truth0=&B00001000 'AND ACO TCD
ccl_lut0ctrla=&B00001001 'OUT ,RUN LUT
ccl_ctrla=&B00000001 'Run CCL
'config AC
ac0_muxctrla=&B10000011 '
ac0_ctrla=&B00100101
dim current_fuse as word '
dim set_current as word
dim pom_current_fuse as word
dim zob_current_fuse as single
dim zob_set_current as single
do
set_current=getadc(2) 'value from the potentiometer of the desired current
current_fuse=getadc(3) 'value from the current fuse potentiometer
pom_current_fuse=current_fuse\4 'conversion from 10-bit to 8-bit number for writing to DAC
dac0_data=pom_current_fuse
zob_set_current= set_current*4300
zob_set_current=zob_set_current/1023
zob_set_current=zob_set_current/40
zob_current_fuse= current_fuse*4300
zob_current_fuse=zob_current_fuse/1023
zob_current_fuse=zob_current_fuse/40
print "Desired stream=" ; zob_set_current;" mA"
print "Settings current fuse=" ; zob_current_fuse;" mA"
TCD0_CMPACLR = set_current 'Requested stream value for PWM generation
'confirmation of the new value
TCD0_CTRLE = &B00000001
waitms 1000
loop |