Thanks for posting the code. I'll take a look..@JohnInTX
Tag, you are it.
Thanks for posting the code. I'll take a look..@JohnInTX
Tag, you are it.
The first time is always the hardest. I believe you'll find that it is time well spent. It will give you a basis for all future coding projects rather than having to fiddle with dumb delays on an ad-hoc basis on each different one. FWIW, I use this method for everything, even simple little things - it always works and simple little things have a way of growing into complex big things.All without dumb delays. It is mounted and working. It took me 3 nights, like 9 hrs. It is fast for me u know. figuring out the interrupt and timer stuff which I never did before
For the ADC, I just run it in main. Each time through the main loop, examine the DONE bit. If DONE, take the value and store it in an array of channel values, change the channel and start the conversion on the new channel. That way, the last ADC value for each channel is always present in the array - when you decide you need the value of something, just get it from the array, you don't have to start a conversion and wait... (there's that word 'wait' again). You probably want to average the readings so you can keep a sum and count for each channel and post the averaged reading in the array of current values. Chew on that while I look at your code.Posted code is OK and the Second one I made is also OK. I can use either if I want.
All I like to learn is to store the message in ROM and use pointers to Display using interrupt(if needed).
Too many messages is giving me jumbled characters. The code works with the jumbled display.
I will be using 5 ADC inputs. I dunno your approach. Read ADC using IRQ or all in main, or not.
If LCD part is figured out I can finish an earlier project that is also halted due to jumbled characters. No one gave me a way to figure out the issue. I cannot find any solution in the net too. Been a couple of years since I gave up on that.
Cool! I assume by 'interrupt' you mean that you will schedule display updates with an interrupt-driven tik. I wouldn't actually do the LCD write itself within an interrupt routine. The PIC is not particularly suited to doing lots of stuff in an interrupt service routine.It's working.
All the messages are displaying correctly
So far I am trying using blocking type from MikroC lib.
The messages are in ROM. Copied to RAM and displayed.
Once satisfied I will try to use the interrupt to update the LCD.
Thanks John.
If you are getting accurate, stable readings you can probably dispense with averaging - at least for now. I've always used some sort of software averaging so that I have control over the system response to changes etc. but it sounds like you can skip it for now. In the event that you eventually decide you need it you can make it easier to add if you code with it in mind - something like post #65. Write your main code to expect always valid values for each analog input, with that value being generated 'behind the scenes'. In the simple case, each ADC channel gets read in sequence, scaled appropriately (to Volts, Amps etc) and posted in the analog inputs array. Main routines just index the array to read the last-posted value whenever they need it.You said some thing about averaging...!
I am using 100nf caps on each ADC. Do I still need software averaging ?
If so I like to know how it is done. A simple example will be enough to give me an idea.
My readings gives ±0.02 compared to my Fluke. Which I believe is quite OK for this.
What do you think ?
sbit Charger_On at RB1_bit;
sbit Back_lit at RB2_bit;
sbit AC_On at RB5_bit
sbit Float_Charge at RB0_bit;
#define Backlitmask 0x04 // Back light at RB2
#define Backlit_On (PORTBimg |= Backlitmask) // Back light On
//In IRQ
PORTB = PORTBimg;
//In MAIN
Backlit_On;
#define Amask 0x01
ShadowRegister |= Amask; //generates bsf ShadowRegister,0
ShadowRegister &= ~ Amask;// generates bcf ShadowRegister,0
PORTx = ShadowRegister; // writes the new image to the port
Really Nice.Used RAM (bytes): 68 (19%) Free RAM (bytes): 284 (81%)
Used ROM (program words): 3088 (38%) Free ROM (program words): 5104 (62%)
unsigned int SecsTime; // number to be converted - maybe its a parameter to a function.. use a copy because it gets clobbered in this example
unsigned char Hours,Minutes,Secs;
// write some function that does this - pass parameters to your liking or use globals
Hours = (unsigned char)(SecsTime / 3600); // 3600 secs in an hour
SecsTime = SecsTime % 3600; // compute remaining seconds
Minutes = (unsigned char)(SecsTime / 60); // number of minutes
Secs = (unsigned char)(SecsTime %60); // remaining seconds.
void show2(unsigned char d)
{
LCD_outchar_CP ( d/10 + \'0'); // output 10's digit as ASCII
LCD_outchar_CP (d%10 + \'0'); // output 1's digit as ASCII
}
void WriteTimeToLCD_CP(unsigned int SecsTime)
{
convertSecsTohhmmss(SecsTime); // dissect seconds into Hours, Minutes,Seconds
show2(Hours);
LCD_outchar_CP(':');
show2(Minutes);
LCD_outchar_CP(':');
show2(Seconds);
}
by Aaron Carman
by Jake Hertz
by Jake Hertz
by Jake Hertz