PCA9629 a stepper motor controller class library
Class library for PCA9629.
A sample program available on http://mbed.org/users/nxp_ip/code/PCA9629_Hello/
Diff: PCA9629.h
- Revision:
- 6:138665018069
- Parent:
- 5:aff87a1c8bd6
- Child:
- 7:199f109eb0c6
diff -r aff87a1c8bd6 -r 138665018069 PCA9629.h --- a/PCA9629.h Tue Apr 24 08:05:03 2012 +0000 +++ b/PCA9629.h Wed Jul 18 07:42:48 2012 +0000 @@ -17,51 +17,10 @@ #define PCA9629_DEFAULT_ADDR 0x42 -#define INIT_VALUE__MODE 0x10; -#define INIT_VALUE__SUBADR1 0xE2; -#define INIT_VALUE__SUBADR2 0xE4; -#define INIT_VALUE__SUBADR3 0xE8; -#define INIT_VALUE__ALLCALLADR 0xE0; -#define INIT_VALUE__WDTOI 0xFF; -#define INIT_VALUE__WDTCNTL 0x00; -#define INIT_VALUE__IP 0x00; -#define INIT_VALUE__INTSTAT 0x00; -#define INIT_VALUE__OP 0x0F; -#define INIT_VALUE__IOC 0x03; -#define INIT_VALUE__MSK 0x0F; -#define INIT_VALUE__CLRINT 0x0C; -#define INIT_VALUE__INTMODE 0x00; -#define INIT_VALUE__INT_ACT_SETUP 0x00; -#define INIT_VALUE__INT_MTR_SETUP 0x00; -#define INIT_VALUE__INT_ES_SETUP 0x00; -#define INIT_VALUE__INT_AUTO_CLR 0x00; -#define INIT_VALUE__SETMODE 0x00; -#define INIT_VALUE__PHCNTL 0x00; -#define INIT_VALUE__SROTNL 0x30; -#define INIT_VALUE__SROTNH 0x00; -#define INIT_VALUE__CWPWL 0x00; -#define INIT_VALUE__CWPWH 0x00; -#define INIT_VALUE__CCWPWL 0x00; -#define INIT_VALUE__CCWPWH 0x00; -#define INIT_VALUE__CWSCOUNTL 0x00; -#define INIT_VALUE__CWSCOUNTH 0x00; -#define INIT_VALUE__CCWSCOUNTL 0x00; -#define INIT_VALUE__CCWSCOUNTH 0x00; -#define INIT_VALUE__CWRCOUNTL 0x00; -#define INIT_VALUE__CWRCOUNTH 0x00; -#define INIT_VALUE__CCWRCOUNTL 0x00; -#define INIT_VALUE__CCWRCOUNTH 0x00; -#define INIT_VALUE__EXTRASTEPS0 0x00; -#define INIT_VALUE__EXTRASTEPS1 0x00; -#define INIT_VALUE__RAMPCNTL 0x00; -#define INIT_VALUE__LOOPDLY 0x00; -#define INIT_VALUE__MCNTL 0x00; - - /** PCA9629 class * */ - + class PCA9629 { public: @@ -167,7 +126,7 @@ * The initializing values are defined in the function */ void set_all_registers( char *a, char size ); - + /** Write 1 byte data into a register * * Setting 8 bits data into a register @@ -208,12 +167,12 @@ * * Start command * This function starts motor operation with hard-stop flag and rotation+step enabled, no repeat will be performed - * If custom start is required, use "write( PCA9629::MCNTL, 0xXX )" to control each bits. + * If custom start is required, use "write( PCA9629::MCNTL, 0xXX )" to control each bits. * * @param dir rotate direction ("CW" or "CCW") */ void start( Direction dir ); - + /** Motor stop * * Stop command @@ -228,10 +187,10 @@ * * @param dir rotate direction ("CW" or "CCW") * @param prescaler prescaler setting (for 3 bits setting range from 0 to 0x7. See datasheet) - * @param pps pps defineds pulse width for the motor. The pulse width will be 1/pps + * @param pulse_per_second pps defineds pulse width for the motor. The pulse width will be 1/pps * @return 16 bit data that what set to the CWPWx or CCWPWx registers */ - short pps( Direction dir, PrescalerRange prescaler, int pps ); + short pps( Direction dir, PrescalerRange prescaler, int pulse_per_second ); /** Set PPS * @@ -239,10 +198,10 @@ * This interface can be used to set CWPWx or CCWPWx registers * * @param dir rotate direction ("CW" or "CCW") - * @param prescaler prescaler setting (for 3 bits setting range from 0 to 0x7. See datasheet) - * @param pps pps defineds pulse width for the motor. The pulse width will be 1/pps + * @param pulse_per_second pps defineds pulse width for the motor. The pulse width will be 1/pps * @return 16 bit data that what set to the CWPWx or CCWPWx registers */ + short pps( Direction dir, float pulse_per_second ); /** Set rotation count * @@ -280,6 +239,7 @@ void speed_change( unsigned short pw ); private: + I2C i2c; char i2c_addr; };