Nandika, Go through the ADC with variable resistor path. That's the professional way of approaching this. Variable clock is only good for theoretical arguments but practically it is completely impossible to achieve anything with that. Semi says about SPI, but SPI also needs an accurate clock. Jerky clocks will tend to disrupt communication and introduce lot of instability to overall system.
I'll tell you an example. On professionally designed circuits, have you noticed the oscillator is soldered as much as closed to microprocessor. The reason is to avoid even the small interferences on long copper lines.
In such a scenario, think of having a variable resistor to control the system clock. That's simply not recommended at all. I'm sure nobody who has experience on this subject will even discuss about that
Help My Project(12CH LED Driver)??
- SemiconductorCat
- Major
- Posts: 455
- Joined: Mon Aug 22, 2011 8:42 pm
- Location: currently in hyperspace
Re: Help My Project(12CH LED Driver)??
Variable Resistor to calibrate clock! AGREED that's a bad idea. because that's a resistor and , resistance isIn such a scenario, think of having a variable resistor to control the system clock. That's simply not recommended at all. I'm sure nobody who has experience on this subject will even discuss about that
at a high value , and noise is proportional to the root of the temperature and resistance, that will probably
skip the time.
^- last equation E is the noise voltage. T is temperature in Kelvin , R is resistance in Ohms.Don't
ask me more on this simply I don't know. I'll add bibliography , so it will be useful for a knowledge seeker.
A good expensive crystal [32.XXXMhz ] clock crystals , will have about 2ppm per Centigrade.But it varies
due to other parameters too. So even a expensive clock crystal will skip about 1 second per month.
The ultimate solution is to get the time from Seattle [NOT JOKING] , GPS signals.
Or else you need to use a crystal oven to keep the crystal temperature stable.
More than that you need accuracy, Buy a SMD atomic clock.
So even the SMD atomic clock is at lest 100$ [used in high military applications radar , missile controls,etc]
it's not suitable here. Neither you could have a crystal oven. But there is a certainly workaround on this.
You could simply read the temperature and using a simple lookup table and calibrate your RTC module.
There are 16FXXX chips with internal RTC module build in. If your building a clock then as seven zero said,
completely remove the idea of calibrating the clock with Variable Resistor.
Nadika: what actually you want to do with that variable resistor?
How it's impossible ? , SPI is synchronous isn't it? That's why you could read SD card using a microcontrollerSemi says about SPI, but SPI also needs an accurate clock. Jerky clocks will tend to disrupt communication and introduce lot of instability to overall system.
which runs low speed.
Completely agree with you. The only applications of controlling system clock is for reduce the power consumptionIn such a scenario, think of having a variable resistor to control the system clock. That's simply not recommended at all. I'm sure nobody who has experience on this subject will even discuss about that
of the microprocessor.
Re: Help My Project(12CH LED Driver)??
who's going to generate that SCLK clock?How it's impossible ? , SPI is synchronous isn't it? That's why you could read SD card using a microcontrollerSemi says about SPI, but SPI also needs an accurate clock. Jerky clocks will tend to disrupt communication and introduce lot of instability to overall system.
which runs low speed.
Still not clear? See this timing diagram. See how precision timing is required to move data across devices. I'm not going to explain further. Just read about SPI.
Re: Help My Project(12CH LED Driver)??
Hi Friends,
I created 8 LED flasher with speed controlling.I used VR to change speed.
I have coding small ADC Example.It work 90% correctly.
But,When i change the VR,in two end of VR LED get lowest speed.(till analog input pin[RA2] goes +5V and GND)
It's speed is not monotony.(I used VR for "POT-HG" Proteus component.Is it may be a reason for this? )
Actually,What is the reason for this?
Coding
main.c
adc.h
Circuit
Proteus Design File
Thanks All
I created 8 LED flasher with speed controlling.I used VR to change speed.
I have coding small ADC Example.It work 90% correctly.
But,When i change the VR,in two end of VR LED get lowest speed.(till analog input pin[RA2] goes +5V and GND)
It's speed is not monotony.(I used VR for "POT-HG" Proteus component.Is it may be a reason for this? )
Actually,What is the reason for this?
Coding
main.c
Code: Select all
#include <pic.h>
#include "delay.h"
#include "adc.h"
main(){
PORTC=0;
TRISB=0;
PORTB=0x01;
DelayMs(2000);
do{
int sp=GetADCRes();
if (PORTB==0x80){
PORTB=0X01;
DelayMs(sp);
}
else{
PORTB=PORTB*2;
DelayMs(sp);
}
}while(1);
}
Code: Select all
#include <pic.h>
#include "delay.h"
int GetADCRes(){
ADCON0=0b10001101;//Conversion speed=Fosc/32,Input channel=channel1
ADCON1=0b10000000;//Left jestify format,alls are analog channels
return ((1800/255)*ADRESL)+200;//min speed=2000mS,max speed=200mS,therefore [(2000-200)/255}]*ADRESL
}
Re: Help My Project(12CH LED Driver)??
There are codes required to be called to initialise a device or a peripheral only one time. Those codes are called as init routines. To initialise ADC, you need to call such one time ADC init routine as well. I mentioned this before and you forgot to add that. Instead you add it is ADC reading code which is not correct. Here I add the init code again. Change the values as you need and call it at the beginning of main() routine. Make sure it is only called one time.
You can add it as this in your main() routine.
The DelayMs(2000); is not required at that point.
Change your GetADCRes function.
After reading the value from the ADC, you can convert the voltage to time as you prefer.
Code: Select all
// Setup A2D module
void init_a2d(void){
TRISA = 0x2F; //PORTA all pins are input
ADCON0 = 0x41; // Select Fosc/16 and ADC on
ADCON1 = 0xC1; // Select right justify result.
ADON = 1; // Turn on the A2D conversion module
}
Code: Select all
main(){
PORTC = 0;
TRISB = 0;
PORTB = 0x01;
init_a2d();
.....
.....
Change your GetADCRes function.
Code: Select all
/* Return an 10-bit bit result */
unsigned short read_a2d(unsigned char channel){
unsigned short tmpShort;
channel &= 0x07; // truncate channel to 3 bits
ADCON0 &= 0xC5; // clear current channel select
ADCON0 |= (channel<<3); // apply the new channel select
// Wait till the conversion is completed
GODONE = 1;
while (GODONE);
tmpShort = ADRESH;
DelayMs(10);
return ((tmpShort<<8)+ADRESL);
}
Re: Help My Project(12CH LED Driver)??
I know this before.I know we must initializes ADC unit one time.SevenZero wrote:There are codes required to be called to initialise a device or a peripheral only one time.
But,I want to create new .h file for include ADC function.
However,Now I can do it.
HI-TECH C not easy as I think.I like it. I didn't care ADON,GODON,ADIF,ADIE bits.
Thank you ZevenZero
I must study all of your advices and Data sheet.
Re: Help My Project(12CH LED Driver)??
Please describe some line of this code.I refereed C++ Book.but,I couldn't find those.
1.
What is this shifting system?
2.%=, &=, |=, ^=, <<=
Please,give small explanation for those operators.
( Give me small example and explanation for each operator.I will be able to understand easy for understand me and save your time.)
Thank
SevenZero wrote:Code: Select all
/* Return an 10-bit bit result */ unsigned short read_a2d(unsigned char channel){ unsigned short tmpShort; channel &= 0x07; // truncate channel to 3 bits ADCON0 &= 0xC5; // clear current channel select ADCON0 |= (channel<<3); // apply the new channel select // Wait till the conversion is completed GODONE = 1; while (GODONE); tmpShort = ADRESH; DelayMs(10); return ((tmpShort<<8)+ADRESL); }
1.
Code: Select all
ADCON0 |= (channel<<3)
2.%=, &=, |=, ^=, <<=
Please,give small explanation for those operators.
( Give me small example and explanation for each operator.I will be able to understand easy for understand me and save your time.)
Thank
Re: Help My Project(12CH LED Driver)??
This is left shift which is used to move bits towards the left side.What is this shifting system?Code: Select all
ADCON0 |= (channel<<3)
This is equals to ADCON0 = ADCON0 | (channel<<3);
If you set as ADCON0 = (channel<<3); all previous values of ADCON0 will be changed to (channel<<3) which is not correct. Setting on other bits are required. So the correct way is to preserve them by using OR operator.
I'll explain using small examples then you will understand it better.2.%=, &=, |=, ^=, <<=
Please,give small explanation for those operators.
int a = 3, b = 4;
Say a += b;
This means a = a + b;
a = 3 + 4 = 7;
Say b <<= 1;
This means b = b << 1;
b = 4 << 1 = 8;
Say a |= b; (Note that a = 7 and b = 8)
This means a = a | b;
a = 7 | 8 = 15;
Likewise ^ is for XOR, % is for Modulo, & is for bitwise AND.
Likewise a++ means, a = a + 1;
Re: Help My Project(12CH LED Driver)??
Thank you...
I could understand it correctly.
I could understand it correctly.
Re: Help My Project(12CH LED Driver)??
Hello my Friends....,
(I couldn't log to ROBOT.LK some past days...And,I temporary disable my project. )
However, I have a question about Shifting of HI-TECH C.
I have 12 LED outputs.First[LSBs] 8 for PORTB. Remaining 4 for PORTC.
I coding Write method like this,
But while I call this using this method,It not work correctly.
But ,This work correctly,
Where are problems???
(I couldn't log to ROBOT.LK some past days...And,I temporary disable my project. )
However, I have a question about Shifting of HI-TECH C.
I have 12 LED outputs.First[LSBs] 8 for PORTB. Remaining 4 for PORTC.
I coding Write method like this,
Code: Select all
void Write(unsigned int val){
PORTB=val;
PORTC=(val>>8);//I used shifting method for get last[MSB] bit4 to PORTC.
}
Code: Select all
/*KNIGHT RIDER TO CENTER ALL
n=number of times
del=delay
*/
void NightRiderToCenter(unsigned short n,unsigned int del){
unsigned short i,j;
unsigned int val;
for(i=0;i<n;i++){
for(j=0;j<6;j++){
val=pow(2,j) + pow(2,11-j);
Write(val);
DelayBigMs(del);
}
}
}
Code: Select all
/*
Knight rider system--DARK DOT
nByn==1/2/3/4/6
n=times of loop
del==time of LED on(delay)
comment=
YOU CAN GET 6 STYLE FROM THIS METHORD DIRECTLY.
*/
void Run12346Dot(unsigned char nByn,unsigned char n,unsigned short int del){
unsigned char f,i;
unsigned short int val;
switch (nByn){
case 1:
f=2;
val=1;
break;
case 2:
f=4;
val=3;
break;
case 3:
f=8;
val=7;
break;
case 4:
f=16;
val=15;
break;
case 6:
f=64;
val=63;
}
PORTB=4095-val;
PORTC=((4095-val)>>8);
DelayBigMs(del);
for(i=0;i<n;i++){
while(RC3==1){
val=val*f;
PORTB=4095-val;
PORTC=((4095-val)>>8);
DelayBigMs(del);
}
if (RC3==0){
while(RB0==1){
val=val/f;
PORTB=4095-val;
PORTC=((4095-val)>>8);
DelayBigMs(del);
}
}
}
}