50 hz - Hightechrobo Bin
  MARKDOWN   36

50 hz

Guest on 27th June 2022 07:55:02 AM

Code: //---------------------------------------------------------------------------------------- //Programmer: Syed Tahmid Mahbub //Target Microcontroller: ATMEGA16 //Compiler: mikroC PRO for AVR (Can easily port to any other compiler) //-----------------------------------------------------------------------------------------

[COLOR="#FF0000"] unsigned int sin_table[128]={0, 24, 49, 73, 98, 122, 146, 171, 195, 219, 242, 266, 290, 313, 336, 359, 382, 404, 426, 448, 470, 491, 513, 533, 554, 574, 594, 613, 632, 651, 669, 687, 704, 721, 738, 754, 770, 785, 799, 814, 827, 841, 853, 865, 877, 888, 899, 909, 918, 927, 935, 943, 950, 957, 963, 968, 973, 977, 981, 984, 986, 988, 989, 990, 990, 989, 988, 986, 984, 981, 977, 973, 968, 963, 957, 950, 943, 935, 927, 918, 909, 899, 888, 877, 865, 853, 841, 827, 814, 799, 785, 770, 754, 738, 721, 704, 687, 669, 651, 632, 613, 594, 574, 554, 533, 513, 491, 470, 448, 426, 404, 382, 359, 336, 313, 290, 266, 242, 219, 195, 171, 146, 122, 98, 73, 49, 24,0}; [/COLOR] //sine table with 128 entries, Peak value as 999 and 127 entries, zero at the end makes it 128

define MOSA PORTD0_bit

define MOSB PORTD1_bit

define MOSC PORTD2_bit

define MOSD PORTD3_bit

unsigned char FlagReg;

define Direction FlagReg.B0

//0 -> MOS A + D //1 -> MOS B + C

unsigned int TBL_POINTER_NEW, TBL_POINTER_SHIFT, SET_FREQ; unsigned int TBL_temp; unsigned char DUTY_CYCLE;

void interrupt() org IVT_ADDR_TIMER1_OVF{ TBL_POINTER_NEW = TBL_POINTER_NEW + SET_FREQ; //sending signal every 10 ms, if (Direction == 0){ MOSA = 0; MOSD = 0; MOSB = 1; MOSC = 1; Direction = 1; } else{ MOSB = 0; MOSC = 0; MOSA = 1; MOSD = 1; Direction = 0; } [COLOR="#FF0000"] TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 9; [/COLOR] //TBL_POINTER_NEW is shifted 9 times instead of 11. DUTY_CYCLE = TBL_POINTER_SHIFT; TBL_POINTER_SHIFT = sin_table[DUTY_CYCLE]; OCR1AH = TBL_POINTER_SHIFT >> 8; OCR1AL = TBL_POINTER_SHIFT & 0x0F; }

void main() { SET_FREQ = 410; TBL_POINTER_SHIFT = 0; TBL_POINTER_NEW = 0; TBL_POINTER_OLD = 0; DUTY_CYCLE = 0; DDRC = 0xFF; DDRD = 0XFF; OCR1AH = 0; OCR1AL = 0; TCCR1A = 0x82; ICR1H = 0x03; ICR1L = 0xE7; //ICR1 = 999 -> TOP -> 16kHz TIMSK = 0x04; TCCR1B = 0x19; SREG_I_bit = 1; while(1); } Last edited: Jun 11, 2014

Jun 11, 2014

15

KlausST KlausST Super Moderator Staff member Hi,

Please make a test or simulation. The remark says that timer1_ovf happens every 10ms, but it needs to be more often...

There should be 128 table enties plus the limitin 0 giving 129 entries. Peak in sine table is 990 but remark say 999. I think 990 is ok.

Please try it and write what happens.. Klaus

Jun 11, 2014

16

AtMega32 Junior Member level 3 I h



Add Comment

* Required information
1000
Drag & drop images (max 3)
What is the opposite word of small?
Captcha Image
Powered by Commentics

Comments

No comments yet. Be the first!

Raw Paste


Login or Register to edit or fork this paste. It's free.