Generate sine wave program using PWM

Publisher:RainbowGardenLatest update time:2016-11-18 Source: eefocusKeywords:PWM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*******************************************************************
     Experiment name: Generate sine wave demonstration experiment
    device: ATmega16L
   crystal oscillator: external 12M
     wiring method:
        1. PD5 connects to low-pass filter input
     2. Use oscilloscope to measure its output waveform
******************************************************************/
#include
#include
#include
#pragma interrupt_handler timer1:9
char auc_SinParam[128]={//128-point sine wave sample value
128,134,140,147,153,159,165,171,177,182,188,193,198,204,208,213,
218,222,226,230,233,237,240,242,245,247,249,251,252,253,254,254,
254,254,253,252,251,250,248,246,244,241,238,235,232,228,2 24,220,
215,211,206,201,196,191,185,179,174,168,162,156,150,144,137,131,
125,119,112,106,100,94,88,82,77,71,65,60,55,50,45,41,
36,32,28,24,21,18,15,12,10,8,6,5,4,3,2,2,
2,2,3,4,5,7,9,11,14,16,19,23,26,30,34,38,
43,48,52,57,63,68,74,79,85,91,97,103,109,116,122,128 
};
char x=0;
//T/C1 overflow interrupt service
void timer1(void)
{
       x=x+1;
       if (x>128)
       x=0;
      OCR1A=auc_SinParam[x];//auc_SinParam[x];//Sampling point pointer to compare match register
}
void main(void)
{
      DDRD=0xff;//PB3 output mode, as OC0 output PWM wave
      TIMSK=0x04; //Interrupt mask bit, no interrupt is enabled
      TIFR=0; //Interrupt flag
      TCCR1A=0xA1; //Open PWM
      TCCR1B=0x09;//System clock
      SREG=0x80; //Open global interrupt
      OCR1A=128;//auc_SinParam[x];
}

Keywords:PWM Reference address:Generate sine wave program using PWM

Previous article:ATmega16 read and write 24Cxx program
Next article:ATmega16L serial communication program

Recommended ReadingLatest update time:2024-11-16 13:56

FAN6754 - Multi-function PWM Controller for Flyback Adapters
When you plug nearly any small computing or consumer electronic device into an electrical outlet, you'll find that the plug you hold is mostly connected to an external power supply (EPS). The EPS is essential to the working of all small electronic devices, with as many as 1.5 billion in use in the United States alone
[Power Management]
FAN6754 - Multi-function PWM Controller for Flyback Adapters
Dual-switch forward PWM DC/DC converter
The main circuit of the dual-tube forward PWM DC/DC converter is shown in Figure 1. The secondary circuit of its transformer is the same as that of the single-tube forward converter, but the primary winding is connected in series with the two switch tubes V1 and V2. The switch tubes V1 and V2 are turned on or off at
[Power Management]
Dual-switch forward PWM DC/DC converter
PIC32 Output Compare (PWM)
1. Output comparison initialization step: 1. Multiplexed port mapping to OCx      For example: RPA0Rbits.RPA0R=0b0101; that is, the RPA0 pin is used as peripheral OC1 2.OCM 2:0 : Output compare mode selection bit For example: OC1CON=0X06; //Output comparison port 1 is configured as PWM fault disable mode. 3.OC32 5 : 3
[Microcontroller]
PIC32 Output Compare (PWM)
Nuvoton M051 pwm usage program
#include "PWM.h" #define EN_EXT_OSC 0  #define COMPLEMENT_MODE 0x00000020 #define DEAD_ZONE_INTERVAL 0xC8FF0000 #define PWM_ENABLE 0x01010101   #if EN_EXT_OSC #define PWM_CLOCK_SOURCE 0x00000000 //Use external oscillator 12MHz #else  #define PWM_CLOCK_SOURCE 0xF0000000 //Use internal RC oscillator 22.1184MHz #end
[Microcontroller]
PWM Regulation Method Using Inductor
LED is a solid-state electric light source and a semiconductor lighting device. Its electrical characteristics are highly discrete. It has the characteristics of small size, high mechanical strength, low power consumption, long life, easy adjustment and control, and no pollution. It is a new light source product with
[Power Management]
PWM Regulation Method Using Inductor
51 MCU tracking car motor driver PWM
This is extracted from a successfully manufactured tracking car. Download address of schematic diagram and source code compressed package: http://www.51hei.com/bbs/dpj-19526-1.html The following is a preview of the main program files: #include reg52.h // Fast running sbit P00=P0^0; // Tracking port   sbit P01=P
[Microcontroller]
51 MCU tracking car motor driver PWM
STC12C5A60S2 internal PWM module program
/********************************************************************************************* Program name:     Author:   Writing time: 20 Year Month Day Hardware support:   Interface description:     Modification log:     NO.1-         /*************************************************************************
[Microcontroller]
Industrial standard signal generation and measurement instrument design
0 Introduction     This paper introduces the principle of industrial signal generation and measurement, and mainly studies the design of industrial signal generation and measurement instrument based on TI's MSP430F42x.     Industrial signal generation and measurement instrument is a very important detection instrument
[Microcontroller]
Industrial standard signal generation and measurement instrument design
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号