CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Changing PWM duty cycles

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

Changing PWM duty cycles
PostPosted: Thu Mar 04, 2010 5:10 pm     Reply with quote

NO MESSAGE

Last edited by Rodders on Tue Mar 09, 2010 7:37 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 5:54 pm     Reply with quote

Quote:

#byte Port_A=0X80 // file address of Port B
#byte Tris_A=0X92 // file address of Tris B

#byte Port_B=0X81 // file address of Port A
#byte Tris_B=0X93 // file address of Tris A

#byte Port_C=0X82 // file address of Port C
#byte Tris_C=0X94 // file address of Tris C

Why are you not using the full, correct SFR register addresses ?
Why only the bottom 8 bits ? Also, in the case of Port A and B,
the comments are reversed.
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 6:06 pm     Reply with quote

PCM programmer wrote:
Quote:

#byte Port_A=0X80 // file address of Port B
#byte Tris_A=0X92 // file address of Tris B

#byte Port_B=0X81 // file address of Port A
#byte Tris_B=0X93 // file address of Tris A

#byte Port_C=0X82 // file address of Port C
#byte Tris_C=0X94 // file address of Tris C

Why are you not using the full, correct SFR register addresses ?
Why only the bottom 8 bits ? Also, in the case of Port A and B,
the comments are reversed.


I am not sure I understand the bit about only the bottom 8 bits being used.
I got these adresses from the datasheet. They way we were taught was to have a struct as a pinmap of a port. Pins on Port A have the address 0x80 whilst the tris bits are on 0x92.
I thought it'd be more elegant than just having huge struct containing all the 24 pins in a row.

Is there another way I could set my pins?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 6:11 pm     Reply with quote

Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote:

TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 6:34 pm     Reply with quote

PCM programmer wrote:
Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote:

TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES

The exact same addresses I used to set up my ports? I think I may have set up my pin map using already defined SFRs. I don't understand why that wouldn't work.

Instead should I use any addresses on bank 0 for the port adresses and then set the tris bits on the addresses available on bank 1?
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 7:38 pm     Reply with quote

Rodders wrote:
PCM programmer wrote:
Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote:

TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES

The exact same addresses I used to set up my ports? I think I may have set up my pin map using already defined SFRs. I don't understand why that wouldn't work.

Instead should I use any addresses on bank 0 for the port adresses and then set the tris bits on the addresses available on bank 1?

Scrap this last post. I think I've entered the correct addressed for the pinmaps. Forgive my silly mistake and slow understanding. Took me time to understand what you meant.
Code:
#byte Port_C=0XF82 // file address of Port C
#byte Tris_C=0XF94 // file address of Tris C


#byte Port_B=0XF81 // file address of Port B
#byte Tris_B=0XF93 // file address of Tris B



#byte Port_A=0XF80 // file address of Port A
#byte Tris_A=0XF92 // file address of Tris A
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 2:59 pm     Reply with quote

The code works fine now. I used a Switch case menu and the robot processes fine the line readings and converts them into motion.

However, I burned 2 PICS and am wondering should we use 4 diodes when connecting the the inputs from the H-bridge to the motors? I am running my motors using a 20kHz pwm pulse and would like to know which one is the recommended one for small dc motor applications?


P.S. Is it possible to implement PID without optical encoders around the wheel shaft of the motor.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 3:06 pm     Reply with quote

Quote:

However, I burned 2 PICS and am wondering should we use 4 diodes
when connecting the the inputs from the H-bridge to the motors?

By "burned", do you mean "destroyed" or "programmed" ?

Post a schematic of your existing PIC, H-Bridge, and motor circuit.
Rodders



Joined: 04 Mar 2010
Posts: 12
Location: Birmingham

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 4:30 pm     Reply with quote

PCM programmer wrote:
Quote:

However, I burned 2 PICS and am wondering should we use 4 diodes
when connecting the the inputs from the H-bridge to the motors?

By "burned", do you mean "destroyed" or "programmed" ?

Post a schematic of your existing PIC, H-Bridge, and motor circuit.

Unfortunately I don't have it at the moment, the guy in charge of electronics has has it. I am just the programmer. I output 2 pwm signal plus 2 direction and brake signal to the H-bridge: LMD18200. The 2 outputs of the PIC are decoupled with a pair of capacitors connecting the output to bootstrap.

When I say burned, the pic will initially show a pwm output on the oscilloscope before it completely flatlines. Same result with new PICs or reprogrammed pics. The circuit will be revised because it seems to be draining way too much current, i.e. the robot motors will only run when supplied with 15V but will come to a standstill with any supply voltage ranging from 16V-30V. Electronics really isn't my forte, which is why I am focussing on implementing PID for a very smooth and effcient motion.

Is it possible to implement PID using input from the 4 sensors we're using to track the line?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group