Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Table pointer
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Fri Oct 31, 2014 5:33 pm    Post subject: Reply with quote

Can any body tell me how much time GETADC() will take to complete.
Back to top
View user's profile
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Fri Oct 31, 2014 7:32 pm    Post subject: Reply with quote

Sorry for the multiple posts due to page refresh error.
Thanks God I have started the things in the right direction now with encouragement from Adrianj and specialty MWS for making me believe in BASCOM, my code has started responding to the ADC variation, but its very strange that though my ADC variable is a word but it goes to a maximum of 200 though I have based my calculations on maximum value of 200 (0 to 200) but this is temporary and i will move forward with the real values on the word variable, I don,t want to convert this 10 bit value to 8 bit as it will steal some cycles and the 8 bit value is not necessary as I just want to find the maximum, middle, and maximum value of the ADC measuring the voltage from the out put of the transformer.

'*****************************************************************************
' Program : PWM Sine Wave 50Hz inverter.bas
' Date : 23-10-14
' Processor : ATMEGA8
' Input: Internal sine wave value table
' Process : Pulse width modulation
'*****************************************************************************

$regfile = "m8def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 128 ' default use 128 for the hardware stack
$swstack = 64 ' default use 64 for the SW stack
$framesize = 64

' variable


Dim W As Word
Dim Y As Byte
Dim X As Byte
Dim Index As Byte
Dim Half_cycle As Byte
Dim Sine_table(32) As Byte ' Sine_table



' Config Pin
Config Pind.5 = Output 'Pin OC1A - PWM1a
Config Pind.4 = Output 'Pin OC1B - PWM1b
Config Pinb.0 = Output 'Pin OC1A - PWM1a
Config Pind.7 = Output 'Pin OC1B - PWM1b

'******************************************************************
'* Halfperiod = 10 ms
'* There are 32 pwm values in a half period 10ms/32
'* We need to change the OCR value every 10000/32 =312,5 us
'*
'* Let Timer0 overflow after 312.5 us
'* Set Timer0 Prescaler to 64
'* Timer0 step = 64/8MHz = 8 us ; 312,5.0/8 = 39.0625 us
'* Preload value = 255 - 39
'******************************************************************

Config Timer0 = Timer , Prescale = 64 '64/8MHz = 8us
Config Adc = Single , Prescaler = Auto , Reference = Internal
Start Adc
Enable Ovf0
On Ovf0 Timer0_ovf

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 1
'********************************************************
'* PWM Freq 31.25 kHz for PWM = 8 bit
'* PWM Freg 15.625 kHz for PWM = 9 bit
'********************************************************
Disable Timer0
'Enable Timer0 ' PWM Counter
'Enable Interrupts
Disable Interrupts


Start Timer1


Half_cycle = 0 ' Positiv Sine Cycle

Do

Gosub Correction
Print "W" ; W

Loop ' Loop Forever

End ' End Program

'************************ Interrupt0 ****************************************

Correction:
Enable Interrupts
Enable Timer0

For Index = 0 To 31

W = Getadc(0)
Select Case W

Case 151 To 200 : Sine_table(index + 1) = Lookup(index , Sine_dat0)

Case 81 To 150 : Sine_table(index + 1) = Lookup(index , Sine_dat1)

Case 71 To 80 : Sine_table(index + 1) = Lookup(index , Sine_dat2)

Case 61 To 70 : Sine_table(index + 1) = Lookup(index , Sine_dat3)

Case 51 To 60 : Sine_table(index + 1) = Lookup(index , Sine_dat4)

Case 41 To 50 : Sine_table(index + 1) = Lookup(index , Sine_dat5)

Case 31 To 40 : Sine_table(index + 1) = Lookup(index , Sine_dat6)

Case 21 To 30 : Sine_table(index + 1) = Lookup(index , Sine_dat7)

Case 11 To 20 : Sine_table(index + 1) = Lookup(index , Sine_dat8)

Case 0 To 10 : Sine_table(index + 1) = Lookup(index , Sine_dat9)

End Select

Next Index
'Enable Timer0
'Enable Interrupts

Return



Timer0_ovf:

Timer0 = 255 - 39

If Half_cycle = 0 Then ' Select Half Cycle Positiv
Pwm1a = Sine_table(index + 1) ' PWM Positive Half Cycle
Pwm1b = 0
Else
Pwm1b = Sine_table(index + 1) ' PWM Negativ Sine Cycle
Pwm1a = 0
End If

Incr Index ' Increments Index for "1"

If Index => 32 Then
Index = 0 ' Reset Index to "0"
If Half_cycle = 0 Then
Half_cycle = 1 ' Negativ Sine Cycle
Else
Half_cycle = 0 ' Positive Half Cycle

End If
End If

Return

'************ SINE WAVE DATA 32 samples base on PWM PERIOD 255 *************
Sine_dat0:
Data 0 , 25 , 50 , 74 , 98 , 120 , 142 , 162 , 180 , 197 , 212 , 225 , 235 , 244 , 250 , 254 , 255 , 254 , 250 , 244 , 235 , 225 , 212 , 197 , 180 , 162 , 142 , 120 , 98 , 74 , 50 , 25

Sine_dat1:
Data 0, 23, 46, 68, 90, 111, 131, 149, 166, 182, 195, 207, 217, 225, 230, 234, 235, 234, 230, 225, 217, 207, 195, 182, 166, 149, 131, 111, 90, 68, 46, 23

Sine_dat2:
Data 0, 22, 44, 65, 86, 106, 125, 143, 159, 174, 187, 198, 208, 215, 221, 224, 225, 224, 221, 215, 208, 198, 187, 174, 159, 143, 125, 106, 86, 65, 44, 22

Sine_dat3:
Data 0, 21, 42, 62, 82, 101, 119, 136, 152, 166, 179, 190, 199, 206, 211, 214, 215, 214, 211, 206, 199, 190, 179, 166, 152, 136, 119, 101, 82, 62, 42, 21

Sine_dat4:
Data 0, 20, 40, 60, 78, 97, 114, 130, 145, 158, 170, 181, 189, 196, 201, 204, 205, 204, 201, 196, 189, 181, 170, 158, 145, 130, 114, 97, 78, 60, 40, 20

Sine_dat5:
Data 0, 19, 38, 57, 75, 92, 108, 124, 138, 151, 162, 172, 180, 187, 191, 194, 195, 194, 191, 187, 180, 172, 162, 151, 138, 124, 108, 92, 75, 57, 38, 19

Sine_dat6:
Data 0, 18, 36, 54, 71, 87, 103, 117, 131, 143, 154, 163, 171, 177, 181, 184, 185, 184, 181, 177, 171, 163, 154, 143, 131, 117, 103, 87, 71, 54, 36, 18

Sine_dat7:
Data 0, 17, 34, 51, 67, 82, 97, 111, 124, 135, 146, 154, 162, 167, 172, 174, 175, 174, 172, 167, 162, 154, 146, 135, 124, 111, 97, 82, 67, 51, 34, 17

Sine_dat8:
Data 0, 16, 32, 48, 63, 78, 92, 105, 117, 128, 137, 146, 152, 158, 162, 164, 165, 164, 162, 158, 152, 146, 137, 128, 117, 105, 92, 78, 63, 48, 32, 16

Sine_dat9:
Data 0, 15, 30, 45, 59, 73, 86, 98, 110, 120, 129, 137, 143, 148, 152, 154, 155, 154, 152, 148, 143, 137, 129, 120, 110, 98, 86, 73, 59, 45, 30, 15
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2482
Location: Queensland

australia.gif
PostPosted: Sat Nov 01, 2014 2:23 am    Post subject: Reply with quote

Not easily. Because you set the ADC config with prescaler = AUTO, Bascom chooses an ADC clock prescaler value based on the processor clock and what it thinks is a good compromise between speed and accuracy. You would have to read out the value if the ADC control register, figure out which are the prescaler bits, consult the Atmel manual for the processor, and then figure out what that means in terms of ADC read time.

A more direct method, if you have an oscilloscope, you could pulse a spare port line high at the beginning of the ADC read, and low after, then read off the time.

Likewise in software you could read the value of timer1 just before and just after the conversion, and subtract the two to get the time diff.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Sat Nov 01, 2014 3:45 pm    Post subject: Reply with quote

My mistake I did,nt powered AVCC pin, one more question how I would know that ADC has finished its conversion.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2482
Location: Queensland

australia.gif
PostPosted: Sun Nov 02, 2014 10:57 pm    Post subject: Reply with quote

ADC conversion is finished when GetADC returns from its wait. For more details, see the Atmel processor manual.
As has already been suggested, putting the GetADC inside an interrupt service routine is a really bad idea. Interrupts are for things you want serviced REALLY FAST, and you dont want to delay that by waiting 100s of clock cycles for something like an ADC conversion.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Mon Nov 03, 2014 8:57 am    Post subject: Reply with quote

I hust want to know the the time it takes for conversion
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2482
Location: Queensland

australia.gif
PostPosted: Tue Nov 04, 2014 6:14 am    Post subject: Reply with quote

Did you read my post about 3 back, on 1st November ?
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
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