Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F4550 timer issue(USB implementation)

Status
Not open for further replies.

SilverWingz

New Member
Using the microchip's CDC basic demo.(18F4550)

Here,when i try to feed any value to the TMR0L and TMR0H registers,
not changes occurs in the o/p frequency whatsoever...just gives one fixed freq. for 8 bit mode and another for 16 bit mode irrespective to the values set in TMR0L and TMR0H...

Here's my code...can any1 take a looksie and point it out if i am making any obvious mistakes,please?

CODE WITHIN "ProcessIO"

Code:
	TRISC = 0 ;                     
	PORTC = 0b00000001;
	TMR0H=0x00;TMR0L=0x09;//changing these values does nothing whatsoever
	T0CONbits.T0CS = 0;
	T0CONbits.PSA = 0;
	T0CONbits.T0PS0 = 0;
	T0CONbits.T0PS1 = 0;
	T0CONbits.T0PS2 = 0;
	T0CONbits.T08BIT=1;         
	INTCONbits.TMR0IF = 0;
	T0CONbits.TMR0ON = 1;
	TRISCbits.TRISC0=0;
	PORTCbits.RC0=0;
	INTCONbits.GIE = 1;
	INTCONbits.TMR0IE=1; 
	INTCONbits.PEIE =1;
	RCONbits.IPEN = 1; //Enable priority levels on interrupts
	RCONbits.SBOREN = 0; 
	INTCON2bits.TMR0IP =0; //Set interrupt priority as low

Code within "YourLowPriorityISRCode"

Code:
							if(INTCONbits.TMR0IF==1)
							{
							count++;
							if(count==2)
                                                        {
							count=0;
							PORTCbits.RC0=~PORTCbits.RC0;
							}
							INTCONbits.TMR0IF = 0;
							}

Thanks
 
Last edited:
modified the ISR code to:
Code:
							if(INTCONbits.TMR0IF==1)
							{
							count++;
							if(count==2){
							count=0;
							PORTCbits.RC0=~PORTCbits.RC0;
							}
							INTCONbits.TMR0IF = 0;
							TMR0H=0x00;TMR0L=0x03;
							}
no change,i am afraid :(
 
You are trying to interrupt in 3 cycles. Not going to happen. Try a sensible time.

Mike.
 
uh...um...that...i tried everything in the spectrum...from 20 to FF...the output is just the same as would be for FF...as for the 3...i was just playing around
 
umm Ian...might you have any suggestions regarding the matter?
no matter what i load on the TMR0L/H pair, from 0x00 to 0xFF,
the output waveform remains just the same... changing prescaler works fine though...
any idea what might be going on?
I tried Mike's suggestion but reloading the registers within the ISR did not make any diff that i could see...
P.S : i get two freq's. one in the 8 bit mode,another in the 16 bit mode
 
As you are using a USB template, you need to check what resources the code is already using..... I'll take a look at the CDC code and see if I can see anything..

Can you please point me to the code you are using
 
I am using Microchip Application Library's USB CDC Basic demo.
PIC18F4550
i made the additions mentioned above to the code within the main.c
do u want me to attatch my main.c?
 
Sorry... Been having a few problems with my laptop.... I might be upgrading, but I don't want Windows 8... I want a laptop with Windows 7..


Anywho.... I was looking at the USB CDC basic demo...

You want all that code that you posted in the "static void InitializeSystem(void)"

Rather then the processIO() as it only needs to run once...

I'll keep looking..
 
oh...the reason i kept it within processIO() :

you see,i want certain things to happen when i press certain keys on the pc end.
For Example:start up a pwm when i press 'p',increase pwm duty cycle when i press '+',decrease it at '-' and so on...
I was fiddling with the timer for a freq. generator below the hard pwm generator range...easy enough without the USB CDC,but got stuck when trying with USB
i placed the code within the ProcessIO() because that way,i get to make it do do something like this:
Code:
				switch(USB_Out_Buffer[i])
				{
					case 'f':
							TRISC = 0 ;                     
							PORTC = 0b00000001;
							TMR0H=0x00;TMR0L=0x09;//changing these values does nothing whatsoever
							T0CONbits.T0CS = 0;
							T0CONbits.PSA = 0;
							T0CONbits.T0PS0 = 0;
							T0CONbits.T0PS1 = 0;
							T0CONbits.T0PS2 = 0;
							T0CONbits.T08BIT=1;         
							INTCONbits.TMR0IF = 0;
							T0CONbits.TMR0ON = 1;
							TRISCbits.TRISC0=0;
							PORTCbits.RC0=0;
							INTCONbits.GIE = 1;
							INTCONbits.TMR0IE=1; 
							INTCONbits.PEIE =1;
							RCONbits.IPEN = 1; //Enable priority levels on interrupts
							RCONbits.SBOREN = 0; 
							INTCON2bits.TMR0IP =0; //Set interrupt priority as low
						break;
					default:
						USB_In_Buffer[i] = USB_Out_Buffer[i] + 1;
						break;

this way,i can add more switch cases and make the device perform different functions on different key presses on the pc end

see what i'm getting at?
 
you see, i'm aiming at a usb based actuator cum feedback device...after this i'll add a stepper driver,quad encoder feedback and an adc module codes to other switch cases(i previously wrote codes for these in 16F877A format)...hopefully they wont give me too much trouble in the 18F4550 USB CDC transition
 
ugh,finally managed to figure out what was causing all the trouble.
commenting out the TMR0H/L initialization got it working fine.
just had to get rid of the that additional line was what was messing things up and keep the register loads confined within the ISR.Thanks a LOT, Mike.
And Ian as well :)

Here's a working prototype of main.c for a primitive pwm cum freq. generator... I will brush up these modules and add more modules soon.
Feel free to take a look at what I've done and give your feedback,as this is my 1st attempt at USB :D

EAGERLY AWAITING YOUR RESPONSE,
Wingz


P.S: i renamed the main.c for my convenience...dont let it inconvenience you :p
 

Attachments

  • working_pwm_cum_freq_gen.c
    62.5 KB · Views: 320
Status
Not open for further replies.

Latest threads

Back
Top