how to generate a square wave on PIC16F688 ?

Discussion in 'Embedded Systems and Microcontrollers' started by ttuna10, Feb 4, 2016.

  1. ttuna10

    Thread Starter New Member

    Feb 4, 2016
    4
    0
    This is rather a simple question.
    I'm trying to generate a square wave by using PIC16F688. I'm using PIC C compiler and Proteus 7 .This is my microcontroller on Proteus :
    PIC16F688.PNG . So this might a basic question because i'm a newbie on pic programming. I hope someone help me out .
    Thanks.
     
  2. ISB123

    Well-Known Member

    May 21, 2014
    1,239
    527
    Simply cycling the output pin between HIGH and LOW would give you a square wave. PWM would be something different.
     
  3. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    Welcome to AAC

    You can use delays and toggle an output quite easily.
     
  4. ttuna10

    Thread Starter New Member

    Feb 4, 2016
    4
    0
    thanks for the answer. As i said because of i really don't know how to program it .I should know the code. My question is what's the code?
     
  5. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi, is this homework?

    Show us the whole schematic, and tell us what you think you have to do, and what you have done.
    Which PIC C compiler are you using?
     
  6. ISB123

    Well-Known Member

    May 21, 2014
    1,239
    527
    Code (Text):
    1. void main()
    2. {
    3. TRISA=0X00;
    4. PORTA=0X00;
    5. while(1)
    6. {
    7. PORTA=0XFF;
    8. __delay_ms(1000);
    9. PORTA=0X00;
    10. __delay_ms(1000);
    11. }
    12. }
     
  7. saurav2220

    New Member

    Feb 4, 2016
    1
    0
    If you are new, there is an Embedded Systems class on edx for free that teaches you the basics. The course already started, so not sure if you can join but all the materials are on their website. The following link talks about ports/pin so it might help you even though they are using a TM4C micro, the theory behind it is the same.

    http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C6_MicrocontrollerPorts.htm
     
  8. ttuna10

    Thread Starter New Member

    Feb 4, 2016
    4
    0
    circuit.PNG
    So this is my circuit and for compiler i'm using MPLAB IDE. I'm trying to control these power mosfets by using PIC16F688. I should control the mosfets like these first Q1 and Q4(at the same time) should conduct then Q2 and Q3(at the same time) should.After i controled the mosfets then while Q1 AND Q4 are conducting DC motor (at the middle of the power mosfets) should turn to the right or left but it should be opposite to the Q2 AND Q3 conducting.( i mean the direction (to the left or right) ). Our tutor said i can use pwm .He said we can change the duty cycle of the waves(stuff like that) and then can control where dc motor is going to turn.
    As you can see on schematic i labeled the RA0,RA1,RA2 and RA4 pins as the same as the input of the circuit .That is to say i labeled Q1 ,Q2 ,Q3 and Q4 as an input of the circuit and as an 13,12,11 and 4 pins of the PIC16F688 so that when i control the PIC i will control the mosfets.That's it . Can you briefly show me how can control mosfets by writing code into PIC and how to use PWM in that code ?

    Thanks guys and sorry about my grammar mistakes :)
     
    Last edited: Feb 5, 2016
  9. ttuna10

    Thread Starter New Member

    Feb 4, 2016
    4
    0
    Thanks for the reply man. Can you suggest me any other sites that i can learn PIC ?
     
  10. Picbuster

    Member

    Dec 2, 2013
    374
    50
    make an interrupt using trm0 put tris RC1 =0 and the ints TMR0IE=1; GIE=1;
    i
    if (TMR0IF)
    {
    TMR0IF=0;
    RC1=!RC1; // here is your block wave at pin RC1.
    }


    To make it slower do
    if (TMR0IF)
    {
    TMR0IF=0;
    cnt++;
    if ( cnt>wanted_time)
    {
    cnt=0;
    RC1=!RC1; // here is your block wave at pin RC1.
    }
    }
     
Loading...