Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Current supply

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 118

blank.gif
PostPosted: Fri Mar 12, 2021 4:25 pm    Post subject: Current supply Reply with quote

Greetings
Next sample program for xttiny.
A simple current supply with a fuse.
He's using CCL,TCD,ACI,ADC,DAC, so we've compiled a little bit.
I was also asked for an idea scheme and what it might look like, so I enclose a schematic and a 3D model.

Code:

   $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




RS
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum