Pic 16f722a led blink as external clock not function - Page 1
Forum section: electronics / general

author: m2019
author_rank: Newbie
timestamp: November 16, 2019, 05:17:08 pm
content: 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 ledvoid main(){while (1){output_bit(PINOLED, TRUE); // on Leddelay_ms(500); // delay 500 milisegoutput_bit(PINOLED, FALSE); // off Leddelay_ms(500); // delay 500 miliseg}}

author: Nerull
author_rank: Frequent Contributor
timestamp: November 16, 2019, 10:46:41 pm
content: 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.

author: MarkF
author_rank: Super Contributor
timestamp: November 17, 2019, 06:47:23 am
content: 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:// 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:// 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>

author: m2019
author_rank: Newbie
timestamp: November 17, 2019, 10:29:39 pm
content: 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 principalTRISB = 0b00000000; //define todos os pinos do portb como saidaPORTB = 0b00000000; //zera todos os pinos do portbwhile(1){ //loop infinito, vai ate o fim do parenteses e volta executar no inicio do parentesesPORTBbits.RB0 = 1; //acende led MANDA 5V RB0__delay_ms(1000); //espera um tempo de 1000ms = 1sPORTBbits.RB0 = 0; //apaga led manda 0v RB0__delay_ms(1000); //espera um tempo de 1000ms = 1s}}

author: MarkF
author_rank: Super Contributor
timestamp: November 18, 2019, 01:51:37 pm
content: I only see two things. But not sure they are a problem.1) Change your clock definition to: #define _XTAL_FREQ 16000000LAdd 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.

author: m2019
author_rank: Newbie
timestamp: November 18, 2019, 08:45:00 pm
content: 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!

author: MarkF
author_rank: Super Contributor
timestamp: November 18, 2019, 09:18:29 pm
content: 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-NDYou don't have to worry about stray capacitance and such.