50 heryz mega16 - Hightechrobo Bin
  MARKDOWN   39

50 heryz mega16

Guest on 27th June 2022 08:03:57 AM

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

unsigned int sin_table[32]={0, 100, 199, 296, 390, 480, 566, 645, 718, 783, 840, 889, 928, 958, 979, 989, 989, 979, 958, 928, 889, 840, 783, 718, 645, 566, 480, 390, 296, 199, 100,0};

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_OLD, 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; if (TBL_POINTER_NEW < TBL_POINTER_OLD){ if (Direction == 0){ MOSA = 0; MOSD = 0; MOSB = 1; MOSC = 1; Direction = 1; } else{ MOSB = 0; MOSC = 0; MOSA = 1; MOSD = 1; Direction = 0; } } TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11; DUTY_CYCLE = TBL_POINTER_SHIFT; TBL_POINTER_SHIFT = sin_table[DUTY_CYCLE]; OCR1AH = TBL_POINTER_SHIFT >> 8; OCR1AL = TBL_POINTER_SHIFT & 0x0F; TBL_POINTER_OLD = TBL_POINTER_NEW; }

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); }



Add Comment

* Required information
1000
Drag & drop images (max 3)
Which is darker: black or white?
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.