Author Topic: Pic 16f722a led blink as external clock not function  (Read 1426 times)

0 Members and 1 Guest are viewing this topic.

Offline m2019Topic starter

  • Newbie
  • Posts: 5
  • Country: br
Pic 16f722a led blink as external clock not function
« on: November 16, 2019, 05:17:08 pm »
Hello colleagues! Just include fuse hs as the preprocessor clock directive such as #fuses hs to specify fuses for the chip and #use delay to specify clock speed to work with external clocking? In the simulation board does not work.
I am using ccs c compiler.
Any suggestion?
thankful.!
 

// microcontrolador PIC16F722a
 #include <16F722A.h>
 
//Configuracao FUSES
 #FUSES NOWDT
 #FUSES INTRC_IO
 #FUSES NOPUT
 #FUSES NOPROTECT
 #FUSES NOBROWNOUT
 #FUSES NOMCLR
 #fuses HS
 
//clock 16 Mhz
 #use delay(clock=16000000)
 
 PINOLED PIN_B1 //Pin led
 
void main()
{
while (1)
 {
  output_bit(PINOLED, TRUE); // on  Led
  delay_ms(500); // delay 500 miliseg
  output_bit(PINOLED, FALSE); // off Led
  delay_ms(500); // delay 500 miliseg
 }
}
« Last Edit: November 16, 2019, 05:19:47 pm by m2019 »
 

Offline Nerull

  • Frequent Contributor
  • **
  • Posts: 694
Re: Pic 16f722a led blink as external clock not function
« Reply #1 on: November 16, 2019, 10:46:41 pm »
You have the chip configured to use an external oscillator, yet I don't see one in the circuit.

The fuses INTRC_IO (internal oscillator) and HS (high speed xtal) are also contradictory.
« Last Edit: November 16, 2019, 10:51:42 pm by Nerull »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2548
  • Country: us
Re: Pic 16f722a led blink as external clock not function
« Reply #2 on: November 17, 2019, 06:47:23 am »
I would try with the internal oscillator at 16MHz first.
I disabled the MCLR- function on pin 1 since you do NOT have a pull-up resistor there.

Sorry, I use the XC8 compiler.

Code: [Select]

// PIC16F722A Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
 #pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
 #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
 #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
 #pragma config MCLRE = OFF      // RE3/MCLR Pin Function Select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
 #pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
 #pragma config BOREN = ON       // Brown-out Reset Selection bits (BOR enabled)
 #pragma config BORV = 19        // Brown-out Reset Voltage selection bit (Brown-out Reset Voltage (VBOR) set to 1.9 V nominal)
 #pragma config PLLEN = ON       // INTOSC PLL Enable bit (INTOSC Frequency is 16MHz (32x))

// CONFIG2
 #pragma config VCAPEN = DIS     // Voltage Regulator Capacitor Enable bits (All VCAP pin functions are disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of for ON and OFF.

 <xc.h>


Then try with an external oscillator (max 20MHz) to pin 9.

Code: [Select]

// PIC16F722A Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
 #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
 #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
 #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
 #pragma config MCLRE = OFF      // RE3/MCLR Pin Function Select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
 #pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
 #pragma config BOREN = ON       // Brown-out Reset Selection bits (BOR enabled)
 #pragma config BORV = 19        // Brown-out Reset Voltage selection bit (Brown-out Reset Voltage (VBOR) set to 1.9 V nominal)
 #pragma config PLLEN = ON       // INTOSC PLL Enable bit (INTOSC Frequency is 16MHz (32x))

// CONFIG2
 #pragma config VCAPEN = DIS     // Voltage Regulator Capacitor Enable bits (All VCAP pin functions are disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of for ON and OFF.

 <xc.h>

« Last Edit: November 17, 2019, 06:52:56 am by MarkF »
 

Offline m2019Topic starter

  • Newbie
  • Posts: 5
  • Country: br
Re: Pic 16f722a led blink as external clock not function
« Reply #3 on: November 17, 2019, 10:29:39 pm »
Hello gentlemen! I did on mplab and compiled normaly. But in protobord does not work. I put a picture of the montage to check it out. I thank those who can help me.
thanks!




// PIC16F722A Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
 #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
 #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
 #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
 #pragma config MCLRE = OFF      // RE3/MCLR Pin Function Select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
 #pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
 #pragma config BOREN = ON       // Brown-out Reset Selection bits (BOR enabled)
 #pragma config BORV = 19        // Brown-out Reset Voltage selection bit (Brown-out Reset Voltage (VBOR) set to 1.9 V nominal)
 #pragma config PLLEN = ON       // INTOSC PLL Enable bit (INTOSC Frequency is 16MHz (32x))

// CONFIG2
 #pragma config VCAPEN = DIS     // Voltage Regulator Capacitor Enable bits (All VCAP pin functions are disabled)


 #define _XTAL_FREQ 16000000 // 16 MHz
 <xc.h>
 
 void main(void) {          //função principal
    TRISB = 0b00000000;    //define todos os pinos do portb como saida
    PORTB = 0b00000000;    //zera todos os pinos do portb

    while(1){              //loop infinito, vai ate o fim do parenteses e volta executar no inicio do parenteses
        PORTBbits.RB0 = 1; //acende led MANDA 5V RB0
        __delay_ms(1000);  //espera um tempo de 1000ms = 1s
        PORTBbits.RB0 = 0; //apaga led manda 0v RB0
        __delay_ms(1000);  //espera um tempo de 1000ms = 1s
     }
 }
« Last Edit: November 17, 2019, 10:38:28 pm by m2019 »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2548
  • Country: us
Re: Pic 16f722a led blink as external clock not function
« Reply #4 on: November 18, 2019, 01:51:37 pm »
I only see two things.  But not sure they are a problem.

1)  Change your clock definition to:   #define _XTAL_FREQ 16000000L  Add the 'L' at the end.
     I usually put the define after the #include <xc.h>

2)  The wires for the crystal are awful long.  It may not be oscillating.
     I have only ever used a clock module with a TTL output.

Like I say, I do not necessarily see these as a problem.  Just something to check.
I would still try getting it working with the internal oscillator first, to prove the rest of your code.

Note.  Please use the "code" tag when posting code. 
        It is the "#" button just above the emoji's in the Reply editor.
 

Offline m2019Topic starter

  • Newbie
  • Posts: 5
  • Country: br
Re: Pic 16f722a led blink as external clock not function
« Reply #5 on: November 18, 2019, 08:45:00 pm »
Hello MarkF! I already did the internal clock test. Just was not working with the external clock. There is no need to change the coding, and the length of the wire does not interfere either. To make it work just take the wires that go to pin 9 and 10 and position them above the crystal and not below as it is in the assembly I made.
It's just this detail: But I only realized from your point of view that length could be influencing.
thanks!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2548
  • Country: us
Re: Pic 16f722a led blink as external clock not function
« Reply #6 on: November 18, 2019, 09:18:29 pm »
Good!

I tend to use these clock modules on breadboards instead of crystals.  Just Vcc, GND and clock out.
   https://www.digikey.com/products/en?keywords=535-9181-5-ND

You don't have to worry about stray capacitance and such.
 
The following users thanked this post: m2019


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf