View previous topic :: View next topic |
Author |
Message |
abadade
Joined: 24 May 2014 Posts: 4
|
Voltmeter with 7-segment display |
Posted: Sat May 24, 2014 4:27 pm |
|
|
hello,
I want to make a digital voltmeter based on the PIC16F676 and 3 digit max, 30v with a lower consumption of 15 mA. I already tested it but consumption was 30 mA.
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat May 24, 2014 6:33 pm |
|
|
post a schematic for your circuit and some code that drives it.
then help may be possible. otherwise what can you expect ? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat May 24, 2014 7:48 pm |
|
|
If really running from 30 volts, redesign the power supply to be closer to 5 volts using low power regulators, schottky diodes, etc. You could be wasting 10-20 ma just in the basic 5V power supply.
Be sure to set high or low any/all unused I/O pins.
Disable any internal peripherals you are not using.
Choose a lower clock frequency as 'transitions' consume power.
Experiment with the LED 'refresh' rate. Again slower is better but too slow is bad.
Read the uChip application notes about 'low power' designs.
Use low current LED displays.
As requested, upload your code and schematic. From there we can 'fine tune' both to reduce power.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
abadade
Joined: 24 May 2014 Posts: 4
|
voltmetre numerique a 7 seg |
Posted: Sun May 25, 2014 4:20 am |
|
|
Code: |
#include <16F676.h>
#device adc=10
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
#use delay (clock=4000000) // 4MHz clock
#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 1500 //5000
#define INTERRUPT_OVERHEAD 35
#define TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
// 0 1 2 3 4 5 6 7 8 9
const char Seg_mask_C[7] = {0x01,0x02,0x4,0x08,0x10,0x20,0x00};
// C0 C1 C2 C3 C4 C5
const char Column[3] = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};
static char Segment_port[2] = {0x7f,0x7f};
static unsigned char ColCount=0x00;
static unsigned char SegCount=0x00;
void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num);
byte i;
unsigned int32 result;
#INT_TIMER1
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(1000);
}
}
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=0b00010000;
PORTA=0x27;
TRISC=0b00000000;
PORTC=0x37;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(TMR1RESET);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
}
//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
if (ColCount>=3) {ColCount=0;SegCount++;}
if (SegCount>=7)SegCount=0;
Segment_port[1] = Segment[ColCount] | (Seg_mask_C[segcount]^0xFF);
if (segcount>=6)Segment_port[0] = ((Segment[ColCount]>>1) & 0b00100000) | (Column[ColCount]& 0b00000111);
if (segcount<6)Segment_port[0] = 0b00100000|(Column[ColCount]& 0b00000111);
sportc=Segment_port[1];
sporta=Segment_port[0];
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];
//! Segment[0]=SegCode[1];
//! Segment[1]=SegCode[2];
//! Segment[2]=SegCode[5];
} |
[img]
http://www.coolcircuit.com/project/meter/circuit.gif[/img]
without resistor and transistor |
|
![](templates/subSilver/images/spacer.gif) |
abadade
Joined: 24 May 2014 Posts: 4
|
voltmetre numerique a 7 seg |
Posted: Sun May 25, 2014 5:07 am |
|
|
j'ai remarque que si je debranche l'afficheur le pic a lui seule consomme 15mA ????bizzare |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sun May 25, 2014 5:19 am |
|
|
Link to schematic is busted ( internal server error 500).
jay |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun May 25, 2014 5:22 am |
|
|
Your link did not work for me.
I'm assuming your PIC circuit looks something like this. Code: |
_______
vdd | 1 14 | Vss
________ RA5 | 2 13 | AN0 ______________________________________________________________
| RA4 | 3 12 | AN1 ___________________________________________ |
| MCLR | 4 11 | RA2 ______________________ | |
| ______ RC5 | 5 10 | RC0 ______ | | |
| | ____ RC4 | 6 9 | RC1 ____ | _______________ _______________ _______________
| | | __ RC3 | 7 8 | RC2 __ | | | ______ | | ______ | | ______ |
| | | | _______ | | | | F / A / | | F / A / | | F / A / |
| | | | | | | | /_____/ B | | /_____/ B | | /_____/ B |
| | | | | | | | E / G / | | E / G / | | E / G / |
| | | | | | | | /_____/ C | | /_____/ C | | /_____/ C |
| | | | | | | | D | | D | | D |
| | | | | | | | H | | H | | H |
| | | | | | | |_______________| |_______________| |_______________|
| | | | | | | A B C D E F G H A B C D E F G H A B C D E F G H
| | | | | | |__WWW___|_|_|_|_|_|_|_______|_|_|_|_|_|_|_______| | | | | | |
| | | | | |____WWW_____|_|_|_|_|_|_________|_|_|_|_|_|_________| | | | | |
| | | | |______WWW_______|_|_|_|_|___________|_|_|_|_|___________| | | | |
| | | |______________________________WWW_________|_|_|_|_____________|_|_|_|_____________| | | |
| | |________________________________WWW___________|_|_|_______________|_|_|_______________| | |
| |__________________________________WWW_____________|_|_________________|_|_________________| |
|____________________________________WWW_______________|___________________|___________________| | If it does not, modify and show us exactly what you are doing.
Mike
PS This forum uses English only. |
|
![](templates/subSilver/images/spacer.gif) |
abadade
Joined: 24 May 2014 Posts: 4
|
|
Posted: Sun May 25, 2014 5:28 am |
|
|
Code: | _______
vdd | 1 14 | Vss
________ RA5 | 2 13 | AN0 ______________________________________________________________
| RA4 | 3 12 | AN1 ___________________________________________ |
| MCLR | 4 11 | RA2 ______________________ | |
| ______ RC5 | 5 10 | RC0 ______ | | |
| | ____ RC4 | 6 9 | RC1 ____ | _______________ _______________ _______________
| | | __ RC3 | 7 8 | RC2 __ | | | ______ | | ______ | | ______ |
| | | | _______ | | | | F / A / | | F / A / | | F / A / |
| | | | | | | | /_____/ B | | /_____/ B | | /_____/ B |
| | | | | | | | E / G / | | E / G / | | E / G / |
| | | | | | | | /_____/ C | | /_____/ C | | /_____/ C |
| | | | | | | | D | | D | | D |
| | | | | | | | H | | H | | H |
| | | | | | | |_______________| |_______________| |_______________|
| | | | | | | A F E B D C G H A F E B D C G H A F E B D C G H
| | | | | | |__WWW___|_|_|_|_|_|_|_______|_|_|_|_|_|_|_______| | | | | | |
| | | | | |____WWW_____|_|_|_|_|_|_________|_|_|_|_|_|_________| | | | | |
| | | | |______WWW_______|_|_|_|_|___________|_|_|_|_|___________| | | | |
| | | |______________________________WWW_________|_|_|_|_____________|_|_|_|_____________| | | |
| | |________________________________WWW___________|_|_|_______________|_|_|_______________| | |
| |__________________________________WWW_____________|_|_________________|_|_________________| |
|____________________________________WWW_______________|___________________|___________________| |
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun May 25, 2014 7:57 am |
|
|
OK. I've guessed at your PIC circuit.
1) What is the value of the current limiting resistors?
2) Are you running the whole thing from a 30V supply?
Mike |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun May 25, 2014 8:53 am |
|
|
my 2 cents
i think he means his INLET measurement span is 30vdc
NOT his PSU Vdd ....
if my hunch is right - this is a proteus -
CLASSIC school project - you are struggling to elicit details on.
i am not losing any sleep based on what i've seen.
has anybody who is
(dry behind the ears- && posted seriously,
more than a few times -&& done a muxed LED display )
USED it in a PRODUCT lately?
in my case - its at least 6 years in the PAST
since we have these newfangled (reflective) LCD's that can use
a single ma or two - to do the display job for us now.
![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Wed Sep 17, 2014 10:04 am |
|
|
any body can explain this line ?
TRISA=0b00010000;
PORTA=0x27;
TRISC=0b00000000;
PORTC=0x37; _________________ sahu |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Wed Sep 17, 2014 10:40 am |
|
|
easy as reading the datasheet !
1st line says to configure PORTA as one input( bit4) the rest outputs
2nd line says to send to PORTA the data '0x27' or '0010 0111' in binary
3rd line says to configure PORTC as all outputs ( '0'=output, '1' = input)
4th line says to send to PORTC the data '0x37' or '0011 0111' in binary
Now as to WHAT this code does in the program is up to you to comprehend.
This is all basic microcontroller information that should have been taught in the FIRST week of the course.It is vitally important to KNOW and forms the basis of everything else.
hth
jay
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Wed Sep 17, 2014 11:08 am |
|
|
temtronic wrote: | easy as reading the datasheet !
1st line says to configure PORTA as one input( bit4) the rest outputs
2nd line says to send to PORTA the data '0x27' or '0010 0111' in binary
3rd line says to configure PORTC as all outputs ( '0'=output, '1' = input)
4th line says to send to PORTC the data '0x37' or '0011 0111' in binary
Now as to WHAT this code does in the program is up to you to comprehend.
This is all basic microcontroller information that should have been taught in the FIRST week of the course.It is vitally important to KNOW and forms the basis of everything else.
hth
jay
hth
jay |
I understand line 1&3.
but confused with line 2&4.
why 27 & 37 ? _________________ sahu |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Wed Sep 17, 2014 1:55 pm |
|
|
probably used as a 'power up' test of the LED segments to confirm they all light up ??? it would be nice to have this brief test,and the original programmer might have done it.
I don't know as I haven't seen a good schematic( properly labelled) let alone a 'paragrah of comments' detailing the pinout usage of the PIC , which normally would be in the first section of code. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Sep 17, 2014 5:09 pm |
|
|
sahu77 wrote: | any body can explain this line ?
TRISA=0b00010000;
PORTA=0x27;
TRISC=0b00000000;
PORTC=0x37; |
Oh, come on Sahu.
The lines are very close to your own thread dating back to February this year.
Like I said before, you can work out with pencil and paper what the effects are.
(Assuming you know whether the displays are CA or CC.)
Mike |
|
![](templates/subSilver/images/spacer.gif) |
|