Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ATMEGA 16 16MHz SPWM Inverter in Bascom AVR - Need Help

Status
Not open for further replies.

ilacmano

Newbie level 6
Joined
Aug 30, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Croatia
Activity points
1,392
My hobby is electronic and wish to work inverter DC12V/AC220V 50Hz project in Bascom AVR with microcontroller Atmega16/32 16MHZ and need help.
For 1st step of project is write code for PWM positiv half cycle sine wave on PWM1A and negative half cycle on PWM1B with 32 samples every cycle.
On PWM1A/PWM1B connect 1K resistor IRFZ44N and transformer 2x12V/220V. Simulated in Proteus Isis on output transformer haven't sinusoidal curve measured by oscilloscope, and on PWM1A/PWM1B not have 10ms (20ms) half cycle.
Sine_Dat calculated on PWM Period 255.

I dont' know where is may error in code.

Code:
' Program : PWM Sine Wave 50Hz inverter.bas 
' Date : 05-06-12 
' Processor : ATMEGA 16/32 16 MHz 
' Input: Internal sine wave value table 
' Process : Pulse width modulation 

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

' variable
Dim Half_cycle As Byte
Dim Sine_table(32) As Byte ' sine_table
Dim Index As Byte ' Positive or Negativ Half_cycle
' Config Pin
Config Pind.5 = Output 'Pin OC1A - PWM1a
Config Pind.4 = 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 microsec 
'* Let Timer0 overflow after 312.5 us. 
'* Set prescaler to 64 *
'* 1 timer step = 64/16MHz = 4 us ; 312.5/4 = 78.12 
'* Preload value = 256 - 78. 
'************************************************* 

Config Timer0 = Timer , Prescale = 64 '64/16MHz = 4us

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 or PWM Freg 15.625 kHz for PWM = 9 bit

'restore Sine_dat 
For Index = 0 To 31
Sine_table(index + 1) = Lookup(index , Sine_dat) ' read sine_dat
Next Index

Index = 0
Half_cycle = 0 ' positiv sine cycle
'Pwm_count = 0

Enable Timer0 ' PWM Counter
Enable Interrupts

Do

Loop ' Loop forever

End ' end program

'************************ Interrupt0 ****************************************
Timer0_ovf:

Timer0 = 255 - 78 ' preload

If Half_cycle = 0 Then ' select half cycle positiv
Pwm1a = Sine_table(index + 1) ' positive half cycle
Pwm1b = 0
Elseif Half_cycle = 1 Then
Pwm1b = Sine_table(index + 1) ' 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 ' select negativ Half Cycle
Elseif Half_cycle = 1 Then
Half_cycle = 0 ' select positiv Half Cycle
End If
End If

Return

'**************** SINE WAVE DATA baase on PWM PERIOD 255 **********************
Sine_dat:
Data 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 , 0
 

naseerak

Full Member level 5
Joined
Jun 14, 2003
Messages
241
Helped
19
Reputation
38
Reaction score
19
Trophy points
1,298
Activity points
1,222
Hi ilacmano
I will suggest you to take this code to BASCOM where a lot of people will help you. As for I understand I do not see any error in your code, but you are wrong in driving IRFZ44n from UC you will have to insert a buffer between your mosfets and UC pin to amplify the gate voltage as this is not a logic level mosfet.Any how I will Take this code to Bascom for further refinement.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top