Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Quick adc to measure the pins xmega

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
sackoizo

Bascom Member



Joined: 17 Feb 2015
Posts: 12

PostPosted: Sat Mar 21, 2015 12:22 pm    Post subject: Quick adc to measure the pins xmega Reply with quote

Welcome! It needs a bit of code to adc in the XMEGA. I measured peak power changes in the order of microseconds + - 1 volt from the norm (5V). Please help.

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 919
Location: France

france.gif
PostPosted: Sat Mar 21, 2015 2:51 pm    Post subject: Reply with quote

hello,
Did you watch the help: ADC?
You will find a superb example of ADC for mega and atmege and all the necessary information.

Bon courage

JP Wink
Back to top
View user's profile Visit poster's website
sultanm9000

Bascom Member



Joined: 23 Aug 2014
Posts: 40

uk.gif
PostPosted: Sat Mar 21, 2015 4:38 pm    Post subject: Reply with quote

'The AUTO feature, will select the highest clockrate possible

Config Adc = Single , Prescaler = Auto , Reference = Avcc
'Now give power to the chip
Start Adc

'With STOP ADC, you can remove the power from the chip
'Stop Adc

Dim W As Word , Channel As Byte

'now read A/D value from channel 0
Do
W = Getadc(channel)
Print "Channel " ; Channel ; " value " ; W
Incr Channel
If Channel > 7 Then Channel = 0
Waitms 500
Loop
End
Back to top
View user's profile
sackoizo

Bascom Member



Joined: 17 Feb 2015
Posts: 12

PostPosted: Sat Mar 21, 2015 4:48 pm    Post subject: Reply with quote

For XMEGA does not work the auto. And maybe some code for XMEGA checking how fast the ruler in khz for different frequencies. I checked now at 2MHz pll x31 = 62MHz and looks the same as for the 32MHz. Any suggestions
Edit1
I took the code that checks the samples folder: xm128A1_measure_adc_a_signed_single_ended_mode.bas
Back to top
View user's profile
sultanm9000

Bascom Member



Joined: 23 Aug 2014
Posts: 40

uk.gif
PostPosted: Sat Mar 21, 2015 5:02 pm    Post subject: Reply with quote

Put the work file here
Back to top
View user's profile
sackoizo

Bascom Member



Joined: 17 Feb 2015
Posts: 12

PostPosted: Sat Mar 21, 2015 5:12 pm    Post subject: Reply with quote

Code:

$regfile = "xm128a4udef.dat"
$crystal = 62000000                                         '32MHz
$hwstack = 128
$swstack = 128
$framesize = 128

$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014

Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled       '32MHz
Config Sysclock = 32mhz                                     '32Mhz
'(Dim A As Byte
Out &H50 , &B00000001                                       ' enable  2MHz Oscillator
Out &H55 , &B00011111                                       'PLL Clocksource = 2MHz internal Osc.
'                                                           ,Multiplicator = 16 to get 32 MHz Out
Out &H34 , &HD8                                             'No write protection for 4 cycles
Out &H41 , &B00000000                                       'Prescaler= No division Prescaler A, B and C
While A.0 = 0                                               'Wait for 2MHz Osc. to be ready
   A = Inp(&H51)
Wend
Out &H50 , &B00010001                                       ' enable  PLL
While A.4 = 0                                               'Wait for PLL to be ready
   A = Inp(&H51)
Wend
Out &H34 , &HD8                                             'No write protection for 4 cycles                                         '
Out &H40 , &B00000100                                       'Select PLL as system Clock
Out &H34 , &HD8                                             'No write protection for 4 cycles                                         '
Out &H42 , &B00000001                                       'Lock System Clock Settings
')
'Config Priority = Static , Vector = Application , Lo = Enabled       'config interrupts
'Enable Interrupts

$lib "glcdeadogm128x6.lbx"
Config Graphlcd = 128 * 64eadogm , Cs1 = Portc.4 , A0 = Portc.1 , Si = Portc.5 , Sclk = Portc.7 , Rst = Portc.0
Glcdcmd 141                                                 '&B10001101                                          'pętla zmieniająca kontrast co sekunde
Glcdcmd 32
Waitms 10
Glcdcmd 141                                                 '&B10001101                                          'pętla zmieniająca kontrast co sekunde
Glcdcmd 38
Setfont My6_8                                               'My12_16
Cls
Dim Tick As Long
Tick = 0
Dim Ttt As Long
Config Adca = Free , Convmode = Signed , Resolution = 12bit , Dma = Off , Reference = Intvcc , Event_mode = None , Prescaler = 16 , _
Ch0_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B00000000   'Setup Channel 0 in Single Ended Mode
' ADC Clock = 32MHz/512 = 62.5 KHz

Config Tcc0 = Normal , Prescale = 1024
Tcc0_per = 0                                                '31250       '32MHz/1024 = 31250
On Tcc0_ovf Tc0_isr                                         'Setup overflow interrupt of Timer/Counter C0 and name ISR
Enable Tcc0_ovf , Lo                                        'Enable overflow interrupt in LOW Priority
Enable Interrupts
Config Priority = Static , Vector = Application , Lo = Enabled

Dim Mensure As Word
Dim Mensurepom As Long
Dim Minn As Word
Minn = 9999
Mensure = 0
Mensurepom = 9999
Dim Tttt As Integer

Dim Measurement As Word
Dim Single_measurment As Single
Dim Single_measurment1 As String * 10
Dim Single_measurment2 As String * 10

Dim I As Byte



Do


For Mensurepom = 0 To 10000
Measurement = Getadc(adca , 0 , &B00000000)
If Measurement < Minn Then Minn = Measurement
Next Mensurepom
Lcdat 1 , 1 , Tick
Lcdat 2 , 1 , Measurement
Wait 1
Tick = 0

Loop

End


Tc0_isr:
'Lcdat 2 , 1 , "tick"
Incr Tick
'Onlyfortesting
Return

$include "font8x8TT.font"
$include "my12_16.font"
$include "my6_8.font"
 


the code works but how to check how quickly measure adc?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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