• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 7KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 5
    下载次数
  • 2016-01-25 15:08
    上传日期
太阳能逆变器追日用程序,主要应用在DSP2812上
suntrack.rar
  • suntrack.c
    34.3KB
内容介绍
#include <f2407_c.h> #include <stdio.h> #include <math.h> #define pi 3.1416 #define Ts1 0.001 #define Ts2 0.0001664 #define TRUE 1 #define FALSE 0 #define DAOUT1 0 #define DAOUT2 1 #define DAOUT3 2 #define ENABLEPWM 3 #define ADIN1 0 #define ADIN2 2 #define ADIN3 1 #define ADIN4 3 #define ADIN5 4 #define HI_5V 5.0 /* 0x0FFF = 5V */ #define LO_0V 0 #define START_KEY 0x0002 /* start bit = port C bit1 */ #define DAC0 port0000 /* EVM DAC register 0 (I/O space) */ ioport unsigned port0000; /* '24xx compiler specific keyword */ #define DAC1 port0001 /* EVM DAC register 1 (I/O space) */ ioport unsigned port0001; /* '24xx compiler specific keyword */ #define DAC2 port0002 /* EVM DAC register 2 (I/O space) */ ioport unsigned port0002; /* '24xx compiler specific keyword */ #define DAC3 port0003 /* EVM DAC register 3 (I/O space) */ ioport unsigned port0003; /* '24xx compiler specific keyword */ #define DACOUT port0004 /* EVM DAC update register (I/O space) */ ioport unsigned port0004; /* '24xx compiler specific keyword */ #define DIPSWCH port0008 /* EVM DIP switch (I/O space) */ ioport unsigned port0008; /* '24xx compiler specific keyword */ /* Sub routine Definitions */ /*sub routine must be declared here if it is defined after main() */ /* Global Variable Definitions */ int jj,indx,inphase_flag,L_R_flag,compare_flag,perturb_flag; float sin1[200],cos1[200]; float display_array[2048]; float display_array1[2048]; unsigned char start_flag,press_flag,old_press_flag,enable_flag; unsigned int portdata,adcdata,timer1_count,timer2_count; unsigned int LED_index; unsigned int dis_count; int AD3,oAD3; float stop_time,spin_time_R,spin_time_L; int L_R_flag,stop_flag; /* Constructure sin/cos table */ void init_table(void) { float a,b1,b2; a=0.0; for (jj=0;jj<100;jj++) { b1=sin(a); sin1[jj]=b1; sin1[jj+100]=b1; b2=cos(a); cos1[jj]=b2; cos1[jj+100]=b2; a=a+2*pi/100.0; } } float signn(float aa) { if (aa>0.0) return (1.0); else if (aa<0.0) return (-1.0); else return (0.0); } float abss(float bb) { if (bb >=0) return (bb); else return (-bb); } /*#define GPTCONA 7400h define GP timer control reg A */ /*#define T1CNT 7401h define GP timer 1 counter reg */ /*#define T1CMPR 7402h define GP timer 1 compare reg */ /*#define T1PR 7403h define GP timer 1 period reg */ /*#define T1CON 7404h define GP timer 1 control reg */ /*#define T2CNT 7405h define GP timer 2 counter reg */ /*#define T2CMPR 7406h define GP timer 2 compare reg */ /*#define T2PR 7407h define GP timer 2 period reg */ /*#define T2CON 7408h define GP timer 2 control reg */ /*#define EVAIFRA 742Fh Event Manager A Interrupt flag reg A */ /*#define EVAIFRB 7430h Event Manager A Interrupt flag reg B */ void set_timer12(void) { timer1_count = 0; timer2_count = 0; /* LDP #100h for change page code*/ /* DP_EVA .set 232 ;Event manager A (0x7400 - 0x747F) */ /* DP_EVB .set 234 ;Event manager B (0x7500 - 0x757F) */ /* LDP #DP_EVA ;set data page */ /* asm(" LDP #232 "); */ *GPTCONA = 0x0000; /* SPLK #0000000000000000b, GPTCONA * |||||||||||||||| * FEDCBA9876543210 * bit 15 0: reserved * bit 14 0: T2STAT, read-only * bit 13 0: T1STAT, read-only * bit 12-11 00: reserved * bit 10-9 00: T2TOADC, 00 = no timer2 event starts ADC * bit 8-7 00: T1TOADC, 00 = no timer1 event starts ADC * bit 6 0: TCOMPOE, 0 = Hi-z all timer compare outputs * bit 5-4 00: reserved * bit 3-2 00: T2PIN, 00 = forced low * bit 1-0 00: T1PIN, 00 = forced low */ /* SET TIMER 1 */ *T1CNT = 0x0000; /* clear timer counter */ /* asm(" SPLK #0000h,01h "); */ /* T1CNT address 7401h */ *T1PR = 0x0271; /* set timer period */ //*T1PR = 0x0064; /* 1/30MHz*128(prescaler)=0.033us*128=4.224us 00ECh(236) ==> 1ms(236*4.224us=996.864us) */ /* 1/40MHz*64(prescaler)=0.025us*64=1.6us 0271h(625) ==> 1ms(625*1.6us=1000us) */ /* asm(" SPLK #00ECh,03h "); 1.0 ms at 30MHz */ /* asm(" SPLK #0271h,03h "); 1.0 ms at 40MHz */ /* T1PR address 7403h */ *T1CON = 0x1640; /* configure T1CON register p.6-31 */ /* asm(" SPLK #1740h,04h "); at 30MHz */ /* asm(" SPLK #01640h,04h "); at 40MHz */ /* T1CON address 7404h */ /* bit 15-14 00: stop immediately on emulator suspend bit 13 0: reserved bit 12-11 10: 10 = continous-up count mode bit 10-8 110: 111 = x/128 prescaler 110 = x/64 bit 7 0: T2SWT1, 0 = use own TENABLE bit bit 6 1: TENABLE, 1 = enable timer bit 5-4 00: 00 = CPUCLK is clock source bit 3-2 00: 00 = reload compare reg on underflow bit 1 0: 0 = disable timer compare bit 0 0: SELT1PR, 0 = use own period register */ *EVAIFRA = 0x00FF; /* all clear T1PINT flag p.6-86*/ /* asm(" SPLK #00FFh,2Fh "); clear all flag */ /* EVAIFRA address 742Fh */ /* bit 15-11 0: reserved bit 10 0: T1OFINT FLAG(T1 Overflow Interrupt) 0:No effect 1:Reset flag bit 9 0: T1UFINT FLAG(T1 Underflow Interrupt) 0:No effect 1:Reset flag bit 8 0: T1CINT FLAG(T1 Compare Interrupt) 0:No effect 1:Reset flag bit 7 1: T1PINT FLAG(T1 Period Interrupt) 0:No effect 1:Reset flag bit 6-4 1: reserved bit 3 1: CMP3INT FLAG(Full Compare3 Interrupt) 0:No effect 1:Reset flag bit 2 1: CMP2INT FLAG(Full Compare2 Interrupt) 0:No effect 1:Reset flag bit 1 1: CMP1INT FLAG(Full Compare1 Interrupt) 0:No effect 1:Reset flag bit 0 1: PDPINTA FLAG(Power Drive Protect Interrupt A) 0:No effect 1:Reset flag */ *EVAIMRA = 0x0080; /* enable T1PINT Interrupt p.6-90 */ /* asm(" SPLK #0080h,2Ch "); enable T1PINT Interrupt */ /* asm(" LDP #100h "); */ /* bit 15-11 0: reserved bit 10 0: T1OFINT(T1 Overflow Interrupt) ENABLE 0:Disable 1:Enable bit 9 0: T1UFINT(T1 Underflow Interrupt) ENABLE 0:Disable 1:Enable bit 8 0: T1CINT (T1 Compare Interrupt)ENABLE 0:Disable 1:Enable bit 7 1: T1PINT (T1 Period Interrupt)ENABLE 0:Disable 1:Enable bit 6-4 0: reserved bit 3 0: CMP3INT (Full Compare3 Interrupt)ENABLE 0:Disable 1:Enable bit 2 0: CMP2INT (Full Compare2 Interrupt)ENABLE 0:Disable 1:Enable bit 1 0: CMP1INT (Full Compare1 Interrupt)ENABLE 0:Disable 1:Enable bit 0 0: PDPINTA (Power Drive Protect Interrupt A)ENABLE 0:Disable 1:Enable p.s Enabled following reset */ /* SET TIMER2 */ *T2CNT = 0x0000; /* clear timer counter */ /* asm(" SPLK #0000h,05h "); */ /* *T2PR = timer2_per; set timer period */ /* SPLK #002fh, T2PR */ *T2PR = 0x0067; /* 166.4us */ /* asm(" SPLK #0064h,07h ");*/ /* #64h=0.16ms #0Ah=0.016ms */ /* 1/40MHz*64(prescaler)=0.025us*64=1.6us 0064h(100) ==> 0.16ms(100*1.6us=160us) */ *T2CON = 0x1640; /*
评论
    相关推荐