Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] pwm with powerbank conflict

Status
Not open for further replies.

ruben91

Junior Member level 3
Joined
Nov 17, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
209
hello everyone, recently i have programed an ultrasonic detection system with pic18f1330 to detect obstacle, i want to make it portable, this i have make use of powerbank
But the problem arise when i use 2600mah the output is not as i wanted but if i use 10000mah the output i s as i wanted, can anyone help me regarding this, tq
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,734
Helped
4,345
Reputation
8,699
Reaction score
4,305
Trophy points
1,393
Activity points
130,616
Hi,

The problem surely is not the mAh but more likely the voltage. Maybe the voltage drops and also maybe caused by pulsed current.

For us it is not possible to find the error source, because your description gives only a few (unrelated) data.

It sounds like "i have a car type XY, it works good when i drive to city1, but it has an error when i want to drive to city2"
What we need is a detailed view on your circuit: schematic, voltages, currents, timing. Other related informations like code, pcb layout, pictures, scope screenshot....and very important: a detailed error description. "...is not what i wanted..." is no information for us, because we don't know what you want, and what is not like you expected...

Please try to give more information, so we can better assist you.

Klaus
 

ruben91

Junior Member level 3
Joined
Nov 17, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
209
Hi,

The problem surely is not the mAh but more likely the voltage. Maybe the voltage drops and also maybe caused by pulsed current.

For us it is not possible to find the error source, because your description gives only a few (unrelated) data.

It sounds like "i have a car type XY, it works good when i drive to city1, but it has an error when i want to drive to city2"
What we need is a detailed view on your circuit: schematic, voltages, currents, timing. Other related informations like code, pcb layout, pictures, scope screenshot....and very important: a detailed error description. "...is not what i wanted..." is no information for us, because we don't know what you want, and what is not like you expected...

Please try to give more information, so we can better assist you.

Klaus

i'm sorry for being silly and not providing he accurate info, by the way this is my circuit, and basically my project is ultrasonic ranging system.

Code:
/*
 * File:   uss.c
 * Author: RubeN
 *
 * Created on 31 March 2015, 00:34
 */

#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000


// PIC18F1330 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1H
#pragma config OSC = INTIO2     // Oscillator (Internal oscillator, port function on RA6 and RA7)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = BOHW       // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3L
#pragma config PWMPIN = OFF     // PWM Output Pins Reset State Control bit (PWM outputs disabled upon Reset)
#pragma config LPOL = HIGH      // Low-Side Transistors Polarity bit (Even PWM Output Polarity Control bit) (PWM0, PWM2 and PWM4 are active-high (default))
#pragma config HPOL = HIGH      // High Side Transistors Polarity bit (Odd PWM Output Polarity Control bit) (PWM1, PWM3 and PWM5 are active-high (default))

// CONFIG3H
#pragma config FLTAMX = RA5     // FLTA Mux bit (FLTA input is muxed onto RA5)
#pragma config T1OSCMX = LOW    // T1OSO/T1CKI MUX bit (T1OSO/T1CKI pin resides on RB2)
#pragma config MCLRE = ON       // Master Clear Enable bit (MCLR pin enabled, RA5 input pin disabled)

// CONFIG4L
#pragma config STVREN = OFF     // Stack Overflow/Underflow Reset Enable bit (Reset on stack overflow/underflow disabled)
#pragma config BBSIZ = BB256    // Boot Block Size Select bits (256 Words (512 Bytes) Boot Block size)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit Block 0 (000800-000FFF) (Block 0 is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit Block 1 (001000-001FFF) (Block 1 is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Code Protection bit (Boot Block Memory Area) (Boot Block is not code-protected)
#pragma config CPD = OFF        // Code Protection bit (Data EEPROM) (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit Block 0 (000800-000FFF) (Block 0 is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit Block 1 (001000-001FFF) (Block 1 is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Write Protection bit (Configuration Registers) (Configuration registers are not write-protected)
#pragma config WRTB = OFF       // Write Protection bit (Boot Block Memory Area) (Boot Block is not write-protected)
#pragma config WRTD = OFF       // Write Protection bit (Data EEPROM) (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit Block 0 (000800-000FFF) (Block 0 is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit Block 1 (001000-001FFF) (Block 1 is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protection bit (Boot Block Memory Area) (Boot Block is not protected from table reads executed in other blocks)



/*
 *
 */


void pwm1(void);
void pwm2(void);
void pwm3(void);
void pwm4(void);
unsigned int a;
unsigned int time;

void main()

{
OSCCONbits.IRCF2 = 1;// 4mhz OSC
OSCCONbits.IRCF1 = 1;//
OSCCONbits.IRCF0 = 0;//

//PTCON0=0xF;
PTCON0=0xF;
PTCON1=0x0;
//PWMCON0 = 0x28;
PWMCON0 = 0x10;
PWMCON1 = 0x0;
FLTCONFIG = 0x00;
PTMRL = 0;
PTMRH = 0;
PTPERH=0x0F;
PTPERL=0xFF;

PTCON1bits.PTEN= 1;

TRISBbits.TRISB2=0; // trig
TRISBbits.TRISB5=1; //echo
TRISAbits.TRISA2=0; //RED led
TRISAbits.TRISA3=0; //GREEN led


//PORTAbits.RA2=0;//red
//PORTAbits.RA3=0;//green

while(1)
{
PORTBbits.RB2=0;
PORTBbits.RB5=0;
PORTAbits.RA2=0;//red
PORTAbits.RA3=0;//green

TMR1H= 0;
TMR1L= 0;

	PORTBbits.RB2=1;
__delay_us(10);

	PORTBbits.RB2=0;


while(PORTBbits.RB5 == 0);                      //If ECHO is HIGH
    T1CONbits.TMR1ON = 1;                       //Start Timer
while(PORTBbits.RB5 == 1);                      //If ECHO is LOW
    T1CONbits.TMR1ON = 0;                     //Stop Timer
     // a = (TMR1L | (TMR1H<<8))/58.82; //Calculate Distance
//Delay10KTCYx(255);
//Delay10KTCYx(255);

time= TMR1H;
time= time<<8;
time= time|TMR1L;
a = time/58;
PIR1bits.TMR1IF=0;
__delay_ms(100);
//Delay10KTCYx(255);
//Delay10KTCYx(255);



if(a>=2 && a<=75)
//if(a>=2 && a<=10)
{
    pwm1();
}

//if(a<=38)
if(a>=76 && a<=120)
//if(a>=11 && a<=20)
{
    pwm2();
}

if(a>=121 && a<=170)
//if(a>=21 && a<=30)
{
    pwm3();
}


if(a>=151)
{
   pwm4();
}

}
}

void pwm1() //stay
{
 PTPERL = 1; //PWM time base period set to 10 bits
 PTPERH = 0xFF; //the higher bits will not be used here.
 PDC0H = 0xFF; //set period
 PDC0L= 0xFF;
}

void pwm2() //very fast
{
 PTPERL = 1; //PWM time base period set to 10 bits
 PTPERH = 0x54; //the higher bits will not be used here.
 PDC0H = 10; //set period
 PDC0L= 0xFF;
}

void pwm3() //slow
{
 PTPERL = 1; //PWM time base period set to 10 bits
 PTPERH = 0xFF; //the higher bits will not be used here.
 PDC0H = 10; //set period
 PDC0L= 0xFF;
}

void pwm4() //nothg
{
 PTPERL = 0; //PWM time base period set to 10 bits
 PTPERH = 0; //the higher bits will not be used here.
 PDC0H = 0; //set period
 PDC0L= 0;
}

PCB.JPG

this is the spec of battery(1)
Capacity: 2600mAh
Input: DC 5V, 1000mA
Output: DC 5V, 1000mA

Battery(2)
capacity 10000mah
output 2100mA
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,734
Helped
4,345
Reputation
8,699
Reaction score
4,305
Trophy points
1,393
Activity points
130,616
Hi,

in your circuit i can´t find any power supply capacitor. Use a (at least) 10uF electrolyte or tantalum and add a 100nF ceramic capacitor. Especially the cerami capacitor should be connected with short and wide traces to the VCC and GND of the PIC.

For future projects use a GND plane.

Still don´t see "what doesn´t function like expected"

Klaus
 

ruben91

Junior Member level 3
Joined
Nov 17, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
209
Hi,

in your circuit i can´t find any power supply capacitor. Use a (at least) 10uF electrolyte or tantalum and add a 100nF ceramic capacitor. Especially the cerami capacitor should be connected with short and wide traces to the VCC and GND of the PIC.

For future projects use a GND plane.

Still don´t see "what doesn´t function like expected"

Klaus

hello sir, wat i meant was, i am using HC-SR04 sensor, and the output i expected is when distance between the ostacle and the sensor is less than 75cm, the buzzer beeps fast, when the sensor is placed in between 76cm and 120 cm the buzzer beeps at moderate speed, and wen the distance of ostacle and the sensor is in between 121cm and 170cm, the buzzer beeps at slow speed and wen the distance is more than 170cm the buzzer shud not beep, this is what i meant by my expected result, it works fine when i connect to my laptop usb and on 10000mah battery, but the buzeer wont stop beeping even the distance is more than 170 if i connect to 2600mah power bank, help need pls
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top