My own controller project (and a couple requests)

Hey DJ88, the unsatifsfactory PWM may be a limitation of the BX chip?? It's basically an AVR w/ a basic interpreter loaded in. Maybe the basic OS slows down the PWM? I don't know, but I do know that no matter which frequency I tried to use, the results we not satisfactory. I'm actually pretty satisfied w/ how the LED dimming is working now, but I'll certainly keep everyones suggestions in mind if I run into issues w/ the way I'm doing it.

Thanks all for the info. I'm getting phsyched up to dive back into this project ;)
 
well if ya had a programmer and C complier I'd send you the code for a PIC to do the PWM. :p that would make things really easy. I know it works as I can see it doing it's job right now. :D

you know there could be an issue with the pin not being able to source enough current for the LED/LEDs.

Take a look at that as a possibility.

I don't have the specs handy for the BX or I'd check it out myself. :)
 
If the PWM is implemented in hardware then the BASIC interpreter shouldn't be the bottleneck. Perhaps one of the timer prescalers is set too high and lowering the frequency of the PWM output. Either way, I think you guys are correct about having some kind of driver like a transistor to supply the current rather than your MCU. The only other thing is to not have the frequency too high or the switch on/off time of the LED may become a factor. I don't really know for sure though. Probably anything around 500 Hz would be unnoticable and slow enough for the LED. Darren, I have the CCS compiler (old version though) for the 16F series and ICD2 if you don't mind sending me the code. Should be pretty straight forward with the CCP port, I think.

-Mike
 
Here's the code. For some reason I happened to have my USB key with me(not at home right now) :) Sorry about the formatting. guess the forum software doesn't like tabs. :mad:

I have attached the code as a txt file. Should work on any version of CCS. I didn't use any real fancy functions the newer ones have.

I am running a fairly recent version. I can't remember the ver. No off the top of my head. I do have it at home tho. (obviously)

I used a 16F818 as I had a bunch handy. tho I know it works on any CCP module. I was running this on an 877A for a while when I was writing some other code I threw it in for fun.

#include <16F818.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT
#fuses MCLR,CCPB2, NODEBUG,NOLVP,NOCPD,NOWRT
#use delay(clock = 4000000)

#define INTERRUPT_DELAY_TMR1 0x7FF9 //250ms prescale of 8
#define ON TRUE

int COUNTER, SECONDS, MINUTES, HOURS, DAYS;
int LED_intensity = 0;

BOOLEAN UP = TRUE;
BOOLEAN LED_cycle = TRUE;

void main(void){

setup_timer_1( T1_INTERNAL | T1_DIV_BY_8);
output_low(PIN_B2);
setup_ccp1(ccp_pwm);
set_pwm1_duty(1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

while(1);
}
/************************INTERRUPTS****************************/
#int_TIMER1
void TIMER1_isr(){

set_timer1( get_timer1() + INTERRUPT_DELAY_TMR1);

if (++counter >= 4){
counter = 0;
output_toggle(PIN_B0);
if(++seconds >= 60){
seconds = 0;
if (++minutes >= 60){
minutes = 0;
if(++hours >= 24){
hours = 0;
if(LED_cycle == UP){
LED_intensity = LED_intensity + 10;
set_pwm1_duty(LED_intensity);
}
else{
LED_intensity = LED_intensity - 10;
set_pwm1_duty(LED_intensity);
}
if(++days >= 14){
days = 0;
LED_cycle ^= 1;
}
}
}
}
}
}
 
[ c o d e ]
[ / c o d e ]

Without the spaces, does preformatted.


Code:
Like this:

 (.   \
    \  |   
     \ |___(\--/)
   __/    (  . . )
  "'._.    '-.O.'
       '-.  \ "|\
          '.,,/'.,,mrf
 
oh nice.. I did not know that.. Well on here at least. I knew about that on the CCS forum. Did I think that it would do it here? no..

Code:
#fuses 	HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT
#fuses	MCLR,CCPB2, NODEBUG,NOLVP,NOCPD,NOWRT
#use 	delay(clock = 4000000) 

#define INTERRUPT_DELAY_TMR1  	0x7FF9 	//250ms prescale of 8
#define ON  TRUE

int	COUNTER, SECONDS, MINUTES, HOURS, DAYS;	
int	LED_intensity = 0;

BOOLEAN UP = TRUE;
BOOLEAN	LED_cycle = TRUE;

void main(void){
     delay_ms(500);
     setup_timer_1( T1_INTERNAL | T1_DIV_BY_8);   
     output_low(PIN_B2); 
     setup_ccp1(ccp_pwm);
     set_pwm1_duty(1);
     enable_interrupts(INT_TIMER1);
     enable_interrupts(GLOBAL);

     while(1);
}
/************************INTERRUPTS****************************/
#int_TIMER1 
void TIMER1_isr(){

set_timer1( get_timer1() + INTERRUPT_DELAY_TMR1);  

	if (++counter >= 4){
		counter = 0; 
		output_toggle(PIN_B0);	
		if(++seconds >= 60){ 
			seconds = 0;
			if (++minutes >= 60){
				minutes = 0;
				if(++hours >= 24){
					hours = 0;
					if(LED_cycle == UP){
						LED_intensity = LED_intensity + 10;
						set_pwm1_duty(LED_intensity);
					}
					else{
						LED_intensity = LED_intensity - 10;
						set_pwm1_duty(LED_intensity);
					}
					if(++days >= 14){
						days = 0;
						LED_cycle ^= 1;
					}
				} 
			} 
		} 
	}
}
 
Last edited:
hi i have atlas pH stamp, arduino duemilanove.

i want to trigger some LEDs, buzzer,when certain pH is reached. i also want to display the pH reading on LCD display.

please help me with the code. any reference would also be really helpful.

this is my first time doing such project.

thanks
 
Back
Top