• AVR Freaks

remove a zero

Page: << < ..678 Showing page 8 of 8
Author
1and0
Access is Denied
  • Total Posts : 11774
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/03/30 14:31:00 (permalink)
+1 (1)
kurt
underneath is my 'concept'  code,  i want the value 9234 to be showed on the four digits   but it only shows the nine 
i don't know what it is.  the code is reconstructed from the temperature meter only now with common anode instead of common cathode.  sometimes i get the feeling that the pic itself is not oke.  at the end of my multiplexing lines i add the code to make LA2=1;   to make this output high and see in this way if the code comes to here i connected a led to this output but it don't become high. but in proteus it works  there is something wrong.  anyone ideas

The code you posted in Post #139 is no better than the code you posted in Post #1.  So it seems there's no progress and everything in 130+ posts is gone with the wind. :(
 
dan1138
Super Member
  • Total Posts : 4173
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/30 14:57:30 (permalink)
+1 (1)
kurt
No it's not unable or unwilling but the code in #42 is way above my level it's totally new for me and if possible I want to do it as much as possible myself (with some help).  If I just copy and paste the code in my MPLAB, sure it works but I don't understand one thing of it. Now I'm constructing pieces of code I understand and see if the code in works in real (see pictures attached) with this I encounter problems and try to solve it. I don't get the feeling that I'm not serious with it although I must say that due to my 'amateur' programming skills sometimes it seems to be so.   
 
for dan1138,  what's your opinion about my methode?

My opinion is that your method is saturated with the N-I-H (Not-Invented-Here) attitude.
 
It appears that there is no room for you to see that there is usually more than one way to reach the same goal, so are not that open to asking why anyone would use an idea that is different form the one you have.

But then this is my opinion, and we all know what opinions are like and that everyone else's stink. (You did ask)
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/31 09:56:50 (permalink)
0
sorry if i make you angry. i'am scared by the reactions
 
here you say that after 130 posts there is no progress but in post 58 and before we discuss the program/progress and you didn't made an issue of it .
 
anyway thanks for all the help
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/31 10:24:43 (permalink)
0
Start again.  Try interrupts and set one digit for each interrupt.
 
Shift the pins.  1 on, 3 off.
8 4 2 1
         x
      x
   x
x
         x
      x
    x
x

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
PStechPaul
Super Member
  • Total Posts : 2993
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/03/31 15:12:49 (permalink)
0
It would be helpful if the OP would provide the revised schematic for the common anode display. Also, use the simulator (preferably in MPLAB) to step through the code to see what is going on. And this discussion has gone far past the original issue of "remove a zero". I think it's time to start a new thread, and not in the MPLABX forum, as it is not about the IDE, but really basic C programming on an 8 bit PIC.

 
1and0
Access is Denied
  • Total Posts : 11774
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/04/01 07:07:43 (permalink)
0
kurt
here you say that after 130 posts there is no progress but in post 58 and before we discuss the program/progress and you didn't made an issue of it .

Before it was to get your code as-is to work. I don't have any issue. My comment in Post #141 is that your code in Post #139 is effectively the same as your code in Post #1 in that it does not use whatever learned between those two posts.
 
Anyway, instead of using Proteus try debugging with the MPLAB Simulator or preferably a Microchip debugger.
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/04/16 13:14:24 (permalink)
0
with my pic i encountered an issue,   i got 4 segments to display the temperature with the use of a pic18f2220 and an lm35. to get a nice smooth temperature to be displayed i added a rolling average calculation.  but every time after 2 minutes or so, the pic starts to "restart the calculation". i thought that there was something wrong in my calculation/code so i changed the code so that the temperature to be displayed is: "temperature = temperature + 1;"
 
so i power up the pic and every time the interrupt takes place (interrupt is every 65.536ms) the displayed value is added by 1. with this i transformed my temperature meter to a counter. 
i power up the pic and the segments start to count quickly 0.1.2.3.4.5 and so on but than when the display shows 1995  (approximately it goes so quick) the pic starts over again from 0 to +/-1995  every time there is something that makes the pic restart at exactly the same time,  a calculation  1995 * 65.536 ms = 130.7 seconds. the same as i measure with my stopwatch. so in my pic there is something that makes it restart after a little more than 2 minutes 
 
who knows what this can be?  underneath is my code 
 
 
 
#include "header.h"/////////////////////dit is de orginele mainfile....gggggggggggg
#include <xc.h>
#include <plib.h>
#include <pic18f2220.h>
#define _XTAL_FREQ 4000000
//#include "Multiplexing-7-Segment.h"
#define Digit1 PORTCbits.RC0
#define Digit2 PORTCbits.RC1
#define Digit3 PORTCbits.RC2
#define Digit4 PORTCbits.RC3
#define punt PORTBbits.RB7
#define delay 4
void init_ADC(void);
unsigned long int ADCResult = 0;
unsigned int temperature = 0;
unsigned int temperatura = 0;
unsigned int temperaturo = 0;
unsigned int temperaturu = 0;
unsigned int total = 0;
static unsigned char cnt = 4;
unsigned char Display(unsigned char digit)
{
unsigned char pattern;
unsigned char SEGMENT_MAP[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F };
pattern = SEGMENT_MAP[digit]; //The pattern to return
return (pattern);
}
void initTimer0 (void){
TMR0 = 0x00;
PSA = 0; //prescaler 0=on 1=off
T0PS2 = 1;
T0PS1 = 1;
T0PS0 = 1;
TMR0IE = 1;
GIE = 1;
T0CS = 0;
}
void main()
{
unsigned char ASD, BSD, CSD, DSD, ESD, FSD;
TRISB = 0;
TRISC = 0;
OSCCON = 0x60; // Set for Internal Oscillator
initTimer0();
init_ADC();
Digit1 = 0; //Disable digit 1
Digit2 = 0; //Disable digit 2
Digit3 = 0;
Digit4 = 0;

while (1)
{
ASD = (temperature / 1000) % 10;
if (ASD)
LATB = Display (ASD);
else
LATB = 0x00;
Digit1 = 1;
__delay_ms(delay);
Digit1 = 0;
BSD = (temperature / 100) % 10;
if (BSD || LATB)
LATB = Display (BSD);
//else LATB = 0x00;
Digit2 = 1;
__delay_ms(delay);
Digit2 = 0;
CSD = (temperature / 10) % 10;
if (CSD || LATB)
LATB = Display (CSD);
Digit3 = 1;
punt = 1;
__delay_ms(delay);
Digit3 = 0;
punt = 0;
DSD = temperature % 10;
LATB = Display(DSD);
Digit4 = 1;
__delay_ms(delay);
Digit4 = 0;
ADCResult = 0;
//---sample and convert----
ConvertADC(); //Start conversionn
while (BusyADC()); //Wait here until conversion is finished
ADCResult = ReadADC(); //Read the converted data
//temperature = (((ADCResult * 1500) >> 10)); //LM35
//temperature = ((ADCResult * 500) / 100); //orgineel
//temperatura = ((ADCResult -560) *5)-10; // voor lm 335
temperatura = (ADCResult *10)/2;
}
}
void interrupt myISR() {
TMR0IF =0;
// LATCbits.LATC7 ^= 1;



temperature = temperature + 1;


/*
temperaturo = (temperaturu*7)+temperatura;
temperaturu = temperaturo/8;

total = total + temperaturu;
cnt = cnt - 1;
if (cnt == 0) { cnt = 10 ; temperature = total / 10 ; total = 0;*/
}
void init_ADC(void)
{
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_2_TAD,
ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS,
ADC_1ANA);
}
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/04/16 13:35:46 (permalink)
+1 (1)
This sounds like your Watchdog Timer triggering.
You don't show us your config bit settings, so we can't check how you have set it.
 
I said this once before two months ago. (Post#54, 29-Jan-2018)
Get rid of this line
#include <pic18f2220.h>

 
It is pointless having it there, as xc.h has already included that file for you.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/04/16 13:43:19 (permalink)
0
oke thanks,
 
but it happes after 120 + seconds
 
// CONFIG1H
#pragma config OSC = INTIO2 // Oscillator Selection bits (Internal RC oscillator, CLKO function on RA6 and port function on RA7)
#pragma config FSCM = ON // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON // Internal/External Switchover bit (Internal/External Switchover mode enabled)
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer enable bit (PWRT disabled)
#pragma config BOR = ON // Brown-out Reset enable bit (Brown-out Reset enabled)
#pragma config BORV = 20 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
// CONFIG2H
#pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config CCP2MX = ON // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBAD = ANA // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config MCLRE = OFF // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVR = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000200-0007FFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (000800-000FFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0001FFh) is not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000200-0007FFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (000800-000FFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0001FFh) is not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000200-0007FFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (000800-000FFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0001FFh) is not protected from table reads executed in other blocks)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/04/16 13:45:28 (permalink)
+1 (1)
Yes, you have it right there

#pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)

As I recall, that gives a WDT timeout of about two minutes.
 
Change
#pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled)
to
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled)
 
Do not turn it on until you understand how it works, and when it is appropriate to use it.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/04/16 13:51:35 (permalink)
0
#pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled)
 
Set to OFF or periodically clear the watchdog timer.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
PStechPaul
Super Member
  • Total Posts : 2993
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/04/16 17:57:07 (permalink)
0
It looks like the WDT uses the INTRC clock, which is 32768 Hz. There is a divide by 125 on this clock, as well as the prescaler, which is set to divide by 32768. So a 125 second WDT reset would be expected.
 
As I understand it, a WDT reset does not initialize registers so unless they are explicitly initialized in main() code, execution will continue where these were at the time of WDT reset. A hard reset (MCLR) will perform the C preprocessing.

 
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/04/16 18:07:41 (permalink)
+1 (1)
PStechPaul
As I understand it, a WDT reset does not initialize registers so unless they are explicitly initialized in main() code, execution will continue where these were at the time of WDT reset. A hard reset (MCLR) will perform the C preprocessing.

I do not think that is correct.
A WDT reset is exactly the same as an MCLR reset, except for the TO bit in the RCON register being cleared.
 
You are probably thinking about what happens when there is a WDT timeout in SLEEP mode, which does not apply here.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
dan1138
Super Member
  • Total Posts : 4173
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: remove a zero 2018/04/16 18:26:19 (permalink)
0
PStechPaul
It looks like the WDT uses the INTRC clock, which is 32768 Hz. There is a divide by 125 on this clock, as well as the prescaler, which is set to divide by 32768. So a 125 second WDT reset would be expected.
 
As I understand it, a WDT reset does not initialize registers so unless they are explicitly initialized in main() code, execution will continue where these were at the time of WDT reset. A hard reset (MCLR) will perform the C preprocessing.

The configuration words used by the Original Poster have the WDT on from POR by default.
 
According to the data sheet:
 
TABLE 26-8: INTERNAL RC ACCURACY: PIC18F2220/2320/4220/4320
Prarmeter: F21, INTRC Accuracy @ Freq = 31 kHz

WDT timeout with default prescale setting: 113.974 seconds(min), 132.129 seconds(typ), 154.205 seconds(max).
 
So  a restart after 2 minutes (132.129 seconds) is the expected behavior. This matches what the OP has reported.
1and0
Access is Denied
  • Total Posts : 11774
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/04/16 19:09:16 (permalink)
0
Or, according to the datasheet:
 
TABLE 26-10: RESET, WATCHDOG TIMER, ...
Parameter 31, Watchdog Timer Time-out Period, Twdt = 3.48 ms(min), 4.00 ms(typ), 4.71 ms(max).
 
With WDT postscaler of 1:32768 it yields 114.033 sec(min), 131.072 sec(typ), 154.337 sec(max).
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/04/16 21:32:20 (permalink)
0
Page 247

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
Page: << < ..678 Showing page 8 of 8
Jump to:
© 2021 APG vNext Commercial Version 4.5