• AVR Freaks

remove a zero

Page: < 12345.. > >> Showing page 4 of 8
Author
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/02/02 13:29:35 (permalink)
+1 (1)
kurt
hey qub
you said: " you don't need to test for TMR0IF either"
 but i cant get  the code working if i remove this.

You probably didn't do just what I said, but how can we know if you just say what you think you did, rather than showing the code, so we can see what you really did?
 

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"
#61
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/03 11:56:58 (permalink)
0
 
 
#include "header.h"///////////////////// this is with official interrupt
#include
#include
#include
#define _XTAL_FREQ 1000000
//#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 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 = 0;
T0CONbits.PSA = 0; //prescaler
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 = 0x40; // 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)); // voor 1 getal achter de komma en VDD wordt VREFPLUS BIJ LM35
// temperature = ((ADCResult * 500) / 1024)-273; //orgineel
temperature = ((ADCResult -560) *5)-10; // voor lm 335
//converfsda into temperature (LM35 produces 10mV per degree celcius)
}
}
void interrupt myISR() {
    TMR0IF =0;
    LATCbits.LATC7 ^= 1;
}


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);
}



#62
1and0
Access is Denied
  • Total Posts : 9198
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/02/03 12:14:29 (permalink)
0
You have to turn on Timer0. Take a look at the T0CON register.
 
 
#63
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/04 14:11:54 (permalink)
0
i assume that in "initTimer0"   it write there "TMR0 = 0;   ,  i've changed this to "TMR0 = 1;. 
but i couldn't notice any difference. (can it be that this is the startpoint for tmr0 or something like that
 
but i looked again through the data sheet by the T0CON register and saw that i 
made a clerical error it has to be TMR0ON. enables/stop timer0.  but now i got so much confusing
 
also in t0con register is saw that you can set timer 0 as an 8 or 16 bit timer/counter, this is never mentioned in my code so by default it has to be 16 bit. but i thougt that i used an 8 bit 
 
can you clear this to me
#64
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/02/04 14:19:25 (permalink)
0
kurt
i assume that in "initTimer0"   it write there "TMR0 = 0;   ,  i've changed this to "TMR0 = 1;.

Why?
That is just changing the initial count from 0 to 1.
You won't notice the difference.
 

but i couldn't notice any difference. (can it be that this is the startpoint for tmr0 or something like that

Yes. Exactly.
 

but i looked again through the data sheet by the T0CON register and saw that i 
made a clerical error it has to be TMR0ON. enables/stop timer0.  but now i got so much confusing

So what is the confusion now?
You have found the correct bit to turn the timer on.
 

also in t0con register is saw that you can set timer 0 as an 8 or 16 bit timer/counter, this is never mentioned in my code so by default it has to be 16 bit. but i thougt that i used an 8 bit

Don't just look at the name of a bit, and guess what it does. Read the rest of the datasheet.
That does NOT set the timer to count in 8 or 16 bits, it just controls a mechanism to make it simpler to read the timer accurately without stopping it.
Edit: Disregard that last sentence, I was thinking about a different timer peripheral.
post edited by qɥb - 2018/02/04 15:06:54

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"
#65
1and0
Access is Denied
  • Total Posts : 9198
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/02/04 14:53:19 (permalink)
0
qɥb
That does NOT set the timer to count in 8 or 16 bits, it just controls a mechanism to make it simpler to read the timer accurately without stopping it.

I think it does. In 8-bit mode, interrupt occurs when TMR0L overflows from 0xFF to 0x00. In 16-bit mode, interrupt occurs when TMR0H:TMR0L overflows from 0xFFFF to 0x0000.
#66
1and0
Access is Denied
  • Total Posts : 9198
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/02/04 14:59:23 (permalink)
0
kurt
also in t0con register is saw that you can set timer 0 as an 8 or 16 bit timer/counter, this is never mentioned in my code so by default it has to be 16 bit. but i thougt that i used an 8 bit 

I have to download the datasheet to make sure. It is default to 8-bit.
#67
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/02/04 15:07:30 (permalink)
0
1and0
qɥb
That does NOT set the timer to count in 8 or 16 bits, it just controls a mechanism to make it simpler to read the timer accurately without stopping it.

I think it does. In 8-bit mode, interrupt occurs when TMR0L overflows from 0xFF to 0x00. In 16-bit mode, interrupt occurs when TMR0H:TMR0L overflows from 0xFFFF to 0x0000.

My bad, thinking about a different timer altogether. I've edited that post.
 

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"
#68
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/05 12:25:48 (permalink)
0
looking through the datasheet on one page i read that 8 bit is default (99) and on other page (117) i read '1=8 bit' and '0=16 bit'.   so two things in the datasheet are contradicted to eachother.??????
 
my interrupt looks like this:
void interrupt myISR() {
TMR0IF =0;
LATCbits.LATC7 ^= 1; }  ////////////////
 
so i hooked up an multimeter (who is capable of measuring duty cycle) to port RC7 and i played a little bit with the prescaler bits of the T0CON register. Also i watched this movie: " https://www.youtube.com/watch?v=nAr58JNgRlo&t=495s  "   starting at 8:15.  i've  tried different prescaler settings and calculated the time like they do in the youtube movie and than see if my multimeter displayed the same time but there is a little difference
prescaler off                             calculated duty cylce 0.256 ms  and on multimeter  0.262 ms
prescaler on TOPS bits set 111   calculated duty cycle 65.536 ms and on multimeter  65.8 ms
prescaler on TOPS bits set 101   calculated duty cycle 16.384 ms and on multimeter   16.5 ms
prescaler on TOPS bits set 110   calculated duty cycle 32.768 ms and on multimeter    32.9 ms
in real my pic is a little bit slower than it used to be. so it's not running at 4mhz but lets say for instance at 3.98
or something.  is this because i'am using an internal oscillator 
 
 
 
 
 
#69
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/02/05 12:33:04 (permalink)
0
kurt
looking through the datasheet on one page i read that 8 bit is default (99) and on other page (117) i read '1=8 bit' and '0=16 bit'.   so two things in the datasheet are contradicted to eachother.??????
 

Only if you assume the default setting is 0.
Look just above the register description. Each bit is labelled with the default setting.
 
Above "T08BIT", is says "R/W-1".
that means this bit can be read and written, and the power up default value is 1.
This is documented in the "Legend" box just below the register description.
 

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"
#70
1and0
Access is Denied
  • Total Posts : 9198
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/02/05 12:34:59 (permalink)
0
kurt
looking through the datasheet on one page i read that 8 bit is default (99) and on other page (117) i read '1=8 bit' and '0=16 bit'.   so two things in the datasheet are contradicted to eachother.??????

On page 99 it states "In 8-bit mode (which is the default) ...".  On page 117, the value above the row is the default, e.g. R/W-1 means the default value is 1.
 

in real my pic is a little bit slower than it used to be. so it's not running at 4mhz but lets say for instance at 3.98
or something.  is this because i'am using an internal oscillator 

The internal oscillator has a frequency tolerance -- check the Spec chapter.
 
Edit: Qub beats me again. :(   
 
Take a look to Table 26-8 for the internal osc accuracy:
 
+/-2% at +25°C
+/-5% at -10°C to +85°C
+/-10% at -40°C to +85°C
 
 
post edited by 1and0 - 2018/02/05 12:41:10
#71
PStechPaul
Super Member
  • Total Posts : 2252
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/05 13:46:40 (permalink)
0
There are other things that can affect your measured duty cycle. The multimeter has a certain accuracy, and can always differ by one count. So 16.5 mSec on the multimeter could actually be 16.6 or 16.4 for the theoretical 16.384 mSec. And unless it's a high grade lab instrument, its accuracy might be no better than 1%.
 
The errors you show are 0.4% to 0.7%, except for that with prescaler off, and it is only 2.3% error. In that case, the actual error is only 6 uSec, and some of that could be due to ISR overhead.

 
#72
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/05 14:26:11 (permalink)
0
but in many projects i see external oscillator,   what's the advantage of that 
this one is also pretty accurate
#73
PStechPaul
Super Member
  • Total Posts : 2252
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/05 14:40:00 (permalink)
0
An external oscillator or crystal will typically provide timebase accuracy of 50 PPM or better. Your results with the internal oscillator are not guaranteed or even to be expected, and may also vary with temperature, time, and other variables.
 
Also, older PICs did not have an internal oscillator, or used a rather poor RC oscillator.

 
#74
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3121
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/05 15:43:28 (permalink)
+1 (1)
This chip has an OSCTUNE register so that you can tune the frequency.

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.
#75
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/06 14:05:28 (permalink)
0
so an external oscillator is 'guaranteed' 
if i buy a 4 mhz crystal and place it with capacitors
and i do the calculations as in the youtube video they will match
#76
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/02/06 14:43:01 (permalink)
0
Not sure what you mean by "guaranteed".
If you connect it up correctly, and configure the PIC correctly, the oscillation frequency will be a lot more accurate than the internal oscillator.
 

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"
#77
kurt
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/12 13:48:59 (permalink)
0
in my configuration bits i've changed from an internal oscillator "INTIO2"  to an external oscillator HS. But in my concentration i forgot to place the oscillator with the caps and noticed that if i configure external oscillator the pic also works without the oscillator even places. how is this possible
 
also if i place the oscillator and i measure duty cycle as described a few posts ago, i can not notice that the pic becomes more accurate.  is there a possibility to test if i placed/programmed the external oscillator in the right way
#78
PStechPaul
Super Member
  • Total Posts : 2252
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/12 14:26:43 (permalink)
0
Do you have an external oscillator (EC or ECIO), or a crystal (HS)?
 
It will probably work without the recommended capacitors, but at a higher frequency, and perhaps not stable.
 
Some PICs have a fallback to an internal oscillator if the main clock fails, but the PIC18F2220 seems to have just a fail-safe clock monitor. It also has primary and secondary external oscillator connections, and facility to switch between clocks under program control.

 
#79
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3121
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/12 15:25:55 (permalink)
0
Yeah, sounds like the internal osc. is being used.
You really have to read the mpu docs, it can look daunting with all the options but they are reference.

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.
#80
Page: < 12345.. > >> Showing page 4 of 8
Jump to:
© 2019 APG vNext Commercial Version 4.5