CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Software pwm

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Macko77



Joined: 01 Dec 2013
Posts: 5

View user's profile Send private message MSN Messenger

Software pwm
PostPosted: Sun Dec 01, 2013 2:40 pm     Reply with quote

Good Friends, I come to you to see who can help me with the insertion of a PWM by software in a project I'm doing.

I tell the project that we perform is integrating an acquisition card and Matlab, through signal processing matlab to design a system of light control. For now the pic just turns on and off lights controlled enclosure depending on the character you I sent matlab. Now through an address I will do on camera matlab detect a pattern and modify the intensity of the lights.

I was reading and the best solution is to perform a software PWM, but really do not know much programming the single basic pic, I wonder if someone could help me on this, it is urgent!

This is the code I've been in so far ccs
Code:

#include <18F4550.h> // Definición de registros internos.
#fuses HSPLL,MCLR,NOWDT,NOPROTECT,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,NOLVP
#use delay(clock=20000000) // Frecuencia máxima de trabajo 20 Mhz

#use fast_io(A)
#use standard_io(B)
#use standard_io(D)

#include "usb_cdc.h" // Descripción de funciones del USB, entre comillas es porque esta trabajando sobre la misma carpeta
#include "usb_desc_cdc.h" // Descriptores del dispositivo USB.

void main() {
   int sal1, sal2;
   unsigned char datoIN;
   usb_cdc_init(); // Configuramos al puerto virtual.
   usb_init(); // Inicializamos el stack USB.
   set_tris_B(0x00); // Configuro el puerto b salida

   while(!usb_cdc_connected())
   {
      OUTPUT_HIGH(PIN_E0);
      OUTPUT_LOW(PIN_E1);
      DELAY_MS(500);
      OUTPUT_HIGH(PIN_E1);
      OUTPUT_LOW(PIN_E0);
   }
   // espera a detectar una transmisión de la PC (Set_Line_Coding).
   
   OUTPUT_HIGH(PIN_E0);
   OUTPUT_LOW(PIN_E1);
 
   sal1=0; //Inicializo Variables alternativas
   sal2=0; //Inicializo Variables alternativas
 
  do{
      usb_task();
         //////////////////////////////////////////////////////
           
      if (usb_enumerated())
      {  // Espera a que el dispositivo sea enumerado por el host.
         OUTPUT_LOW(PIN_E0);
         OUTPUT_HIGH(PIN_E1);
         if(usb_cdc_kbhit())
         { // En espera de nuevos caracteres en el buffer de recepción.
            datoIN = usb_cdc_getc();
           
            if(datoIN == 'a')
            { //¿lo que llegó fué el caracter a = hay movimiento en el salon 1 y esta en el nivel mas alto?
               OUTPUT_HIGH(PIN_B1);
               sal1=1; //si, entonces se prenden las luces del salon 1
            }
            if(datoIN == 'b')
            { // ¿lo que llegó fué el caracter b = hay movimiento en el salon 1 y esta en el nivel 2?
         
            }
            if(datoIN == 'c')
            { // ¿lo que llegó fué el caracter c = hay movimiento en el salon 1 y esta en el nivel 3?
            }
            if(datoIN == 'd')
            { // ¿lo que llegó fué el caracter d = hay movimiento en el salon 1 y esta en el nivel 4?
            }
            if(datoIN == 'g')
            { //¿lo que llegó fué el caracter g = no hay movimiento en el salon 1?
               OUTPUT_LOW(PIN_B1);
               sal1=2;
               //si, entonces se apagaran las luces del salon 1
            }
            if (sal1==1) // Pregunto por variable del salon
            {
            OUTPUT_HIGH(PIN_B2); // Prende Led Indicador
            }
            else
            {
            OUTPUT_LOW(PIN_B2); // Prende Led Indicador
            }           
           }
       }       
   }while (TRUE); // bucle infinito.
}

The character 'a' turn on the lights, the character 'g' turn off the lights and the characters 'b, c, d' are the signs to control intensity.

What I need is to implement these characters pwm on pin B0, I thank you for your help!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 01, 2013 2:54 pm     Reply with quote

Before you start, you need a specification.

With a spec. you can work out whether what you want is possible or not.

So:-

1) What PWM frequency do you want?
2) How many channels?
3) Resolution?
4) .........................

With a spec., we can begin to help you.

Mike
Macko77



Joined: 01 Dec 2013
Posts: 5

View user's profile Send private message MSN Messenger

PostPosted: Sun Dec 01, 2013 4:55 pm     Reply with quote

This is the circuit I use

https://drive.google.com/file/d/0Bw7-Do2OdLyGbDdLVHQ1WG01anRCRlF6cFZBOFVXX05KS25v/edit?usp=sharing

Mike, the bulbs are 120V AC input 120 V also at 60Hz, PWM only work on pin B0, I mean a single channel, in different widths, eg for 'b' is the pwm 200, for 'c' is the pwm 350 and 'd' is 500.
Just the resolution you believe pertinent to note that the change in the intensity of the bulbs
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Dec 01, 2013 5:09 pm     Reply with quote

PWM is not going to do what you want.

low flicker / flicker free design requires a zero crossing detector
and software method for sending SHORT trigger pulses to the TRIAC
at variable delays after the zero cross is detected.

more important yet , a zero cross trigger opto diac will not work AT ALL as you intend !!!!!
the MOC3023 is the sort of part you want for a variable phase trigger
driver
Macko77



Joined: 01 Dec 2013
Posts: 5

View user's profile Send private message MSN Messenger

PostPosted: Sun Dec 01, 2013 9:03 pm     Reply with quote

asmboy're right, the 3011 moc does not cross zero, and modify the circuit in 3021 and this moc sicruza by zero also supports 400 v.

but that is not set the pwm to make this happen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 3:16 pm     Reply with quote

Quote:
#include <18F4550.h> // Definición de registros internos.
#fuses HSPLL,MCLR,NOWDT,NOPROTECT,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,NOLVP
#use delay(clock=20000000) // Frecuencia máxima de trabajo 20 Mhz

Your #use delay() is incorrect for your fuse settings. If you have a 20
MHz crystal, your PIC is actually running at 48 MHz. To make the CCS
functions and other library code work correctly, the #use delay()
frequency must be the same as the PIC's actual running frequency.
Change the #use delay to 48 MHz.

See this post which has examples of 20 MHz fuses and 48 MHz fuses
for the 18F4550 (both are with a 20 MHz crystal):
http://www.ccsinfo.com/forum/viewtopic.php?t=42223&start=1
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group