amjadali56
Full Member level 3
- Joined
- Sep 17, 2007
- Messages
- 151
- Helped
- 39
- Reputation
- 78
- Reaction score
- 36
- Trophy points
- 1,328
- Location
- Earth
- Activity points
- 2,050
Hi everyone! i am working with CSLA2DG Hall effect current sensor with PIC16F676 and 7 segment display as:
sensor supply volts are DC 8v
out put is DC 4.03 volts at 0 Amps and for every Ampere the voltage increment at 1 mv.
At PIC i used vADC * 500/1023 and (vADC / 10)% 10 is my first digit (I m trying to drop the 4v and want to plot the mv at 7 segment like 4.39V will be 39.0 Amps).
The problem is my reading is unreliable and jumpy so is there any other way I am sure my way is not good at all...... :???:
sensor supply volts are DC 8v
out put is DC 4.03 volts at 0 Amps and for every Ampere the voltage increment at 1 mv.
At PIC i used vADC * 500/1023 and (vADC / 10)% 10 is my first digit (I m trying to drop the 4v and want to plot the mv at 7 segment like 4.39V will be 39.0 Amps).
The problem is my reading is unreliable and jumpy so is there any other way I am sure my way is not good at all...... :???:
PHP:
//Sourced and refrenced by: http://tahmidmc.blogspot.com/2014/06/simple-ac-voltmeter.html
#define SA RC4_bit // 6
#define SB RC2_bit // 8
#define SC RC1_bit // 9
#define SD RC5_bit // 5
#define SE RA4_bit // 3
#define SF RC3_bit // 7
#define SG RC0_bit // 10
#define C1 RA5_bit // 2
#define C2 RA2_bit // 11
#define C3 RA1_bit // 12
#define vinCh 0 // RA0
unsigned int voltage;
unsigned char SEGMENT;
const unsigned char COMMON_CATHODE = 1;
const unsigned char COMMON_ANODE = 0;
const unsigned char COMMON = COMMON_ANODE;
unsigned char DriveSegment[10];
const unsigned char AnodeDriveSegment[10] = {192, 249, 164, 176, 153, 146, 130, 248, 128, 144};
void initialize(void){
unsigned char i;
CMCON = 7;
TRISA = 1;
PORTA = 0;
ANSEL = 1;
ADC_Init();
TRISC = 0;
PORTC = 0;
for (i = 0; i < 10; i++){
DriveSegment[i] = AnodeDriveSegment[i]; }
}
unsigned int getVoltage(void){
unsigned int vADC;
float realVolts;
vADC = ADC_Get_Sample(vinCh);
realVolts = (((float)vADC* 500)/1023);
return (unsigned int) realVolts;
}
void displayVoltage(void){
unsigned int SendVal;
unsigned char Digit;
unsigned char counter;
for (counter = 0; counter < 3; counter++){
SEGMENT++;
if (SEGMENT > 3) SEGMENT = 1;
C1 = 1; C2 = 1; C3 = 1;
switch (SEGMENT){
case 1:
Digit = (unsigned char) ((voltage / 10)% 10);
break;
case 2:
Digit = (unsigned char) (voltage % 10);
break;
case 3:
Digit = (unsigned char) ((voltage / 10) % 10) ;
break;
}
SendVal = DriveSegment[Digit] & 0x7F; // Make bit 7 zero
SA = SendVal & 1; // bit 0
SB = (SendVal & 2) >> 1; // bit 1
SC = (SendVal & 4) >> 2; // bit 2
SD = (SendVal & 8) >> 3; // bit 3
SE = (SendVal & 16) >> 4; // bit 4
SF = (SendVal & 32) >> 5; // bit 5
SG = (SendVal & 64) >> 6; // bit 6
switch (SEGMENT){
case 1:
C1 = 0;
break;
case 2:
C2 = 0;
break;
case 3:
C3 = 0;
break;
}
delay_ms(5);
}
}
void main()
{
char samplecounter;
initialize();
while (1){
voltage = getVoltage();
for (samplecounter = 0; samplecounter < 80; samplecounter++){
displayVoltage();
}
}
}