PIC16F676 voltmeter

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PIC16F676 voltmeter

Postby pic16 » Fri Jan 28, 2011 11:47 am

Hi, everyone... :P
i have a question again about how to set the oscillator issue in this PIC16f676,
i am try to collect the component now & try to build one of this :mrgreen:

May help me take a quick look of this circuit and etc, before i blindness follow it? :oops:






p/s: source code added at 1 Feb 2011
Attachments
v.rar
(14.26 KiB) Downloaded 422 times
i'm poor in english and just an electronic hobbyist.
pic16
Amateur
 
Posts: 135
Joined: Tue Jan 04, 2011 2:28 pm
Location: Earth

Re: PIC16F676 voltmeter

Postby ABSF » Fri Jan 28, 2011 8:09 pm

I do not have this PIC with me. My simulator doesn't support this PIC. The source code is not included in your project file.

May be the newer version of ISIS supports this chip. Mine is v6.1 SP1. What do other members think?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC16F676 voltmeter

Postby ABSF » Fri Jan 28, 2011 8:19 pm

pic16 WROTE:http://electronics-diy.com/electronic_schematic.php?id=721


Hi, everyone... :P
i have a question again about how to set the oscillator issue in this PIC16f676,
i am try to collect the component now & try to build one of this :mrgreen:

May help me take a quick look of this circuit and etc, before i blindness follow it? :oops:


This circuit doesn't use external crystal oscillator. It is config to use its internal 4 MHz osc. You should download the datasheet and study it first before you proceed with it.

The config bits should be:

Oscillator = Internal RC No clockout
WatchDog = off
Power up timer = on
Master clear disable = Internally enabled

config word = 3F84

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC16F676 voltmeter

Postby shiyan » Fri Jan 28, 2011 10:51 pm

Schematic seem to be fine. There is a adjustable voltage divider to allow higher voltage than 5V, not bad. Using PNP transistor to multiplex common anode 7-segments + a dot :0

As for the internal crystal, I am not sure because I do not have simulator to simulate the hex code, but it should be fine if you follow suggestion from allen. Looking forward to see the video!
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am

Re: PIC16F676 voltmeter

Postby pic16 » Sat Jan 29, 2011 1:23 am

ABSF WROTE:I do not have this PIC with me. My simulator doesn't support this PIC. The source code is not included in your project file.

May be the newer version of ISIS supports this chip. Mine is v6.1 SP1. What do other members think?

Allen




source code....
Attachments
main.rar
(1.13 KiB) Downloaded 411 times
i'm poor in english and just an electronic hobbyist.
pic16
Amateur
 
Posts: 135
Joined: Tue Jan 04, 2011 2:28 pm
Location: Earth

Re: PIC16F676 voltmeter

Postby pic16 » Sat Jan 29, 2011 1:30 am

but when i try to burn HEX file it have
ABSF WROTE:
pic16 WROTE:http://electronics-diy.com/electronic_schematic.php?id=721


Hi, everyone... :P
i have a question again about how to set the oscillator issue in this PIC16f676,
i am try to collect the component now & try to build one of this :mrgreen:

May help me take a quick look of this circuit and etc, before i blindness follow it? :oops:


This circuit doesn't use external crystal oscillator. It is config to use its internal 4 MHz osc. You should download the datasheet and study it first before you proceed with it.

The config bits should be:

Oscillator = Internal RC No clock
WatchDog = off
Power up timer = on
Materclear enable = Internal

config word = 3F84

Allen



my PIC16F676 have just arrive... :P
it got so many configuration.. :shock:
could no have 3F84
i'm poor in english and just an electronic hobbyist.
pic16
Amateur
 
Posts: 135
Joined: Tue Jan 04, 2011 2:28 pm
Location: Earth

Re: PIC16F676 voltmeter

Postby pic16 » Sat Jan 29, 2011 1:35 am

i put some picture to let you guys guide me... :oops:

other setting just enable and disable...

which setting i should set?
Attachments
1.jpg
2.jpg
3.jpg
i'm poor in english and just an electronic hobbyist.
pic16
Amateur
 
Posts: 135
Joined: Tue Jan 04, 2011 2:28 pm
Location: Earth

Re: PIC16F676 voltmeter

Postby pic16 » Sat Jan 29, 2011 1:40 am

shiyan WROTE:Schematic seem to be fine. There is a adjustable voltage divider to allow higher voltage than 5V, not bad. Using PNP transistor to multiplex common anode 7-segments + a dot :0

As for the internal crystal, I am not sure because I do not have simulator to simulate the hex code, but it should be fine if you follow suggestion from allen. Looking forward to see the video!



ha.. :lol:
only if success :oops: :oops:


but i still waitting for some componet...
i'm poor in english and just an electronic hobbyist.
pic16
Amateur
 
Posts: 135
Joined: Tue Jan 04, 2011 2:28 pm
Location: Earth

Re: PIC16F676 voltmeter

Postby ABSF » Sat Jan 29, 2011 7:24 am

CODE: SELECT_ALL_CODE
#include <16F676.h>
#device adc=10
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
[color=#FF0000]INTRC_IO = internal RC osc and RA4 and RA5 used as IO
NOWDT = No Watch Dog Timer
PUT = ???
NOPROTECT = Code not protected
BROWNOUT = brownout is YES
NOMCLR = Disable Master Clear
[/color]
#use delay (clock=4000000) // 4MHz clock
[color=#FF0000] Internal clock is 4MHz[/color]
#rom  0x3ff={0x3444}

#byte PORTA = 0x05
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISC = 0x87

#define SPORTA PORTA
#define SPORTC PORTC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000
#define  INTERRUPT_OVERHEAD            35
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
[color=#FF0000]Timer 1 is used for the interrupt to generate clock ticks[/color]
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
[color=#FF0000]The digit patterns on 7-seg LED + blank[/color]
   //                       0    1    2    3    4    5    6    7    8    9
const char Column[3]   = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};   [color=#FF0000]"888"?[/color]
static unsigned char ColCount=0x00;

void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num);

byte i;
unsigned int32 result;

#INT_TIMER1
[color=#FF0000]Is this the interrupt routine?  V V Neat[/color]
void Timer1(void)
{   
   set_timer1(TMR1RESET);
   Display();   
}   

void main()
{      
   unsigned char i;
   
   CPU_SETUP();
   
   while(true)
   {         
      result=0;
      for (i=0;i<20;i++)
      {
         set_adc_channel(3);
         delay_ms(1);
         result=result+read_adc();
      }
         //result = 0x3fe;                           
       HTO7S(result/20);   
      delay_ms(200);         
   }
   
}

void CPU_SETUP()
{
    
   setup_comparator(NC_NC_NC_NC);   // not use comparator module
   setup_adc_ports( sAN3 | VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_64);
   TRISA=0b00011000;
   PORTA=0x27;
   TRISC=0b00000000;
   PORTC=0x37;
   
   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   set_timer1(TMR1RESET);
   enable_interrupts(GLOBAL);  [color=#FF0000]GIE=1[/color]
   enable_interrupts(INT_TIMER1);   [color=#FF0000]TMR1IE=1[/color]
}

//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
   PORTA = 0b00100111;     // off all digits column and Segment G
   PORTC = 0b00111111;   // off segment a-f   
   delay_cycles(2);
   

   if (ColCount>=3)
   ColCount=0;
       
   SPORTC = Segment[ColCount];
   SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
   ColCount++;            
}   

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{

   unsigned int32 res;

   
   Segment[0]=SegCode[30*Num/10230];
   if (Segment[0]==0x40)
   Segment[0]=0xFF;
   
   res = 30*Num%10230;
   Segment[1]=SegCode[10*res/10230];
   res=10*res%10230;
   Segment[2]=SegCode[10*res/10230];
}   


Does the codes look like HTC? Very doubtful. But anyway, see my comments in red.
Looks like your PIC configuration is already defined in the code & Hex files.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC16F676 voltmeter

Postby ABSF » Sat Jan 29, 2011 7:30 am

Oops, code doesnt support color, sorry.

#include <16F676.h>
#device adc=10
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
INTRC_IO = internal RC osc and RA4 and RA5 used as IO
NOWDT = No Watch Dog Timer
PUT = Power-up timer enabled
NOPROTECT = Code not protected
BROWNOUT = brownout is YES
NOMCLR = Disable external Master Clear (Use internal MR)

#use delay (clock=4000000) // 4MHz clock
Internal clock is 4MHz
#rom 0x3ff={0x3444}

#byte PORTA = 0x05
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISC = 0x87

#define SPORTA PORTA
#define SPORTC PORTC
#define TICKS_BETWEEN_INTERRUPTS 5000 //5000
#define INTERRUPT_OVERHEAD 35
#define TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
Timer 1 is used for the interrupt to generate clock ticks
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
The digit patterns on 7-seg LED + blank
// 0 1 2 3 4 5 6 7 8 9
const char Column[3] = {0x02,0x01,0x04}; column scan pattern 0010, 0001, 0100
static char Segment[3] = {0x7f,0x7f,0x7f}; "888"?
static unsigned char ColCount=0x00;

void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num); Hex to 7seg converter

byte i;
unsigned int32 result;

#INT_TIMER1
Is this the interrupt routine? V V Neat
void Timer1(void)
{
set_timer1(TMR1RESET);
Display();
}

void main()
{
unsigned char i;
CPU_SETUP();
while(true)
{
result=0;
for (i=0;i<20;i++)
{
set_adc_channel(3);
delay_ms(1);
result=result+read_adc();
}
//result = 0x3fe;
HTO7S(result/20);
delay_ms(200);
}
}
void CPU_SETUP()
{

setup_comparator(NC_NC_NC_NC); // not use comparator module
setup_adc_ports( sAN3 | VSS_VDD); set up adc on RA4/AN3 for voltage input
setup_adc(ADC_CLOCK_DIV_64);
TRISA=0b00011000;
PORTA=0x27;
TRISC=0b00000000;
PORTC=0x37;

setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(TMR1RESET);
enable_interrupts(GLOBAL); GIE=1
enable_interrupts(INT_TIMER1); TMR1IE=1
}

//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
PORTA = 0b00100111; // off all digits column and Segment G
PORTC = 0b00111111; // off segment a-f
delay_cycles(2);

if (ColCount>=3)
ColCount=0;

SPORTC = Segment[ColCount];
SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
ColCount++;
}

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{
unsigned int32 res;

Segment[0]=SegCode[30*Num/10230];
if (Segment[0]==0x40)
Segment[0]=0xFF;
res = 30*Num%10230;
Segment[1]=SegCode[10*res/10230];
res=10*res%10230;
Segment[2]=SegCode[10*res/10230];
}


Quotes looks better.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron