Continue to Site

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.

[SOLVED] Problems with residual voltage to PWM.

Status
Not open for further replies.

Mondalot

Junior Member level 3
Joined
Sep 28, 2013
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
235
Hello,

I want to regulate a motor with PWM and regulate I'm using a handlebar equipped with accelerator Hall effect (View photo).
The problem is the residual voltage of 0.8V.
The handlebar is fed to 5V.
At full throttle at the output provides a voltage 4.3V only.
Using this formula this means to regulate the PWM with 0.8V
I'm 84 steps of 255, without doing anything.

As I can make as smooth regulation of 0-255.
Without having to start 84.

Code:
Device = 18F26K22
    Xtal = 16   

Config_Start
 FOSC = INTIO67   
 PLLCFG = On 'On      ' Oscillator multiplied by 4
 PRICLKEN = On     ' Primary clock enabled
 FCMEN = OFF           ' Fail-Safe Clock Monitor disabled
 IESO = Off            ' Internal/External Oscillator Switchover mode disabled
 PWRTEN = On           ' Power up timer enabled
 BOREN = SBORDIS       ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
 BORV = 190            ' Brown Out Reset Voltage set to 1.90 V nominal
 WDTEN = Off           ' Watch dog timer is always disabled. SWDTEN has no effect.
 WDTPS = 128           ' Watchdog Timer Postscale 1:128
 CCP2MX = PORTC1       ' CCP2 input/output is multiplexed with RC1
 PBADEN = Off          ' PORTB<5:0> pins are configured as digital I/O on Reset
 CCP3MX = PORTC6       ' P3A/CCP3 input/output is multiplexed with RC6 
 HFOFST = On           ' HFINTOSC output and ready status are not delayed by the oscillator stable status
 T3CMX = PORTC0        ' Timer3 Clock Input (T3CKI) is on RC0
 P2BMX = PORTB5        ' ECCP2 B (P2B) is on RB5                   (EXTMCLR = Enable MCLR/Disable RE Input)
 MCLRE = INTMCLR       ' MCLR pin enabled, RE3 input pin disabled  (INTMCLR = Disable MCLR/Enabled RE Input)
 STVREN = Off          ' Stack full/underflow will not cause Reset
 LVP = Off             ' Single-Supply ICSP disabled
 XINST = Off           ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
 Debug = Off           ' Disabled
 Cp0 = Off             ' Block 0 (000800-001FFFh) not code-protected
 CP1 = Off             ' Block 1 (002000-003FFFh) not code-protected
 CP2 = Off             ' Block 2 (004000-005FFFh) not code-protected
 CP3 = Off             ' Block 3 (006000-007FFFh) not code-protected
 CPB = Off             ' Boot block (000000-0007FFh) not code-protected
 CPD = Off             ' Data EEPROM not code-protected
 WRT0 = Off            ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = Off            ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = Off            ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = Off            ' Block 3 (006000-007FFFh) not write-protected
 WRTC = Off            ' Configuration registers (300000-3000FFh) not write-protected
 WRTB = Off            ' Boot Block (000000-0007FFh) not write-protected
 WRTD = Off            ' Data EEPROM not write-protected
 EBTR0 = Off           ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
 EBTR1 = Off           ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
 EBTR2 = Off           ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
 EBTR3 = Off           ' Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
 EBTRB = Off           ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End


Declare Adin_Res    = 10   ' Resolution 10 BITS 
Declare Adin_Tad    = FRC  ' Oscilator RC AD
Declare Adin_Stime  = 100  ' AD samples 100uS
Declare CCP1_Pin PORTC.2   ' Select Hpwm port and bit for CCP1 module (ch 1)


ANSELA = 00001111  ' Port A4-A7 Digital=0 / A0-A3 Analog
TRISA  =   00101111  ' Port A  I/O 
ADCON1 = %1000000    ' Right justified
ADCON2 = %1000000    ' Right justified


Dim DUTY As Byte                       ' Duty PWM
Dim TENSION As ADRESL.Word      ' Voltage       
Dim VALOR_GAS As Float                    
Dim VOLT As Float                         




VOLT=0
DUTY=0
VALOR_GAS=0


CLS


Main:


GoSub ADC_Handlebar
    Print At 4,6,Dec2 VOLT ," - ", Dec DUTY     'Display 
     HPWM 1,DUTY,20000 
 
 DelayMs 100
Goto Main

ADC_Handlebar:
   TENSION = ADIn 1                         ' Conversor AD
   VALOR_GAS = 489 *(TENSION / 10)  ' 489 = (5V/1023) 10Bits / Vref 5V
   VOLT = (VALOR_GAS / 10000)          ' Value in Volts
                  
         DUTY=(255/4.3)*VOLT             ' Calculates PWM (4.3V  full throttle not 5V )
Return

END

Picture:
Gas Hall.jpg

THX.
 

Hi,

I´m confused by the values.

You talk about 0.8V and 5.0V and 4.3V... how do they fit together?

And you talk about 84 steps of 255. How does this fit together?

****
Let´s say it is 0.7V and 5.0V and 4.3V (5.0V - 0.7V = 4.3V)..
84 Steps of 255 gives about 33%. But 33% of 5V is 1.65V.

Please clarify.


Klaus
 

Hi,

The handlebar is comprised of 3 wires:
1 = VCC (5V)
2 = VSS (GND)
3 = Output

When the handle is connected to 5V, the output of Hall, automatically gives 0.8V (residual)
When the handlebar give Gas output Hall gives 4.3V = (Voltage Maximum all Gas) not 5V


The steps 255 is for:
Syntax
Hpwm Channel, Dutycycle, Frequency

Dutycycle:
is a variable, constant (0-255), or expression that specifies the on/off (high/low) ratio
of the signal. It ranges from 0 to 255, where 0 is off (low all the time) and 255 is on (high) all the
time. A value of 127 gives a 50% duty cycle (square wave).

The Dutycycle is calculate on la formula of code:

DUTY=(255/4.3)*VOLT ' Calculates PWM (4.3V full throttle not 5V )

as you regulate the handlebar gives you 0 to 255 but as I have the residual voltage
0.8V represents that automatically go to 84 = 33% DutyCicle no 0 that would be ideal.


I hope you clarified the doubt.

THX.
 
Last edited:

Hi,

Ok i think it is clarified..

So you want the input of 0.8V ... 4.3V should give 0...100% duty cycle.

If this is the case, then

DutyCycle = 100% * (hallVoltage - 0.8V) / (4.3V - 0.8V)

For 8 bit ADC values and 8 bit duty cycles:
Offset = 0.8V * 255 / 5V = 41
Gain = 5V / (4.3V - 0.8V) = 5V / 3.5V = 1.43

DutyCycle = (ADCvalue - 41) * 1.43

Klaus
 

Hi,

I changed the formula the AD converter is in 10 Bits.

Offset = (0.8V * 1023)/ 5V = 164
Gain = 5V / (4.3V - 0.8V) = 5V / 3.5V = 1.43


TENSION = ADIn 1
VALOR_GAS = 322 *(TENSION / 10) ' 322 = 3.3/1023 (10Bits)
ADCvalue = (VALOR_GAS / 10000)

DutyCycle = (ADCvalue - 164) * 1.43

But now 0 DutyCycle = 23% not 0%
255 DutyCycle = 27% not 255%

THX
 

Hi,

But now 0 DutyCycle = 23% not 0%
255 DutyCycle = 27% not 255%

What does that mean? Where is the ADC?

Klaus
 

Hi,

ADC = ADIn 1 ' Read the value from the on-board Analogue to Digital Converter.
VALOR_GAS = 322 *(ADC/ 10) ' 322 = 3.3/1023 (10Bits)
ADCVolts= (VALOR_GAS / 10000) ' Passes Volts

DutyCycle = (ADCVolts- 164) * 1.43

But now 0 DutyCycle = 23% not 0%
255 DutyCycle = 27% not 255%

THX.
 

Hi,

me: --> DutyCycle = (ADCvalue - 41) * 1.43
you: --> DutyCycle = (ADCVolts- 164) * 1.43

why you now use "volts"?

You also wrote:
ADC = ADIn 1 ' Read the value from the on-board Analogue to Digital Converter.

******
please describe detailed what this means:
But now 0 DutyCycle = 23% not 0%
255 DutyCycle = 27% not 255%


Klaus
 

Hi,

I used "ADCVolts" to be better understood on the display is displayed in Volts.
not what comes directly from the AD pin converter.

ADC = It would Pin pic which is assigned the AD with the ADIN command (gross value of the converter).

The 164 : Offset = (0.8V * 1023)/ 5V = 164 (1023=10Bits AD)

THX.
 

Hi,

I wrote:
For 8 bit ADC values and 8 bit duty cycles:
Offset = 0.8V * 255 / 5V = 41
Gain = 5V / (4.3V - 0.8V) = 5V / 3.5V = 1.43

DutyCycle = (ADCvalue - 41) * 1.43
As said in the headline it is for 8 bit ADC values.
But you have 10 bit ADC.
So 0.8V input gives 164 LSB
4.3V gives 881 LSB.
From min to max this is 881LSB - 164LSB = 717LSB
At the duty cycle side this 717LSB give a range of 255 (0 to 255).
So the new gain is 255/717 = 0.356

DutyCycle = (ADC_value - 164) * 0.356.

Now from i put 0.8V ... 4.3V the ADCvalue is 164 ... 717 and after the calculation the duty cycle is 0 ... 255.

Klaus
 

Hi,

Sorry for the delay, I have been doing the final circuit board and functioning properly.

Thank you.
 

Hey again,

I have a little problem last minute

All I have as we can do it if you can do ...

The handlebars as I said is equipped with an inverter hall effect. when giving more gas or speed, the engine begins to start when I have a 1.8 or 2V almost 41% of duty.
and I have to go by turning the handlebars very very slowly so I would not be fired and is very upset because you're afraid.
If we subtract the 4.3 at full power - the residual offset 0.8, 3.8V are working for 100% duty.
As I can make this go much smoother without having to worry about going slowly giving gas.

or that other solutions may have.


The command works HPWM 8 bits = 0-255) would happen if 10 bits (0-1023) although not reach 1023 are about 881 +/-, this influence something. !!

THX, a lot
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top