Continue to Site

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.

How to generate pure sine wave from PIC micros? !!!

Status
Not open for further replies.

hassan1980

Full Member level 4
Full Member level 4
Joined
Jan 14, 2005
Messages
204
Helped
9
Reputation
18
Reaction score
6
Trophy points
1,298
Activity points
1,340
pic sine wave generator

Did anyone before deal with such thing?
 

pic sine wave

I haven't dealt with PIC but in AVR I have used Look-up table with precalculated sine-wave data. Just read and send out through DAC.
With PIC do the same:
Save one period sine-wave to like 256x8 size table in Program memory or another. then using DDS algorithm or simple read one by one end output to port where DAC is connected. DAC can be simple R/2R resistor ladder.
Here is what I've found for PIC: PIC signal generator
 
pic sine

You achieve it by use of built-in PWM circuit, reading a table.
Operating at frequencies above 60Hz waves, PIC's uC's have not enough speed. It should be better choice a processor containning a float point ALU, like a DSP.

At PIC, I Created a .XLS file to adjust maximum duty-cicle, and then filled that values at a static table.

Bellow, a piece of code, used at an UPS, using CCS C compiler :


Code:
////////////////////////////////////////////////////////////////////////
const unsigned int8 Duty0  [] = {7,15,23,31,38,46,53,61,68,75,82,88,95,101,107,113,118,123,128,133,137,141,144,147,150,153,155,156,158,159,159,160};  // 126 Vac@24Vdc
const unsigned int8 Duty1  [] = {7,15,23,30,38,45,52,60,67,74,80,87,93,99,105,111,116,121,126,130,134,138,142,145,148,150,152,154,155,156,157,157};
.......
const unsigned int8 Duty30 [] = {5,10,15,20,25,30,35,40,44,49,54,58,62,66,70,74,77,81,84,87,90,92,95,97,99,100,102,103,104,104,105,105};  // 117Vac@18Vdc
const unsigned int8 Duty31 [] = {5,10,15,20,25,30,35,39,44,49,53,57,61,65,69,73,77,80,83,86,89,91,94,96,97,99,100,102,102,103,103,104};
const unsigned int8 Duty32 [] = {5,10,15,20,24,29,34,39,43,48,52,57,61,65,69,72,76,79,82,85,88,90,92,95,96,98,99,100,101,102,102,102};
////////////////////////////////////////////////////////////////////////
void CarregaPWM ( void )
{
   if ( direcao == CRESCENTE ) PWM_counter++    ;
      else                     PWM_counter--    ;
   switch ( PWM_counter )
      {
      case 0  : NivelMinimo()   ;  set_pwm1_duty ( 0 )                 ; break ;
      case 1  :                    set_pwm1_duty ( Duty[PWM_counter] ) ; break ;
      case 2  :                    set_pwm1_duty ( Duty[PWM_counter] ) ; break ;
      ..........
      case 29 :                    set_pwm1_duty ( Duty[PWM_counter] ) ; break ;
      case 30 :                    set_pwm1_duty ( Duty[PWM_counter] ) ; break ;
      case 31 : NivelMaximo()    ; set_pwm1_duty ( Duty[PWM_counter] ) ; break ;
      }
}
////////////////////////////////////////////////////////////////////////
void AvaliaBateria ( void )
{
   switch ( NivelBateriaAtualizado )
      {
      case 0  : Duty[PWM_counter] = Duty0[PWM_counter]  ; Beep = CONTINUO     ; break ;
      case 1  : Duty[PWM_counter] = Duty1[PWM_counter]  ; Beep = CONTINUO     ; break ;
      .......
      case 31 : Duty[PWM_counter] = Duty31[PWM_counter] ; Beep = MUDO         ; break ;
      case 32 : Duty[PWM_counter] = Duty32[PWM_counter] ; Beep = MUDO         ; break ;
      }
}

+++
 

    hassan1980

    Points: 2
    Helpful Answer Positive Rating
pic sinewave

Hi,
I made a sine-wave stand-alone inverter, and here a sine-wave constants:

const long sine_wave[32] = {81,162,241,318,392,462,527,588,642,691,733,768,795,
815,827,831,827,815,795,768,733,691,642,588,527,462,
392,318,241,162,81,0};

This is a only for one half of sine-wave.
Best regards
 
sine wave generator pic

Actually, I don't have any idea about C programming.

on the other hand I am using PIC Basic Pro language, can you help me?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top