View previous topic :: View next topic |
Author |
Message |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
identifier save it's value in power up but not in RESET |
Posted: Fri Oct 19, 2012 8:17 am |
|
|
Hey,
I'm trying to get digital potentiometer to work so that in power up
it is zeroed and after controlling that digital pot in next reset it must be zero too...
So the problem is that signed int8 identifier must keep it's value
in reset but not in power up ! Is it possible to do so?
(I understand to save identifier to EPROM might be good answer...
but I don't want to use it)
brdgs
-arto-
Last edited by artohautala on Fri Oct 19, 2012 9:12 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Oct 19, 2012 8:23 am |
|
|
by 'zero' do you mean CENTER of pot - or one LIMIT of pot ??
and NOT store a fixed value in pot's eeprom? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19365
|
|
Posted: Fri Oct 19, 2012 8:25 am |
|
|
Make sure the value is a global variable, _not_ static (which are initialised on boot), and is not initialed by default. So declared as (for example)
Code: |
int8 potval;
//must be declared outside all the code
|
Then at the start of your main code, have:
Code: |
if (restart_cause == NORMAL_POWER_UP) {
potval=0; //clear the pot
}
|
The variable will retain it's value (provided you have _not_ got #ZERO_RAM specified), for all boot up causes, except normal power on.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Fri Oct 19, 2012 8:53 am |
|
|
asmboy wrote: | by 'zero' do you mean CENTER of pot - or one LIMIT of pot ??
and NOT store a fixed value in pot's eeprom? |
Yes after powerup and after RESET must be zeroed but in my case it's zeroed only after powerup...
Code: |
//************************************************************************************************
void ret_offset(void) //returns offset to 0 V after reset
{
signed int i;
//if positive offset after reset:
//offset_wiper = 40; works OK !
if( offset_wiper < 0){ //set offset to negative voltage:
for(i = 0; i < offset_wiper; ++i){
output_high(pot_up_down); //dig.pot wiper down, makes offset V higher!
delay_ms(1);
output_high(pot_inc); //pulse dig. pot
delay_ms(1);
output_low(pot_cs); //dig. pot selected
delay_ms(1);
output_low(pot_inc); //no store ... return to standby
delay_ms(1);
output_high(pot_cs); //dig. pot NOT selected
delay_ms(1);
}
}
if( offset_wiper > 0){ //set offset to negative voltage:
for(i = 0; i > offset_wiper; --i){
output_high(pot_up_down); //dig.pot wiper down, makes offset V lower!
delay_ms(1);
output_high(pot_inc); //pulse dig. pot
delay_ms(1);
output_low(pot_cs); //dig. pot selected
delay_ms(1);
output_low(pot_inc); //no store ... return to standby
delay_ms(1);
output_high(pot_cs); //dig. pot NOT selected
delay_ms(1);
}
}
}
more code:
//+ offset button pressed:
if((x_place > 121) & (x_place < 139) & (y_place > 159) & (y_place < 185)){
delay = 200;
loop = 0;
do{
if(offset < 2.2 ){
offset = offset + 0.04582;
wr_offset(offset);
}
delay_ms(delay);
//offset + button released
putc(0x6F); //cmd
putc(0x04); //wait until touch activity, 0 = no activity, 2= touch release
while(!kbhit(LCD))
delay_us(1);
x_coord_MSB = getc(LCD); //read character from UART
x_coord_LSB = getc(LCD); //read character from UART
y_coord_MSB = getc(LCD); //read character from UART
y_coord_LSB = getc(LCD); //read character from UART
if(loop > 5)
delay = 20;
//set offset towards positive voltage:
output_low(pot_up_down); //dig.pot wiper down, makes offset V higher!
delay_ms(1);
output_high(pot_inc); //pulse dig. pot
delay_ms(1);
output_low(pot_cs); //dig. pot selected
delay_ms(1);
output_low(pot_inc); //no store ... return to standby
delay_ms(1);
output_high(pot_cs); //dig. pot NOT selected
delay_ms(1);
x_place = y_place = 0;
++loop;
++offset_wiper;
}while(x_coord_LSB!=2); //result is in x_coord LSB
}
//- offset button pressed:
if((x_place > 153) & (x_place < 169) & (y_place > 159) & (y_place < 185)){
delay = 200;
loop = 0;
do{
if(offset > -2.2 )
{ offset = offset - 0.04606;
wr_offset(offset);
--offset_wiper;
}
delay_ms(delay);
//offset - button released
putc(0x6F); //cmd
putc(0x04); //wait until touch activity, 0 = no activity, 2= touch release
while(!kbhit(LCD))
delay_us(1);
x_coord_MSB = getc(LCD); //read character from UART
x_coord_LSB = getc(LCD); //read character from UART
y_coord_MSB = getc(LCD); //read character from UART
y_coord_LSB = getc(LCD); //read character from UART
if(loop > 5)
delay = 20;
//set offset towards negative voltage:
output_high(pot_up_down); //dig.pot wiper down, makes offset V higher!
delay_ms(1);
output_high(pot_inc); //pulse dig. pot
delay_ms(1);
output_low(pot_cs); //dig. pot selected
delay_ms(1);
output_low(pot_inc); //no store ... return to standby
delay_ms(1);
output_high(pot_cs); //dig. pot NOT selected
delay_ms(1);
++loop;
--offset_wiper;
}while(x_coord_LSB!=2); //result is in x_coord LSB
}
|
and 0ffset_wiper is global identifier:
Code: |
//global identifiers:
int8 ints;
int1 high_freq;
signed int offset_wiper;
|
brdgs
-arto- |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Oct 19, 2012 9:14 am |
|
|
actually you replied with the SAME lack of specificity !!
when you say 'zero- WHICH DO YOU MEAN ????
1- CENTER of POT or
2- ONE of the LIMIT positions ??
ZERO could IMPLY either based on your schematic
and intent
for most pots w/o eeprom ZERO means CENTER ( 50%) position |
|
![](templates/subSilver/images/spacer.gif) |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Fri Oct 19, 2012 9:31 am |
|
|
asmboy wrote: | actually you replied with the SAME lack of specificity !!
when you say 'zero- WHICH DO YOU MEAN ????
1- CENTER of POT or
2- ONE of the LIMIT positions ??
ZERO could IMPLY either based on your schematic
and intent
for most pots w/o eeprom ZERO means CENTER ( 50%) position |
Yes thks for your good answer...
so I change that offset voltage in my program for many times ... but after RESET I want offset voltage to be zero Volt...
I'm using x9102p digital pot... it must be pulsed to make wiper low and up...
My idea is to make pulses to dig.pot many times to change offset voltage and after RESET offset voltage must be 0 V again...
but problem is that global identifier signed int offset_wiper ; don't keep it's value after reset ?
Quote: |
when you say 'zero- WHICH DO YOU MEAN ????
1- CENTER of POT or
|
I mean CENTER
Sorry I'm not very wise ... and programming is not any business for me ... but it's very interesting !
I'll be very grateful for your help
best regards
-arto- |
|
![](templates/subSilver/images/spacer.gif) |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Fri Oct 19, 2012 9:57 am |
|
|
Ttelmah wrote: | Make sure the value is a global variable, _not_ static (which are initialised on boot), and is not initialed by default. So declared as (for example)
Code: |
int8 potval;
//must be declared outside all the code
|
Then at the start of your main code, have:
Code: |
if (restart_cause == NORMAL_POWER_UP) {
potval=0; //clear the pot
}
|
The variable will retain it's value (provided you have _not_ got #ZERO_RAM specified), for all boot up causes, except normal power on.
Best Wishes |
Ok,
thanks for your answer
but the problem is that I want to save global identifier after RESET not to zero it...
and after powerup I want to make that global identifier zero...
Is it possible to do so ?
You have helped me so many times ... and I'm very gratefull for that ...
brgds
-arto- |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Oct 19, 2012 10:41 am |
|
|
let me direct your attention to:
Quote: |
The potentiometer has associated
with it a volatile Wiper Counter Register (WCR) and
four non-volatile Data Registers that can be directly
written to and read by the user. The contents of the
WCR controls the position of the wiper on the resistor
array though the switches. Powerup recalls the
contents of the default data register (DR0) to the WCR.
|
from the data sheet
a very nice flexible part - and the read back and non volatile storage functions could very likely be put to profitable use in your case .
what you want to accomplish can be done by utilizing features in the pot itself. |
|
![](templates/subSilver/images/spacer.gif) |
|