-
#50 Reply
Posted by
Ian.M
on 26 Mar, 2017 11:23
-
Always connect all power pins together and all ground pins together with a 0.1uF decoupling cap for each power/ground pair. That's Vdd and Vss for this PIC as it doesn't have any dedicated power pins for its ADC.
What's that unholy mess of capacitors round the crystal? Do you have any single caps within 30% of the value you are trying to get to? If so, use them on their own for now.
Due to the sensitivity of the LP oscillator circuit, you should connect the caps as dorectly as possible between the OSC pins and the adjacent Vss pin. Long wires are NOT a good idea . . . .
-
#51 Reply
Posted by
ali6x944
on 26 Mar, 2017 15:27
-
I think you have a few problem with power connections on your breadboard.
1) Vdd should connect to pins 11 and 32. You have only connected to pin 32.
2) Vss should connect to pins 12 and 31. The photo shows it connected to pin 33.
3) The right hand vertical ground bus appears to be floating - not connected to ground.
Always connect all power pins together and all ground pins together with a 0.1uF decoupling cap for each power/ground pair. That's Vdd and Vss for this PIC as it doesn't have any dedicated power pins for its ADC.
What's that unholy mess of capacitors round the crystal? Do you have any single caps within 30% of the value you are trying to get to? If so, use them on their own for now.
Due to the sensitivity of the LP oscillator circuit, you should connect the caps as dorectly as possible between the OSC pins and the adjacent Vss pin. Long wires are NOT a good idea . . . .
i suspected this, also I'm using 10pf caps.
i will fix the connections and upload the photos soon...
-
#52 Reply
Posted by
ali6x944
on 27 Mar, 2017 18:46
-
Sorry about that - Brian gave you bogus info and I didn't notice. On a PIC16F77, port B has NO analog capable pins and its ADC module is far too old to have a separate pin configuration for each port, or even to have individual pin configuration bits at all. To turn off analog mode for all pins on an 'F77', use:
ADCON1bits.PCFG=0b111;
See datasheet REGISTER 11-2: ADCON1 REGISTER for details. However it wont make any difference to whether or not your code works, as its only important if you are trying to use ports A or E.
Please post a photo of your board here so we can see how you are testing if RB0 toggles.
Also it would be worth trying a different pin in case you've blown RB0.
it worked see code of main.c:
#include "config.h"
#include <xc.h>
#include <stdio.h>
int main()
{
ADCON1bits.PCFG=0b111;
TRISB = 0xFF; // PortB is an output
TRISBbits.TRISB0 = 0;
while(1)
{
PORTBbits.RB0 = 1;
__delay_ms(500);
PORTBbits.RB0 = 0;
__delay_ms(500);
}
return 0;
}
see output:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'
make -f nbproject/Makefile-default.mk dist/default/production/BlinkLed.X.production.hex
make[2]: Entering directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=16F77 -Q -G --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/main.p1 main.c
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --chip=16F77 -G -mdist/default/production/BlinkLed.X.production.map --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" --memorysummary dist/default/production/memoryfile.xml -odist/default/production/BlinkLed.X.production.elf build/default/production/main.p1
Microchip MPLAB XC8 C Compiler (Free Mode) V1.41
Build date: Jan 24 2017
Part Support Version: 1.41
Copyright (C) 2017 Microchip Technology Inc.
License type: Node Configuration
:: warning: (1273) Omniscient Code Generation not available in Free mode
Memory Summary:
Program space used 24h ( 36) of 2000h words ( 0.4%)
Data space used 4h ( 4) of 170h bytes ( 1.1%)
EEPROM space None available
Data stack space used 0h ( 0) of 60h bytes ( 0.0%)
Configuration bits used 1h ( 1) of 1h word (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
You have compiled in FREE mode.
Using Omniscient Code Generation that is available in PRO mode,
you could have produced up to 60% smaller and 400% faster code.
See http://www.microchip.com/MPLABXCcompilers for more information.
make[2]: Leaving directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'
make[1]: Leaving directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'
BUILD SUCCESSFUL (total time: 6s)
Loading code from C:/Users/hadaw/MPLABXProjects/BlinkLed.X/dist/default/production/BlinkLed.X.production.hex...
Loading completed
i think it will work now...
-
#53 Reply
Posted by
Luminax
on 28 Mar, 2017 16:54
-
I wonder how effective the code 'conversion' will be if you actually purchased the XC8 License... hmmmm
-
#54 Reply
Posted by
ali6x944
on 30 Mar, 2017 17:45
-
It finally worked! thanks for all the help
I will post a video of it soon in the form of a tutorial so no body have to suffer through this like many others -including me- did,
so if u can or wish post anything that might be helpful to include in the video...
and if anybody have any questions on this topic they can ask it in this thread.
thanks a lot for all who contributed here , this is greatly appreciated
-
#55 Reply
Posted by
ali6x944
on 01 Apr, 2017 05:13
-
-
#56 Reply
Posted by
ali6x944
on 09 Apr, 2017 13:32
-
here is the video I made, A big thanks goes to you guys for the great help which made the video possible ...
also I hope u correct me if I got anything wrong in the video, so I can benefit from this experience too and can deliver better content in the future.
https://youtu.be/eypsp_32Ptwor
I hope it is informing... sorry if I didn't explain the code thoroughly, or overgeneralised when describing the function of certain registers or calling them ports all the time...
give me anything that u guys think might need improving so this thread can deliver the low-level/beginner-level documentation a lot of people may need.
thanks a lot for all support
-
#57 Reply
Posted by
ali6x944
on 09 Apr, 2017 17:06
-
so what do u think??
-
#58 Reply
Posted by
Ian.M
on 09 Apr, 2017 17:43
-
lthough its nice to see the face we've been helping, as its a long video few of us will have watched it. If you want people to review a video, best keep it under 5 minutes till you've built up a good reputation, and if you cant cover a topic in such a format, consider blogging it or writing an instructable, with short embedded videos for key points to back-up your text.
You lost me 1 minute in when it became obvious that you hadn't prepared, checked and practised a script. Dave can get away with unscripted stuff on EEVblog because he knows the field so well, but even so he puts a lot of work into locating technical data before making tutorial, design or review videos. Its inexcusable NOT to know the part number you chose as an example of an unsupported part, and suggesting that the best way of identifying if a part is supported is to check in MPLAB is unhelpful due to the slowness and difficulty of checking multiple parts, especially as Microchip provide a concise HTML PIC vs tool compatibility chart as part of the MPLAB release notes.
-
#59 Reply
Posted by
ali6x944
on 10 Apr, 2017 13:19
-
lthough its nice to see the face we've been helping, as its a long video few of us will have watched it. If you want people to review a video, best keep it under 5 minutes till you've built up a good reputation, and if you cant cover a topic in such a format, consider blogging it or writing an instructable, with short embedded videos for key points to back-up your text.
You lost me 1 minute in when it became obvious that you hadn't prepared, checked and practised a script. Dave can get away with unscripted stuff on EEVblog because he knows the field so well, but even so he puts a lot of work into locating technical data before making tutorial, design or review videos. Its inexcusable NOT to know the part number you chose as an example of an unsupported part, and suggesting that the best way of identifying if a part is supported is to check in MPLAB is unhelpful due to the slowness and difficulty of checking multiple parts, especially as Microchip provide a concise HTML PIC vs tool compatibility chart as part of the MPLAB release notes.
true I fully agree, and I will do a "re-do/shot" of the video and I will upload it to YouTube taking all your points in consideration...
sorry if the audio quality was bad near the middle of the video for all who watched the hole video and prior to those who didn't watch it in hole...
I will try to hopefully upload it this week or next week, I would like to thank you all for ur help especially Ian.M for his great constructive comment
in the next video I will cover in order:
1.the programmer compatibility with the PIC
2.Compiler choosing
3.IDE installation
4.code explanation (includes a general description of the the 4 main registers -port,tris,ANSEL and ANSELH-)
if anyone wants to add anything I missed or correct any thing wrong feel free to do so because i need to improve the kinds of videos i make
-
#60 Reply
Posted by
ali6x944
on 27 Jun, 2017 20:50
-
not re-shot yet:
i will re-shot it soon...
-
#61 Reply
Posted by
ali6x944
on 01 Jul, 2017 20:08
-
just a quick question:
are all Pickit2 compatible chips compatible with Pickit3?
-
#62 Reply
Posted by
Ian.M
on 01 Jul, 2017 22:31
-
I just checked the MPLAB 8.92 device support (PICkit 2 device support was frozen somewhat earlier than v8.92, and was then ported to MPLAB X with no further changes), as I have it in a spreadsheet for easy searching, and there are NO PICs that have PICkit 2 programming support but aren't supported by the PICkit 3.
-
#63 Reply
Posted by
ali6x944
on 02 Jul, 2017 20:00
-
Thanks
-
#64 Reply
Posted by
Luminax
on 06 Jul, 2017 00:21
-
I think we can safely say that there are NO PICs that are NOT supported by PicKit3... it's their flagship programmer after all
-
#65 Reply
Posted by
Ian.M
on 06 Jul, 2017 00:47
-
Actually it doesn't support any of the old EPROM program memory PICS*. They are mature products but many are still in production. It supports all FLASH program memory PICs. If you need to program the EPROM PICs with a currently supported programmer, you need a Microchip PM3. However unless you've got deep pockets, it makes more sense to pick up a second hand PICstart Plus and maintain a legacy MPLAB 8.92 install to run it.
* IIRC the algorithms for programming the PIC18Cxxx and PIC16Cxx parts could easily be ported to it, but its Vpp generator isn't beefy enough. As a minimum it would require an external Vpp buffer and supply for it.
-
#66 Reply
Posted by
NorthGuy
on 06 Jul, 2017 01:22
-
It supports all FLASH program memory PICs.
Except PIC18F4539 and family. Not that this matters ...
More importantly, it supports newer parts, such as PIC18 K42 and will support PICs which appear in the future.
-
#67 Reply
Posted by
ali6x944
on 19 Jul, 2017 11:24
-
Hi guys,
thanks for all the help, but do anyone knows how to use 8 bit ADC in PIC16F77 using XC8, because I'm going to use it to demonstrate this as an example code implementation of an 8-bit ADC and 10-bit ADC of modern PICs in the upcoming video...
I tried but with no luck:
config.h
#include <xc.h>
// include processor files - each processor file is guarded.
// PIC16F77 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = LP // Oscillator Selection bits (LP oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#define _XTAL_FREQ 32786 // Sets the crystal oscillator frequency
void ADC_Init()
{
ADCON0 = 0b00000001;
/*
*See the the "0b" tells the compiler that this is a binary number,
* The number right after the "0b" is MSB, the last number -right before the ";"- is LSB.
* Bit 7-6 are A/D Conversion Clock Select bits, which set the sample clock.
* Bit 5-3 are Analog Channel Select bits, which will select a particular channel out of 8 Analog channel.
* Bit 2 is A/D Conversion Status bit, which initiates A/D conversion and it will be automatically cleared when the conversion completes.
* Bit 1 is not used so set to zero.
* Bit 0 is A/D On bit, which basically turns on/off the ADC
*/
ADCON1 = 0b00000000; //All pins as Analog Input and setting Reference Voltages
/*
*See the the "0b" tells the compiler that this is a binary number,
* The number right after the "0b" is MSB, the last number -right before the ";"- is LSB.
* Bit 7-3 is not used so set to zero.
* Bit 2-0 are A/D Port Configuration Control bits, which set the analog pins and refrence.
*/
}
unsigned int ADC_Read(unsigned int channel)
{
if(channel > 7) //Channel range is 0 ~ 7
{
return 0;
}
ADCON0 &= 0xC5; //Clearing channel selection bits
ADCON0 |= channel<<3; //Setting channel selection bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D conversion
while(GO_nDONE); //Waiting for conversion to complete
return ((ADRES));
}
main.c
#include "config.h"
void main(void) {
TRISAbits.TRISA0=1; // Analog Input pin AN0
TRISAbits.TRISA1=1; // Analog Input pin AN1
TRISBbits.TRISB7=0; // Digital Output pin RB7
ADC_Init(); //Initialize ADC
unsigned int ADC; // value of first analog channel
unsigned int ADC1; // value of second analog channel
ADC1=ADC_Read(1); //Initialize channel (1)
ADC=ADC_Read(0); //Initialize channel (0)
while(1){
if (ADC==ADC1){
PORTBbits.RB7=1; //if both channels are equal turn RB7 to high
}
else{
PORTBbits.RB7=0;//else turn RB7 to low
}
}
}
-
-
ADCON0 = 0b00000001;
* Bit 7-6 are A/D Conversion Clock Select bits, which set the sample clock.
If the XTAL_FREQ is only 32,768, you'll need to use the ADC's internal RC oscillator.
ADCON0 = 0b11000001;
-
#69 Reply
Posted by
ali6x944
on 19 Jul, 2017 14:22
-
will try it in a second....
but I want to know why do I have to use the internal oscillator?
is the ADC in PIC micros need specific exact frequencies to work at properly?
-
#70 Reply
Posted by
ali6x944
on 19 Jul, 2017 14:44
-
it dose not work...
I connected both AN0 and AN1 to ground, and RB7 didn't go high...
I did the same thing but connected the inputs to VDD with no luck too.
-
-
Yep, the ADC clock speeds are limited ~250kHz - ~1MHz.
In ADC_Read(), is ADCON0 &= 0xC5; (b11000101) is starting a conversion before you've set the channel number ?
In main(void) should ADC1=ADC_Read(1); & ADC=ADC_Read(0); be inside the while(1) loop ?
-
-
You may be expecting a bit too much from the A/D converter. You only read each channel once, and if they are not identical your code will fail. A/D conversion is inherently noisy and (especially at the extremes) channels may not track precisely.
Try connecting one channel to a pot which you can turn to vary the voltage from Vss to Vdd, and the other to a midpoint voltage (eg. using a voltage divider with 2 equal resistors). Then read the channels continuously inside the while() loop, and set the output according to which voltage is higher, like this:-
while(1){
ADC1=ADC_Read(1); //Initialize channel (1)
ADC=ADC_Read(0); //Initialize channel (0)
if (ADC > ADC1){
PORTBbits.RB7=1; //if channel 0 > channel 1 then turn RB7 to high
}
else{
PORTBbits.RB7=0; //else turn RB7 to low
}
The LED should turn on/off as the pot is turned through its center position.
-
#73 Reply
Posted by
ali6x944
on 24 Jul, 2017 11:15
-
thanks a lot!!